00001 /***************************************************************************** 00002 * Copyright 2005 Daniel Ferullo * 00003 * * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); * 00005 * you may not use this file except in compliance with the License. * 00006 * You may obtain a copy of the License at * 00007 * * 00008 * http://www.apache.org/licenses/LICENSE-2.0 * 00009 * * 00010 * Unless required by applicable law or agreed to in writing, software * 00011 * distributed under the License is distributed on an "AS IS" BASIS, * 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00013 * See the License for the specific language governing permissions and * 00014 * limitations under the License. * 00015 * * 00016 *****************************************************************************/ 00017 00018 /** 00019 * @file def.h 00020 * @author Daniel Ferullo (ferullo@cmu.edu) 00021 * 00022 * @brief a handful of useful generic defintions 00023 */ 00024 00025 #ifndef __DEF_H__ 00026 #define __DEF_H__ 00027 00028 #include "berkeleyapi.h" 00029 #include "flag.h" 00030 00031 /**************************************************************************** 00032 * THE PORT TYPE DEFINITIONS * 00033 ****************************************************************************/ 00034 00035 /** @brief typedef for port type (16 bit network byte order unsigned short) */ 00036 typedef unsigned short port_t; 00037 00038 /** @brief a macro to so port arithmatic */ 00039 #define PORT_ADD(x,y) (htons(ntohs(x)+y)) 00040 00041 /** @brief a macro to return the port in host byte order */ 00042 #define PORT_2HBO(x) (ntohs(x)) 00043 00044 /** @brief macro for unknown port value */ 00045 #define PORT_UNKNOWN 0 00046 00047 00048 /**************************************************************************** 00049 * THE IP TYPE DEFINITIONS * 00050 ****************************************************************************/ 00051 00052 /** @brief typedef for an ip type (32 bit network byte order unsigned long ) */ 00053 typedef unsigned long ip_t; 00054 00055 /** @brief macro for unknown ip value */ 00056 #define IP_UNKNOWN 0 00057 00058 /** @brief the maximum length an IP string can be (xxx.xxx.xxx.xxx+NULL) = 16 */ 00059 #define MAX_IP_STR_LEN 16 00060 00061 00062 /**************************************************************************** 00063 * THE SOCK TYPE DEFINITIONS * 00064 ****************************************************************************/ 00065 00066 /** @brief typedef for socket descriptor type */ 00067 typedef int sock_t; 00068 00069 /** @brief macro for an unknown socket value */ 00070 #define SOCKET_UNKNOWN -1 00071 00072 00073 /**************************************************************************** 00074 * THE SEQUENCE NUMBER TYPE DEFINITIONS * 00075 ****************************************************************************/ 00076 00077 /** @brief sequence number type (32 bit network byte order unsigned long) */ 00078 typedef unsigned long seq_num_t; 00079 00080 /** @brief macro to aid in sequence number math */ 00081 #define SEQ_NUM_ADD(x,y) (htonl(ntohl(x)+y)) 00082 00083 /** @brief a macro to return the sequence number in host byte order */ 00084 #define SEQ_NUM_2HBO(x) (ntohl(x)) 00085 00086 /** @brief macro for unknown sequence number */ 00087 #define SEQ_NUM_UNKNOWN 0 00088 00089 /**************************************************************************** 00090 * THE WINDOW TYPE DEFINITIONS * 00091 ****************************************************************************/ 00092 00093 /** @brief window type (16 bit network byte order unsigned short) */ 00094 typedef unsigned short window_t; 00095 00096 /** @brief a macro to return the window in host byte order */ 00097 #define WINDOW_2HBO(x) (ntohs(x)) 00098 00099 /** @brief macro for unknown window size */ 00100 #define WINDOW_UNKNOWN 0 00101 00102 /** @brief macro for the default window size (used in spoofing) */ 00103 #define WINDOW_DEFAULT 0x6815 00104 00105 /**************************************************************************** 00106 * THE STRUCTURE TYPE DEFINITIONS * 00107 ****************************************************************************/ 00108 00109 /** @brief structure to hold essential information about a tcp packet */ 00110 struct tcp_packet_info { 00111 /** @brief the destination ip address */ 00112 ip_t d_addr; 00113 /** @brief the source ip address */ 00114 ip_t s_addr; 00115 /** @brief the destination port */ 00116 port_t d_port; 00117 /** @brief the source port */ 00118 port_t s_port; 00119 /** @brief the sequence number */ 00120 seq_num_t seq_num; 00121 /** @brief the ack number */ 00122 seq_num_t ack_num; 00123 /** @brief was the SYN flag set in the packet? */ 00124 flag_t syn_flag; 00125 /** @brief was the ACK flag set in the packet? */ 00126 flag_t ack_flag; 00127 /** @brief the window for the packet */ 00128 window_t window; 00129 } __attribute__((packed)); 00130 00131 /** @brief typedef for the tcp_packet_info structure type */ 00132 typedef struct tcp_packet_info tcp_packet_info_t; 00133 00134 /** @brief a structure to contain the port allocation method, and a flag 00135 * indicating when it is set */ 00136 struct port_alloc { 00137 /** @brief the port allocation method */ 00138 flag_t method; 00139 /** @brief the flag indicating if the value is set */ 00140 flag_t method_set; 00141 /** @brief the external predicted or found port */ 00142 port_t ext_port; 00143 /** @brief if the external port has been set */ 00144 flag_t ext_port_set; 00145 } __attribute__((packed)); 00146 00147 /** @brief typedef for the port alloc type */ 00148 typedef struct port_alloc port_alloc_t; 00149 00150 /** @brief structure with all the helper connection informatino */ 00151 struct helper_info { 00152 /** @brief the helper's ip address */ 00153 ip_t ip; 00154 /** @brief the helper's port */ 00155 port_t port; 00156 } __attribute__((packed)); 00157 00158 /** @brief typedef for the helper_info struct */ 00159 typedef struct helper_info helper_info_t; 00160 00161 /** @brief structure with all the peer connection information */ 00162 struct peer_info { 00163 /** @brief the peer's ip address */ 00164 ip_t ip; 00165 /** @brief the peer's port for connection to buddy*/ 00166 port_t port; 00167 /** @brief a flag indicating if the info has been set */ 00168 flag_t set; 00169 }__attribute__ ((packed)); 00170 00171 /** @brief typedef for teh peer_info structure */ 00172 typedef struct peer_info peer_info_t; 00173 00174 /** @brief structure with all the buddy connection information */ 00175 struct buddy_info { 00176 /** @brief the buddy's external ip address */ 00177 ip_t ext_ip; 00178 /** @brief the buddy's internal ip address */ 00179 ip_t int_ip; 00180 /** @brief the buddy's internal port */ 00181 port_t int_port; 00182 /** @brief the buddy's external port */ 00183 port_t ext_port; 00184 /** @brief a flag indicating if the identifier fields of the buddy 00185 * info have been set */ 00186 flag_t identifier; 00187 /** @brief a flag indicating if the external port has been set */ 00188 flag_t ext_port_set; 00189 } __attribute__((packed)); 00190 00191 /** @brief typedef for the buddy_info structure */ 00192 typedef struct buddy_info buddy_info_t; 00193 00194 #endif /* __DEF_H__ */ 00195