1
/*** This Programs/Libraries are (C)opyright by Sebastian Krahmer.
2
*** You may use it under the terms of the GPL. You should have
3
*** already received the file COPYING that shows you your rights.
4
*** Please look at COPYING for further license-details.
6
*** THERE IS ABSOLUTELY NO WARRANTY. SO YOU USE IT AT YOUR OWN RISK.
7
*** IT WAS WRITTEN IN THE HOPE THAT IT WILL BE USEFULL. I AM NOT RESPONSIBLE
8
*** FOR ANY DAMAGE YOU MAYBE GET DUE TO USING MY PROGRAMS.
12
#ifndef _USI_STRUCTS_H_
13
#define _USI_STRUCTS_H_
15
#include <sys/types.h>
17
#include <sys/socket.h>
19
#include <netinet/in.h>
20
#include <arpa/inet.h>
27
#define MAXHOSTLEN 1000
31
/* putting an own version of
32
* iphdr, udphdr, tcphdr, icmphdr and pseudohdr
33
* in usipp namespace to avoid collision with
34
* kernel ones. Mostly the IP etc. structs from system to system differ
35
* and are often broken.
44
/* This is a name for the 48 bit ethernet address available on many
49
u_int8_t ether_addr_octet[ETH_ALEN];
54
u_int8_t ether_dhost[ETH_ALEN]; // destination eth addr
55
u_int8_t ether_shost[ETH_ALEN]; // source ether addr
56
u_int16_t ether_type; // packet type ID field
61
* These are the defined Ethernet Protocol ID's.
63
#define ETH_P_LOOP 0x0060 // Ethernet Loopback packet
64
#define ETH_P_ECHO 0x0200 // Ethernet Echo packet
66
#define ETH_P_PUP 0x0200 // Xerox PUP packet
68
#define ETH_P_IP 0x0800 // Internet Protocol packet
69
#define ETH_P_X25 0x0805 // CCITT X.25
70
#define ETH_P_ARP 0x0806 // Address Resolution packet
71
#define ETH_P_BPQ 0x08FF // G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */
72
#define ETH_P_DEC 0x6000 // DEC Assigned proto
73
#define ETH_P_DNA_DL 0x6001 // DEC DNA Dump/Load
74
#define ETH_P_DNA_RC 0x6002 // DEC DNA Remote Console
75
#define ETH_P_DNA_RT 0x6003 // DEC DNA Routing
76
#define ETH_P_LAT 0x6004 // DEC LAT
77
#define ETH_P_DIAG 0x6005 // DEC Diagnostics
78
#define ETH_P_CUST 0x6006 // DEC Customer use
79
#define ETH_P_SCA 0x6007 // DEC Systems Comms Arch
80
#define ETH_P_RARP 0x8035 // Reverse Addr Res packet
81
#define ETH_P_ATALK 0x809B // Appletalk DDP
82
#define ETH_P_AARP 0x80F3 // Appletalk AARP
83
#define ETH_P_IPX 0x8137 // IPX over DIX
84
#define ETH_P_IPV6 0x86DD // IPv6 over bluebook
87
* Non DIX types. Won't clash for 1500 types.
90
#define ETH_P_802_3 0x0001 // Dummy type for 802.3 frames
91
#define ETH_P_AX25 0x0002 // Dummy protocol id for AX.25
92
#define ETH_P_ALL 0x0003 // Every packet (be careful!!!)
93
#define ETH_P_802_2 0x0004 // 802.2 frames
94
#define ETH_P_SNAP 0x0005 // Internal only
95
#define ETH_P_DDCMP 0x0006 // DEC DDCMP: Internal only
96
#define ETH_P_WAN_PPP 0x0007 // Dummy type for WAN PPP frames
97
#define ETH_P_PPP_MP 0x0008 // Dummy type for PPP MP frames
98
#define ETH_P_LOCALTALK 0x0009 // Localtalk pseudo type
99
#define ETH_P_PPPTALK 0x0010 // Dummy type for Atalk over PPP
100
#define ETH_P_TR_802_2 0x0011 // 802.2 frames
101
#define ETH_P_MOBITEX 0x0015 // Mobitex (kaz@cafe.net)
102
#define ETH_P_CONTROL 0x0016 // Card specific control frames
103
#define ETH_P_IRDA 0x0017 // Linux/IR
106
/* See RFC 826 for protocol description. ARP packets are variable
107
* in size; the arphdr structure defines the fixed-length portion.
108
* Protocol type values are the same as those for 10 Mb/s Ethernet.
109
* It is followed by the variable-sized fields ar_sha, arp_spa,
110
* arp_tha and arp_tpa in that order, according to the lengths
111
* specified. Field names used correspond to RFC 826.
114
u_int16_t ar_hrd; // Format of hardware address.
115
u_int16_t ar_pro; // Format of protocol address.
116
unsigned char ar_hln; // Length of hardware address.
117
unsigned char ar_pln; // Length of protocol address.
118
u_int16_t ar_op; // ARP opcode (command).
120
/* Ethernet looks like this : This bit is variable sized
123
unsigned char __ar_sha[ETH_ALEN]; // Sender hardware address.
124
unsigned char __ar_sip[4]; // Sender IP address.
125
unsigned char __ar_tha[ETH_ALEN]; // Target hardware address.
126
unsigned char __ar_tip[4]; // Target IP address.
131
/* ARP protocol opcodes. */
132
#define ARPOP_REQUEST 1 // ARP request.
133
#define ARPOP_REPLY 2 // ARP reply.
134
#define ARPOP_RREQUEST 3 // RARP request.
135
#define ARPOP_RREPLY 4 // RARP reply.
137
/* ARP protocol HARDWARE identifiers. */
138
#define ARPHRD_NETROM 0 // From KA9Q: NET/ROM pseudo.
139
#define ARPHRD_ETHER 1 // Ethernet 10/100Mbps.
140
#define ARPHRD_EETHER 2 // Experimental Ethernet.
141
#define ARPHRD_AX25 3 // AX.25 Level 2.
142
#define ARPHRD_PRONET 4 // PROnet token ring.
143
#define ARPHRD_CHAOS 5 // Chaosnet.
144
#define ARPHRD_IEEE802 6 // IEEE 802.2 Ethernet/TR/TB.
145
#define ARPHRD_ARCNET 7 // ARCnet.
146
#define ARPHRD_APPLETLK 8 // APPLEtalk.
147
#define ARPHRD_DLCI 15 // Frame Relay DLCI.
148
#define ARPHRD_METRICOM 23 // Metricom STRIP (new IANA id).
150
/* Dummy types for non ARP hardware */
151
#define ARPHRD_SLIP 256
152
#define ARPHRD_CSLIP 257
153
#define ARPHRD_SLIP6 258
154
#define ARPHRD_CSLIP6 259
155
#define ARPHRD_RSRVD 260 /* Notional KISS type. */
156
#define ARPHRD_ADAPT 264
157
#define ARPHRD_ROSE 270
158
#define ARPHRD_X25 271 /* CCITT X.25. */
159
#define ARPHRD_PPP 512
161
#define ARPHRD_HDLC 513 /* (Cisco) HDLC. */
163
#define ARPHRD_LAPB 516 /* LAPB. */
165
#define ARPHRD_TUNNEL 768 /* IPIP tunnel. */
166
#define ARPHRD_TUNNEL6 769 /* IPIP6 tunnel. */
167
#define ARPHRD_FRAD 770 /* Frame Relay Access Device. */
168
#define ARPHRD_SKIP 771 /* SKIP vif. */
169
#define ARPHRD_LOOPBACK 772 /* Loopback device. */
170
#define ARPHRD_LOCALTLK 773 /* Localtalk device. */
171
#define ARPHRD_FDDI 774 /* Fiber Distributed Data Interface. */
172
#define ARPHRD_BIF 775 /* AP1000 BIF. */
173
#define ARPHRD_SIT 776 /* sit0 device - IPv6-in-IPv4. */
174
#define ARPHRD_IPDDP 777 /* IP-in-DDP tunnel. */
175
#define ARPHRD_IPGRE 778 /* GRE over IP. */
176
#define ARPHRD_PIMREG 779 /* PIMSM register interface. */
177
#define ARPHRD_HIPPI 780 /* High Performance Parallel I'face. */
178
#define ARPHRD_ASH 781 /* (Nexus Electronics) Ash. */
179
#define ARPHRD_ECONET 782 /* Acorn Econet. */
180
#define ARPHRD_IRDA 783 /* Linux/IR. */
181
#define ARPHRD_FCPP 784 /* Point to point fibrechanel. */
182
#define ARPHRD_FCAL 785 /* Fibrechanel arbitrated loop. */
183
#define ARPHRD_FCPL 786 /* Fibrechanel public loop. */
184
#define ARPHRD_FCPFABRIC 787 /* Fibrechanel fabric. */
186
/* See RFC 826 for protocol description. Structure below is adapted
187
* to resolving internet addresses. Field names used correspond to
191
struct arphdr ea_hdr; // fixed-size header
192
u_int8_t arp_sha[ETH_ALEN]; // sender hardware address
193
u_int8_t arp_spa[4]; // sender protocol address
194
u_int8_t arp_tha[ETH_ALEN]; // target hardware address
195
u_int8_t arp_tpa[4]; // target protocol address
197
#define arp_hrd ea_hdr.ar_hrd
198
#define arp_pro ea_hdr.ar_pro
199
#define arp_hln ea_hdr.ar_hln
200
#define arp_pln ea_hdr.ar_pln
201
#define arp_op ea_hdr.ar_op
223
#define ICMP_ECHOREPLY 0 /* Echo Reply */
224
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
225
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
226
#define ICMP_REDIRECT 5 /* Redirect (change route) */
227
#define ICMP_ECHO 8 /* Echo Request */
228
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
229
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
230
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
231
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
232
#define ICMP_INFO_REQUEST 15 /* Information Request */
233
#define ICMP_INFO_REPLY 16 /* Information Reply */
234
#define ICMP_ADDRESS 17 /* Address Mask Request */
235
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
236
#define NR_ICMP_TYPES 18
239
/* Codes for UNREACH. */
240
#define ICMP_NET_UNREACH 0 /* Network Unreachable */
241
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
242
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
243
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
244
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
245
#define ICMP_SR_FAILED 5 /* Source Route failed */
246
#define ICMP_NET_UNKNOWN 6
247
#define ICMP_HOST_UNKNOWN 7
248
#define ICMP_HOST_ISOLATED 8
249
#define ICMP_NET_ANO 9
250
#define ICMP_HOST_ANO 10
251
#define ICMP_NET_UNR_TOS 11
252
#define ICMP_HOST_UNR_TOS 12
253
#define ICMP_PKT_FILTERED 13 /* Packet filtered */
254
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
255
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
256
#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
258
/* Codes for REDIRECT. */
259
#define ICMP_REDIR_NET 0 /* Redirect Net */
260
#define ICMP_REDIR_HOST 1 /* Redirect Host */
261
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
262
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
264
/* Codes for TIME_EXCEEDED. */
265
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
266
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
268
#define PING_PAYLOAD_SIZE 56
269
#define TIMESTAMP_PAYLOAD_SIZE 12
270
#define ADDRMASK_PAYLOAD_SIZE 4
281
* The pseudo-header is used to calculate checksums over UDP
295
u_int16_t th_sport; // source port
296
u_int16_t th_dport; // destination port
297
u_int32_t th_seq; // sequence number
298
u_int32_t th_ack; // acknowledgement number
299
//#if __BYTE_ORDER == __LITTLE_ENDIAN
300
#ifndef WORDS_BIGENDIAN
301
u_int8_t th_x2:4; // (unused)
302
u_int8_t th_off:4; // data offset
303
//#elif __BYTE_ORDER == __BIG_ENDIAN
305
u_int8_t th_off:4; // data offset
306
u_int8_t th_x2:4; // (unused)
327
u_int16_t th_win; // window
328
u_int16_t th_sum; // checksum
329
u_int16_t th_urp; // urgent pointer
335
//#if __BYTE_ORDER == __LITTLE_ENDIAN
336
#ifndef WORDS_BIGENDIAN
339
//#elif __BYTE_ORDER == __BIG_ENDIAN
344
//# error "Please fix <bits/endian.h>"
360
#define IP_OFFMASK 0x1fff
367
/* The options start here. */
371
/* describes a fragment for re-assembling routines
374
int id; // the IP id-filed
375
int len; // how much data received yet?
376
int origLen; // and how much has it to be?
377
int userLen; // and how much did we saved?
378
char *data; // the packet itself
381
// from netinet/tcp.h
384
#define TCPOPT_MAXSEG 2
385
#define TCPOLEN_MAXSEG 4
386
#define TCPOPT_WINDOW 3
387
#define TCPOLEN_WINDOW 3
388
#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
389
#define TCPOLEN_SACK_PERMITTED 2
390
#define TCPOPT_SACK 5 /* Experimental */
391
#define TCPOPT_TIMESTAMP 8
392
#define TCPOLEN_TIMESTAMP 10
393
#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
399
// nothing for kind 0 and 1
400
char one_byte; // kind: 3
401
u_int16_t one_word; // kind: 2
402
u_int32_t two_dwords[2]; // kind: 8 (timestamp)
403
char unknown[20]; // default
409
#endif // _USI_STRUCTS_H_