ip_compat.h revision 53024
1/* 2 * (C)opyright 1995 by Darren Reed. 3 * 4 * This code may be freely distributed as long as it retains this notice 5 * and is not changed in any way. The author accepts no responsibility 6 * for the use of this software. I hate legaleese, don't you ? 7 * 8 * @(#)ip_compat.h 1.2 12/7/95 9 */ 10 11/* 12 * These #ifdef's are here mainly for linux, but who knows, they may 13 * not be in other places or maybe one day linux will grow up and some 14 * of these will turn up there too. 15 */ 16#ifndef ICMP_UNREACH 17# define ICMP_UNREACH ICMP_DEST_UNREACH 18#endif 19#ifndef ICMP_SOURCEQUENCH 20# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH 21#endif 22#ifndef ICMP_TIMXCEED 23# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED 24#endif 25#ifndef ICMP_PARAMPROB 26# define ICMP_PARAMPROB ICMP_PARAMETERPROB 27#endif 28#ifndef IPVERSION 29# define IPVERSION 4 30#endif 31#ifndef IPOPT_MINOFF 32# define IPOPT_MINOFF 4 33#endif 34#ifndef IPOPT_COPIED 35# define IPOPT_COPIED(x) ((x)&0x80) 36#endif 37#ifndef IPOPT_EOL 38# define IPOPT_EOL 0 39#endif 40#ifndef IPOPT_NOP 41# define IPOPT_NOP 1 42#endif 43#ifndef IP_MF 44# define IP_MF ((u_short)0x2000) 45#endif 46#ifndef ETHERTYPE_IP 47# define ETHERTYPE_IP ((u_short)0x0800) 48#endif 49#ifndef TH_FIN 50# define TH_FIN 0x01 51#endif 52#ifndef TH_SYN 53# define TH_SYN 0x02 54#endif 55#ifndef TH_RST 56# define TH_RST 0x04 57#endif 58#ifndef TH_PUSH 59# define TH_PUSH 0x08 60#endif 61#ifndef TH_ACK 62# define TH_ACK 0x10 63#endif 64#ifndef TH_URG 65# define TH_URG 0x20 66#endif 67#ifndef IPOPT_EOL 68# define IPOPT_EOL 0 69#endif 70#ifndef IPOPT_NOP 71# define IPOPT_NOP 1 72#endif 73#ifndef IPOPT_RR 74# define IPOPT_RR 7 75#endif 76#ifndef IPOPT_TS 77# define IPOPT_TS 68 78#endif 79#ifndef IPOPT_SECURITY 80# define IPOPT_SECURITY 130 81#endif 82#ifndef IPOPT_LSRR 83# define IPOPT_LSRR 131 84#endif 85#ifndef IPOPT_SATID 86# define IPOPT_SATID 136 87#endif 88#ifndef IPOPT_SSRR 89# define IPOPT_SSRR 137 90#endif 91#ifndef IPOPT_SECUR_UNCLASS 92# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) 93#endif 94#ifndef IPOPT_SECUR_CONFID 95# define IPOPT_SECUR_CONFID ((u_short)0xf135) 96#endif 97#ifndef IPOPT_SECUR_EFTO 98# define IPOPT_SECUR_EFTO ((u_short)0x789a) 99#endif 100#ifndef IPOPT_SECUR_MMMM 101# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) 102#endif 103#ifndef IPOPT_SECUR_RESTR 104# define IPOPT_SECUR_RESTR ((u_short)0xaf13) 105#endif 106#ifndef IPOPT_SECUR_SECRET 107# define IPOPT_SECUR_SECRET ((u_short)0xd788) 108#endif 109#ifndef IPOPT_SECUR_TOPSECRET 110# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 111#endif 112 113#ifdef linux 114# if LINUX < 0200 115# define icmp icmphdr 116# define icmp_type type 117# define icmp_code code 118# endif 119 120/* 121 * From /usr/include/netinet/ip_var.h 122 * !%@#!$@# linux... 123 */ 124struct ipovly { 125 caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 126 u_char ih_x1; /* (unused) */ 127 u_char ih_pr; /* protocol */ 128 short ih_len; /* protocol length */ 129 struct in_addr ih_src; /* source internet address */ 130 struct in_addr ih_dst; /* destination internet address */ 131}; 132 133typedef struct { 134 __u16 th_sport; 135 __u16 th_dport; 136 __u32 th_seq; 137 __u32 th_ack; 138# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 139 defined(vax) 140 __u8 th_res:4; 141 __u8 th_off:4; 142#else 143 __u8 th_off:4; 144 __u8 th_res:4; 145#endif 146 __u8 th_flags; 147 __u16 th_win; 148 __u16 th_sum; 149 __u16 th_urp; 150} tcphdr_t; 151 152typedef struct { 153 __u16 uh_sport; 154 __u16 uh_dport; 155 __s16 uh_ulen; 156 __u16 uh_sum; 157} udphdr_t; 158 159typedef struct { 160# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 161 defined(vax) 162 __u8 ip_hl:4; 163 __u8 ip_v:4; 164# else 165 __u8 ip_hl:4; 166 __u8 ip_v:4; 167# endif 168 __u8 ip_tos; 169 __u16 ip_len; 170 __u16 ip_id; 171 __u16 ip_off; 172 __u8 ip_ttl; 173 __u8 ip_p; 174 __u16 ip_sum; 175 struct in_addr ip_src; 176 struct in_addr ip_dst; 177} ip_t; 178 179typedef struct { 180 __u8 ether_dhost[6]; 181 __u8 ether_shost[6]; 182 __u16 ether_type; 183} ether_header_t; 184 185typedef struct icmp { 186 u_char icmp_type; /* type of message, see below */ 187 u_char icmp_code; /* type sub code */ 188 u_short icmp_cksum; /* ones complement cksum of struct */ 189 union { 190 u_char ih_pptr; /* ICMP_PARAMPROB */ 191 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 192 struct ih_idseq { 193 n_short icd_id; 194 n_short icd_seq; 195 } ih_idseq; 196 int ih_void; 197 } icmp_hun; 198#define icmp_pptr icmp_hun.ih_pptr 199#define icmp_gwaddr icmp_hun.ih_gwaddr 200#define icmp_id icmp_hun.ih_idseq.icd_id 201#define icmp_seq icmp_hun.ih_idseq.icd_seq 202#define icmp_void icmp_hun.ih_void 203 union { 204 struct id_ts { 205 n_time its_otime; 206 n_time its_rtime; 207 n_time its_ttime; 208 } id_ts; 209 struct id_ip { 210 ip_t idi_ip; 211 /* options and then 64 bits of data */ 212 } id_ip; 213 u_long id_mask; 214 char id_data[1]; 215 } icmp_dun; 216#define icmp_otime icmp_dun.id_ts.its_otime 217#define icmp_rtime icmp_dun.id_ts.its_rtime 218#define icmp_ttime icmp_dun.id_ts.its_ttime 219#define icmp_ip icmp_dun.id_ip.idi_ip 220#define icmp_mask icmp_dun.id_mask 221#define icmp_data icmp_dun.id_data 222} icmphdr_t; 223 224# define bcopy(a,b,c) memmove(b,a,c) 225# define bcmp(a,b,c) memcmp(a,b,c) 226 227# define ifnet device 228 229#else 230 231typedef struct udphdr udphdr_t; 232typedef struct tcphdr tcphdr_t; 233typedef struct ip ip_t; 234typedef struct ether_header ether_header_t; 235 236#endif 237 238#if defined(__SVR4) || defined(__svr4__) 239# define bcopy(a,b,c) memmove(b,a,c) 240# define bcmp(a,b,c) memcmp(a,b,c) 241# define bzero(a,b) memset(a,0,b) 242#endif 243