]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/capture/cap_debug/libpal.h
Merge branch 'stg-2.409-radius'
[stg.git] / projects / stargazer / plugins / capture / cap_debug / libpal.h
1 /* $Id: libpal.h,v 1.1 2005/12/12 18:14:22 nobunaga Exp $
2
3 Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifndef _LIBPAL_H_
21 #define _LIBPAL_H_
22
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <sys/time.h>
26 #include <netinet/in.h>
27 #include <netinet/ip.h>
28 #include <netinet/ip_icmp.h>
29 #include <netinet/tcp.h>
30 #include <netinet/udp.h>
31 #include <arpa/inet.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include "checksum.h"
36 #include "constants.h"
37
38 /*
39 * generic packet structure
40 *
41 * we maintain a so called "active ptr" inside the packet. Most operations
42 * on the packet will take place at the position the pointer points at.
43 * The pointer should never be moved directly, instead the functions
44 * pkt_set_actpr() and pkt_move_actptr() are provided.
45 * Using this approach we can perform bounds checking and make sure our
46 * library functions won't segfault.
47 * pkt_type is not really being used at the moment. I don't know if it
48 * ever will be. It might just be left out one day, so keep your fingers
49 * off. Use pkt_init() to set it. And dont even think of messing with the
50 * packet payload pointer pkt. You do NOT want to do that. Use the provided
51 * library functions.
52 * To be clear: don't do _anything_ with this struct. Just pass it as a
53 * parameter, be happy and your programs will (hopefully) work. 
54 */
55 struct packet {
56         unsigned long   pkt_type;
57         unsigned char   *pkt;
58         unsigned int    pkt_size;
59         unsigned char   *pkt_ptr; /* active ptr inside packet */
60         unsigned int    pkt_pos; /* pkt_ptr position, starting at 0 */
61 };
62
63 /*
64 * our socket structure
65 *
66 * same as above. Use the provided library fuctions to change its values.
67 * Do not do it on your own. Live and let die. You have been warned.
68 */
69 struct pkt_socket {
70         int rawfd;
71         struct sockaddr_in *sckad;
72         /*struct sockaddr_ll *sckll;*/
73         socklen_t sckad_len;    
74 };
75
76 /* memory management */
77 int pkt_init(struct packet *pkt, unsigned long type, unsigned int size);
78 int pkt_free(struct packet *pkt);
79
80 /* pointer movement */
81 int pkt_move_actptr(struct packet *pkt, int relmov);
82
83 /* IP */
84 int pkt_ip_header(struct packet *pkt, unsigned int iphdr_len, unsigned int version, unsigned char tos, unsigned short int total_len, unsigned short int id, unsigned short int frag_off /* 3bit flag, 13bit offset */, unsigned char ttl, unsigned char protocol, unsigned short int cksum, unsigned int saddr, unsigned int daddr);
85
86 /* TCP */
87 int pkt_tcp_header(struct packet *pkt, unsigned short int sport, unsigned short int dport, unsigned int seq, unsigned int ackseq, unsigned char headerlen, unsigned char reserved, unsigned char flags, unsigned short window, unsigned short int checksum, unsigned short int urgent);
88 int pkt_tcp_cksum(struct packet *pkt, char *saddr, char *daddr, unsigned int tcp_pkt_size);
89 int pkt_tcp_option(struct packet *pkt, unsigned char kind, unsigned char len, void *optval, size_t optlen);
90
91 /* functions that might be useful and might be added some day ... 
92 int pkt_shift_data(struct packet *pkt, unsigned int from, unsigned int to, unsigned int len);
93 int pkt_tcp_change_seqno(int rel_seq, int rel_ackseq);
94 int pkt_tcp_set_seqno(unsigned int seq, unsigned int ackseq);
95 int pkt_ip_option(struct packet *pkt, unsigned char code, unsigned char len, unsigned char ptr);
96 int pkt_ip_option_addval(struct *pkt, unsigned char posptr, unsigned int optval);
97 */
98
99 #endif