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