3 International Computer Science Institute
6 This file may contain software code originally developed for the
7 Sting project. The Sting software carries the following copyright:
9 Copyright (c) 1998, 1999
10 Stefan Savage and the University of Washington.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 3. All advertising materials mentioning features or use of this software
22 must display the following acknowledgment:
23 This product includes software developed by ACIRI, the AT&T
24 Center for Internet Research at ICSI (the International Computer
25 Science Institute). This product may also include software developed
26 by Stefan Savage at the University of Washington.
27 4. The names of ACIRI, ICSI, Stefan Savage and University of Washington
28 may not be used to endorse or promote products derived from this software
29 without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
32 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 ARE DISCLAIMED. IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
35 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 /* XXX These are machine/compiler dependent */
48 typedef unsigned char uint8
;
49 typedef unsigned short uint16
;
50 typedef unsigned int uint32
;
52 #define IPPROTOCOL_ICMP 1
53 #define IPPROTOCOL_IGMP 2
54 #define IPPROTOCOL_TCP 6
55 #define IPPROTOCOL_UDP 17
59 #define TCPFLAGS_FIN 0x01
60 #define TCPFLAGS_SYN 0x02
61 #define TCPFLAGS_RST 0x04
62 #define TCPFLAGS_PSH 0x08
63 #define TCPFLAGS_ACK 0x10
64 #define TCPFLAGS_URG 0x20
65 #define TCPFLAGS_ECN_ECHO 0x40
66 #define TCPFLAGS_CWR 0x80
68 /* IP Options Parameters -- for IP Options te*/
70 #define IPOLEN_EOL 0x1
72 #define IPOLEN_NOP 0x1
74 #define IPOLEN_RR 0x27 /* Maximum length; up to 9 IP addresses */
76 #define IPOLEN_TS 0x28
77 #define IPOPT_FAKED 0xff
78 #define IPOLEN_FAKED 0x4
80 /* TCP Options Parameters */
85 #define TCPOPT_MAXSEG 2
86 #define TCPOLEN_MAXSEG 4
87 #define TCPOPT_WINDOW 3
88 #define TCPOLEN_WINDOW 3
89 #define TCPOPT_SACK_PERMITTED 4
90 #define TCPOLEN_SACK_PERMITTED 2
92 #define TCPOPT_TIMESTAMP 8
93 #define TCPOLEN_TIMESTAMP 10
94 #define TCPOPT_FAKED 0x19
95 #define TCPOLEN_FAKED 0x4
98 uint8 ip_vhl
; /* version (4bits) & header length (4 bits) */
99 uint8 ip_tos
; /* type of service */
100 uint16 ip_len
; /* length of IP datagram */
101 uint16 ip_id
; /* identification (for frags) */
102 uint16 ip_off
; /* offset (within a fragment) and flags (3 bits) */
103 uint8 ip_ttl
; /* time to live */
104 uint8 ip_p
; /* protocol number */
105 uint16 ip_xsum
; /* checksum */
106 uint32 ip_src
; /* source address */
107 uint32 ip_dst
; /* destination address */
110 /* Pseudo header for doing TCP checksum calculation */
111 struct PseudoIpHeader
{
121 uint16 tcp_sport
; /* source port */
122 uint16 tcp_dport
; /* destination port */
123 uint32 tcp_seq
; /* sequence number */
124 uint32 tcp_ack
; /* acknoledgement number */
125 uint8 tcp_hl
; /* header length (4 bits) */
126 uint8 tcp_flags
; /* flags */
127 uint16 tcp_win
; /* advertized window size */
128 uint16 tcp_xsum
; /* checksum */
129 uint16 tcp_urp
; /* urgent pointer */
135 uint8 icmp_type
; /* ICMP message type */
136 uint8 icmp_code
; /* Message code */
137 uint16 icmp_xsum
; /* checksum */
138 uint16 icmp_unused
; /* unused field */
139 uint16 icmp_mtu
; /* MTU of limiting interface */
144 struct TcpHeader
*tcp
;
147 struct ICMPUnreachableErrorPacket
{
149 struct IcmpHeader icmp
;
150 struct IpHeader off_ip
;
151 /* 8-first bytes of TCP header */
157 char *InetAddress(uint32 addr
);
159 uint16
InetChecksum(uint16
*ip_addr
, uint16
*tcp_addr
, uint16 ip_len
, uint16 tcp_len
);
161 void PrintTcpPacket(struct IPPacket
*p
);
162 void PrintICMPUnreachableErrorPacket(struct ICMPUnreachableErrorPacket
*p
);
164 void WriteIPPacket(struct IPPacket
*p
,
180 void ReadIPPacket(struct IPPacket
*p
, uint32
*src
, uint32
*dst
,
181 uint16
*sport
, uint16
*dport
, uint32
*seq
, uint32
*ack
,
182 uint8
*flags
, uint16
*win
, uint16
*urp
, uint16
*datalen
,
183 uint16
*ip_optlen
, uint16
*optlen
);
185 void StorePacket (struct IPPacket
*p
);
187 struct IPPacket
*FindHeaderBoundaries(char *p
);
189 struct IPPacket
*AllocateIPPacket(int ip_optlen
, int tcp_optlen
, int datalen
, char *str
);
191 void FreeIPPacket(struct IPPacket
**pkt_p
);
193 #endif /* _INET_H_ */