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