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