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 ICMP_TIMXCEED 11
62 #define TCPFLAGS_FIN 0x01
63 #define TCPFLAGS_SYN 0x02
64 #define TCPFLAGS_RST 0x04
65 #define TCPFLAGS_PSH 0x08
66 #define TCPFLAGS_ACK 0x10
67 #define TCPFLAGS_URG 0x20
68 #define TCPFLAGS_ECN_ECHO 0x40
69 #define TCPFLAGS_CWR 0x80
71 /* IP Options Parameters -- for IP Options te*/
73 #define IPOLEN_EOL 0x1
75 #define IPOLEN_NOP 0x1
77 #define IPOLEN_RR 0x27 /* Maximum length; up to 9 IP addresses */
79 #define IPOLEN_TS 0x28
80 #define IPOPT_FAKED 0xff
81 #define IPOLEN_FAKED 0x4
83 /* TCP Options Parameters */
88 #define TCPOPT_MAXSEG 2
89 #define TCPOLEN_MAXSEG 4
90 #define TCPOPT_WINDOW 3
91 #define TCPOLEN_WINDOW 3
92 #define TCPOPT_SACK_PERMITTED 4
93 #define TCPOLEN_SACK_PERMITTED 2
95 #define TCPOPT_TIMESTAMP 8
96 #define TCPOLEN_TIMESTAMP 10
97 #define TCPOPT_FAKED 0x19
98 #define TCPOLEN_FAKED 0x4
101 uint8 ip_vhl
; /* version (4bits) & header length (4 bits) */
102 uint8 ip_tos
; /* type of service */
103 uint16 ip_len
; /* length of IP datagram */
104 uint16 ip_id
; /* identification (for frags) */
105 uint16 ip_off
; /* offset (within a fragment) and flags (3 bits) */
106 uint8 ip_ttl
; /* time to live */
107 uint8 ip_p
; /* protocol number */
108 uint16 ip_xsum
; /* checksum */
109 uint32 ip_src
; /* source address */
110 uint32 ip_dst
; /* destination address */
113 /* Pseudo header for doing TCP checksum calculation */
114 struct PseudoIpHeader
{
124 uint16 tcp_sport
; /* source port */
125 uint16 tcp_dport
; /* destination port */
126 uint32 tcp_seq
; /* sequence number */
127 uint32 tcp_ack
; /* acknoledgement number */
128 uint8 tcp_hl
; /* header length (4 bits) */
129 uint8 tcp_flags
; /* flags */
130 uint16 tcp_win
; /* advertized window size */
131 uint16 tcp_xsum
; /* checksum */
132 uint16 tcp_urp
; /* urgent pointer */
138 uint8 icmp_type
; /* ICMP message type */
139 uint8 icmp_code
; /* Message code */
140 uint16 icmp_xsum
; /* checksum */
141 uint16 icmp_unused
; /* unused field */
142 uint16 icmp_mtu
; /* MTU of limiting interface */
147 struct TcpHeader
*tcp
;
150 struct ICMPUnreachableErrorPacket
{
152 struct IcmpHeader icmp
;
153 struct IpHeader off_ip
;
154 /* 8-first bytes of TCP header */
160 struct ICMPTimeExceededErrorPacket
{
162 struct IcmpHeader icmp
;
163 struct IpHeader off_ip
;
164 /* 8-first bytes of Tcpheader */
170 char *InetAddress(uint32 addr
);
172 uint16
InetChecksum(uint16
*ip_addr
, uint16
*tcp_addr
, uint16 ip_len
, uint16 tcp_len
);
174 void PrintTcpPacket(struct IPPacket
*p
);
175 void PrintICMPUnreachableErrorPacket(struct ICMPUnreachableErrorPacket
*p
);
177 void WriteIPPacket(struct IPPacket
*p
,
193 void ReadIPPacket(struct IPPacket
*p
, uint32
*src
, uint32
*dst
,
194 uint16
*sport
, uint16
*dport
, uint32
*seq
, uint32
*ack
,
195 uint8
*flags
, uint16
*win
, uint16
*urp
, uint16
*datalen
,
196 uint16
*ip_optlen
, uint16
*optlen
);
198 void StorePacket (struct IPPacket
*p
);
200 struct IPPacket
*FindHeaderBoundaries(char *p
);
202 struct IPPacket
*AllocateIPPacket(int ip_optlen
, int tcp_optlen
, int datalen
, char *str
);
204 void FreeIPPacket(struct IPPacket
**pkt_p
);
206 #endif /* _INET_H_ */