add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / src / share / def.h
blob9ae43478c0c6302bca445cd48ebf739173287b5c
1 /*****************************************************************************
2 * Copyright 2005 Daniel Ferullo *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 *****************************************************************************/
18 /**
19 * @file def.h
20 * @author Daniel Ferullo (ferullo@cmu.edu)
22 * @brief a handful of useful generic defintions
25 #ifndef __DEF_H__
26 #define __DEF_H__
28 #include "berkeleyapi.h"
29 #include "flag.h"
31 /****************************************************************************
32 * THE PORT TYPE DEFINITIONS *
33 ****************************************************************************/
35 /** @brief typedef for port type (16 bit network byte order unsigned short) */
36 typedef unsigned short port_t;
38 /** @brief a macro to so port arithmatic */
39 #define PORT_ADD(x,y) (htons(ntohs(x)+y))
41 /** @brief a macro to return the port in host byte order */
42 #define PORT_2HBO(x) (ntohs(x))
44 /** @brief macro for unknown port value */
45 #define PORT_UNKNOWN 0
48 /****************************************************************************
49 * THE IP TYPE DEFINITIONS *
50 ****************************************************************************/
52 /** @brief typedef for an ip type (32 bit network byte order unsigned long ) */
53 typedef unsigned long ip_t;
55 /** @brief macro for unknown ip value */
56 #define IP_UNKNOWN 0
58 /** @brief the maximum length an IP string can be (xxx.xxx.xxx.xxx+NULL) = 16 */
59 #define MAX_IP_STR_LEN 16
62 /****************************************************************************
63 * THE SOCK TYPE DEFINITIONS *
64 ****************************************************************************/
66 /** @brief typedef for socket descriptor type */
67 typedef int sock_t;
69 /** @brief macro for an unknown socket value */
70 #define SOCKET_UNKNOWN -1
73 /****************************************************************************
74 * THE SEQUENCE NUMBER TYPE DEFINITIONS *
75 ****************************************************************************/
77 /** @brief sequence number type (32 bit network byte order unsigned long) */
78 typedef unsigned long seq_num_t;
80 /** @brief macro to aid in sequence number math */
81 #define SEQ_NUM_ADD(x,y) (htonl(ntohl(x)+y))
83 /** @brief a macro to return the sequence number in host byte order */
84 #define SEQ_NUM_2HBO(x) (ntohl(x))
86 /** @brief macro for unknown sequence number */
87 #define SEQ_NUM_UNKNOWN 0
89 /****************************************************************************
90 * THE WINDOW TYPE DEFINITIONS *
91 ****************************************************************************/
93 /** @brief window type (16 bit network byte order unsigned short) */
94 typedef unsigned short window_t;
96 /** @brief a macro to return the window in host byte order */
97 #define WINDOW_2HBO(x) (ntohs(x))
99 /** @brief macro for unknown window size */
100 #define WINDOW_UNKNOWN 0
102 /** @brief macro for the default window size (used in spoofing) */
103 #define WINDOW_DEFAULT 0x6815
105 /****************************************************************************
106 * THE STRUCTURE TYPE DEFINITIONS *
107 ****************************************************************************/
109 /** @brief structure to hold essential information about a tcp packet */
110 struct tcp_packet_info {
111 /** @brief the destination ip address */
112 ip_t d_addr;
113 /** @brief the source ip address */
114 ip_t s_addr;
115 /** @brief the destination port */
116 port_t d_port;
117 /** @brief the source port */
118 port_t s_port;
119 /** @brief the sequence number */
120 seq_num_t seq_num;
121 /** @brief the ack number */
122 seq_num_t ack_num;
123 /** @brief was the SYN flag set in the packet? */
124 flag_t syn_flag;
125 /** @brief was the ACK flag set in the packet? */
126 flag_t ack_flag;
127 /** @brief the window for the packet */
128 window_t window;
129 } __attribute__((packed));
131 /** @brief typedef for the tcp_packet_info structure type */
132 typedef struct tcp_packet_info tcp_packet_info_t;
134 /** @brief a structure to contain the port allocation method, and a flag
135 * indicating when it is set */
136 struct port_alloc {
137 /** @brief the port allocation method */
138 flag_t method;
139 /** @brief the flag indicating if the value is set */
140 flag_t method_set;
141 /** @brief the external predicted or found port */
142 port_t ext_port;
143 /** @brief if the external port has been set */
144 flag_t ext_port_set;
145 } __attribute__((packed));
147 /** @brief typedef for the port alloc type */
148 typedef struct port_alloc port_alloc_t;
150 /** @brief structure with all the helper connection informatino */
151 struct helper_info {
152 /** @brief the helper's ip address */
153 ip_t ip;
154 /** @brief the helper's port */
155 port_t port;
156 } __attribute__((packed));
158 /** @brief typedef for the helper_info struct */
159 typedef struct helper_info helper_info_t;
161 /** @brief structure with all the peer connection information */
162 struct peer_info {
163 /** @brief the peer's ip address */
164 ip_t ip;
165 /** @brief the peer's port for connection to buddy*/
166 port_t port;
167 /** @brief a flag indicating if the info has been set */
168 flag_t set;
169 }__attribute__ ((packed));
171 /** @brief typedef for teh peer_info structure */
172 typedef struct peer_info peer_info_t;
174 /** @brief structure with all the buddy connection information */
175 struct buddy_info {
176 /** @brief the buddy's external ip address */
177 ip_t ext_ip;
178 /** @brief the buddy's internal ip address */
179 ip_t int_ip;
180 /** @brief the buddy's internal port */
181 port_t int_port;
182 /** @brief the buddy's external port */
183 port_t ext_port;
184 /** @brief a flag indicating if the identifier fields of the buddy
185 * info have been set */
186 flag_t identifier;
187 /** @brief a flag indicating if the external port has been set */
188 flag_t ext_port_set;
189 } __attribute__((packed));
191 /** @brief typedef for the buddy_info structure */
192 typedef struct buddy_info buddy_info_t;
194 #endif /* __DEF_H__ */