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