]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
9bccf70c A |
25 | /* |
26 | * Copyright (c) 1982, 1986, 1993 | |
27 | * The Regents of the University of California. All rights reserved. | |
28 | */ | |
1c79356b | 29 | |
9bccf70c | 30 | #include <libsa/types.h> |
1c79356b A |
31 | #include <libkern/OSByteOrder.h> /* OSSwap functions */ |
32 | ||
33 | #define ETHERMTU 1500 | |
34 | #define ETHERHDRSIZE 14 | |
35 | #define ETHERCRC 4 | |
36 | #define KDP_MAXPACKET (ETHERHDRSIZE + ETHERMTU + ETHERCRC) | |
37 | ||
38 | struct in_addr { | |
39 | u_long s_addr; | |
40 | }; | |
41 | ||
42 | struct ether_addr { | |
43 | u_char ether_addr_octet[6]; | |
44 | }; | |
45 | ||
46 | typedef struct ether_addr enet_addr_t; | |
47 | ||
9bccf70c A |
48 | extern struct ether_addr kdp_get_mac_addr(void); |
49 | unsigned int kdp_get_ip_address(void); | |
50 | ||
1c79356b A |
51 | struct ipovly { |
52 | caddr_t ih_next, ih_prev; /* for protocol sequence q's */ | |
53 | u_char ih_x1; /* (unused) */ | |
54 | u_char ih_pr; /* protocol */ | |
55 | short ih_len; /* protocol length */ | |
56 | struct in_addr ih_src; /* source internet address */ | |
57 | struct in_addr ih_dst; /* destination internet address */ | |
58 | }; | |
59 | ||
60 | struct udphdr { | |
61 | u_short uh_sport; /* source port */ | |
62 | u_short uh_dport; /* destination port */ | |
63 | short uh_ulen; /* udp length */ | |
64 | u_short uh_sum; /* udp checksum */ | |
65 | }; | |
66 | ||
67 | struct udpiphdr { | |
68 | struct ipovly ui_i; /* overlaid ip structure */ | |
69 | struct udphdr ui_u; /* udp header */ | |
70 | }; | |
71 | #define ui_next ui_i.ih_next | |
72 | #define ui_prev ui_i.ih_prev | |
73 | #define ui_x1 ui_i.ih_x1 | |
74 | #define ui_pr ui_i.ih_pr | |
75 | #define ui_len ui_i.ih_len | |
76 | #define ui_src ui_i.ih_src | |
77 | #define ui_dst ui_i.ih_dst | |
78 | #define ui_sport ui_u.uh_sport | |
79 | #define ui_dport ui_u.uh_dport | |
80 | #define ui_ulen ui_u.uh_ulen | |
81 | #define ui_sum ui_u.uh_sum | |
82 | ||
83 | struct ip { | |
84 | union { | |
85 | u_long ip_w; | |
86 | struct { | |
87 | unsigned int | |
88 | #if _BIG_ENDIAN == __LITTLE_ENDIAN__ | |
89 | ip_xhl:4, /* header length */ | |
90 | ip_xv:4, /* version */ | |
91 | ip_xtos:8, /* type of service */ | |
92 | ip_xlen:16; /* total length */ | |
93 | #endif | |
94 | #if _BIG_ENDIAN == __BIG_ENDIAN__ | |
95 | ip_xv:4, /* version */ | |
96 | ip_xhl:4, /* header length */ | |
97 | ip_xtos:8, /* type of service */ | |
98 | ip_xlen:16; /* total length */ | |
99 | #endif | |
100 | } ip_x; | |
101 | } ip_vhltl; | |
102 | u_short ip_id; /* identification */ | |
103 | short ip_off; /* fragment offset field */ | |
104 | #define IP_DF 0x4000 /* dont fragment flag */ | |
105 | #define IP_MF 0x2000 /* more fragments flag */ | |
106 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ | |
107 | u_char ip_ttl; /* time to live */ | |
108 | u_char ip_p; /* protocol */ | |
109 | u_short ip_sum; /* checksum */ | |
110 | struct in_addr ip_src,ip_dst; /* source and dest address */ | |
111 | }; | |
112 | #define ip_v ip_vhltl.ip_x.ip_xv | |
113 | #define ip_hl ip_vhltl.ip_x.ip_xhl | |
114 | #define ip_tos ip_vhltl.ip_x.ip_xtos | |
115 | #define ip_len ip_vhltl.ip_x.ip_xlen | |
116 | ||
117 | #define IPPROTO_UDP 17 | |
118 | #define IPVERSION 4 | |
119 | ||
120 | struct ether_header { | |
121 | u_char ether_dhost[6]; | |
122 | u_char ether_shost[6]; | |
123 | u_short ether_type; | |
124 | }; | |
125 | ||
126 | typedef struct ether_header ether_header_t; | |
127 | ||
128 | #define ETHERTYPE_IP 0x0800 /* IP protocol */ | |
129 | ||
130 | #define ntohs(x) OSSwapBigToHostInt16(x) | |
131 | #define htons(x) OSSwapHostToBigInt16(x) | |
9bccf70c A |
132 | |
133 | /* | |
134 | * Ethernet Address Resolution Protocol. | |
135 | * | |
136 | * See RFC 826 for protocol description. Structure below is adapted | |
137 | * to resolving internet addresses. Field names used correspond to | |
138 | * RFC 826. | |
139 | */ | |
140 | ||
141 | #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ | |
142 | ||
143 | struct arphdr { | |
144 | u_short ar_hrd; /* format of hardware address */ | |
145 | #define ARPHRD_ETHER 1 /* ethernet hardware format */ | |
146 | #define ARPHRD_FRELAY 15 /* frame relay hardware format */ | |
147 | u_short ar_pro; /* format of protocol address */ | |
148 | u_char ar_hln; /* length of hardware address */ | |
149 | u_char ar_pln; /* length of protocol address */ | |
150 | u_short ar_op; /* one of: */ | |
151 | #define ARPOP_REQUEST 1 /* request to resolve address */ | |
152 | #define ARPOP_REPLY 2 /* response to previous request */ | |
153 | #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ | |
154 | #define ARPOP_REVREPLY 4 /* response giving protocol address */ | |
155 | #define ARPOP_INVREQUEST 8 /* request to identify peer */ | |
156 | #define ARPOP_INVREPLY 9 /* response identifying peer */ | |
157 | }; | |
158 | ||
159 | #define ETHER_ADDR_LEN 6 | |
160 | ||
161 | struct ether_arp { | |
162 | struct arphdr ea_hdr; /* fixed-size header */ | |
163 | u_char arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ | |
164 | u_char arp_spa[4]; /* sender protocol address */ | |
165 | u_char arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ | |
166 | u_char arp_tpa[4]; /* target protocol address */ | |
167 | }; | |
168 | #define arp_hrd ea_hdr.ar_hrd | |
169 | #define arp_pro ea_hdr.ar_pro | |
170 | #define arp_hln ea_hdr.ar_hln | |
171 | #define arp_pln ea_hdr.ar_pln | |
172 | #define arp_op ea_hdr.ar_op |