etherfun.h revision 1.1 1 /*
2 *
3 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles D. Cranor
17 * and Seth Widoff.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /* etherfun.h */
33
34 /* constants */
35 /* ether header */
36 #define ETYPE_RARP 0x8035 /* ethertype is RARP */
37 #define ETYPE_IP 0x800 /* ethertype is IP */
38
39 /* rev arp */
40 #define PTYPE_IP 0x800 /* Protocol type is IP */
41 #define OPCODE_RARP 3 /* Optype is REVARP request */
42 #define OPCODE_REPLY 4 /* Optype is REVARP reply */
43
44 /* ip header */
45 #define IPP_UDP 17 /* IP Protocol is UDP */
46 #define IP_VERSION 4 /* IP version number */
47 #define IP_HLEN 5 /* IP header length is a fixed 50 bytes */
48 #define N 1536
49
50 /* tftp header */
51 #define FTPOP_ACKN 4 /* Opcode is acknowledge */
52 #define FTPOP_ERR 5 /* Opcode is Error */
53 #define FTP_PORT 69 /* Standard TFTP port number */
54 #define MSG "\0\1xxxxxxxx.147\0octet\0" /* implicit NULL */
55
56 /* data structures */
57
58 struct ether_header {
59 u_char ether_dhost[6];
60 u_char ether_shost[6];
61 u_short ether_type;
62 };
63
64 struct ether_arp {
65 u_short ar_hrd; /* format of hardware address */
66 u_short ar_pro; /* format of protocol address */
67 u_char ar_hln; /* length of hardware address */
68 u_char ar_pln; /* length of protocol address */
69 u_short ar_op;
70 u_char arp_sha[6]; /* sender hardware address */
71 u_char arp_spa[4]; /* sender protocol address */
72 u_char arp_tha[6]; /* target hardware address */
73 u_char arp_tpa[4]; /* target protocol address */
74 };
75
76 struct ip {
77 u_char ip_v:4, /* version */
78 ip_hl:4; /* header length */
79 u_char ip_tos; /* type of service */
80 short ip_len; /* total length */
81 u_short ip_id; /* identification */
82 short ip_off; /* fragment offset field */
83 #define IP_DF 0x4000 /* dont fragment flag */
84 #define IP_MF 0x2000 /* more fragments flag */
85 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
86 u_char ip_ttl; /* time to live */
87 u_char ip_p; /* protocol */
88 u_short ip_sum; /* checksum */
89 u_char ip_src[4];
90 u_char ip_dst[4]; /* source and dest address */
91 };
92
93 struct udp {
94 u_short uh_sport;
95 u_short uh_dport;
96 short uh_ulen;
97 u_short uh_sum;
98 };
99
100 struct tftph {
101 u_short op_code;
102 u_short block;
103 };
104
105 struct tftphr {
106 struct tftph info;
107 char data[1];
108 };
109
110 /* globals */
111 int last_ack;
112 char buf[N];
113 struct ether_header *eh = (struct ether_header *)buf;
114 struct ether_arp *rarp =
115 (struct ether_arp *)(buf + sizeof(struct ether_header));
116 struct ip *iph = (struct ip *)(buf + sizeof(struct ether_header));
117 struct udp *udph = (struct udp *)(buf + sizeof(struct ether_header) +
118 sizeof(struct ip));
119 char *tftp_r = buf + sizeof(struct ether_header) + sizeof(struct ip) +
120 sizeof(struct udp);
121 struct tftph *tftp_a = (struct tftph *)(buf + sizeof(struct ether_header) +
122 sizeof(struct ip) + sizeof(struct udp));
123 struct tftphr *tftp = (struct tftphr *)(buf + sizeof(struct ether_header) +
124 sizeof(struct ip) + sizeof(struct udp));
125