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