|
|
1.1 root 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: #include <libkern/OSByteOrder.h> /* OSSwap functions */
24:
25: #define ETHERMTU 1500
26: #define ETHERHDRSIZE 14
27: #define ETHERCRC 4
28: #define KDP_MAXPACKET (ETHERHDRSIZE + ETHERMTU + ETHERCRC)
29:
30: struct in_addr {
31: u_long s_addr;
32: };
33:
34: struct ether_addr {
35: u_char ether_addr_octet[6];
36: };
37:
38: typedef struct ether_addr enet_addr_t;
39:
40: struct ipovly {
41: caddr_t ih_next, ih_prev; /* for protocol sequence q's */
42: u_char ih_x1; /* (unused) */
43: u_char ih_pr; /* protocol */
44: short ih_len; /* protocol length */
45: struct in_addr ih_src; /* source internet address */
46: struct in_addr ih_dst; /* destination internet address */
47: };
48:
49: struct udphdr {
50: u_short uh_sport; /* source port */
51: u_short uh_dport; /* destination port */
52: short uh_ulen; /* udp length */
53: u_short uh_sum; /* udp checksum */
54: };
55:
56: struct udpiphdr {
57: struct ipovly ui_i; /* overlaid ip structure */
58: struct udphdr ui_u; /* udp header */
59: };
60: #define ui_next ui_i.ih_next
61: #define ui_prev ui_i.ih_prev
62: #define ui_x1 ui_i.ih_x1
63: #define ui_pr ui_i.ih_pr
64: #define ui_len ui_i.ih_len
65: #define ui_src ui_i.ih_src
66: #define ui_dst ui_i.ih_dst
67: #define ui_sport ui_u.uh_sport
68: #define ui_dport ui_u.uh_dport
69: #define ui_ulen ui_u.uh_ulen
70: #define ui_sum ui_u.uh_sum
71:
72: struct ip {
73: union {
74: u_long ip_w;
75: struct {
76: unsigned int
77: #if _BIG_ENDIAN == __LITTLE_ENDIAN__
78: ip_xhl:4, /* header length */
79: ip_xv:4, /* version */
80: ip_xtos:8, /* type of service */
81: ip_xlen:16; /* total length */
82: #endif
83: #if _BIG_ENDIAN == __BIG_ENDIAN__
84: ip_xv:4, /* version */
85: ip_xhl:4, /* header length */
86: ip_xtos:8, /* type of service */
87: ip_xlen:16; /* total length */
88: #endif
89: } ip_x;
90: } ip_vhltl;
91: u_short ip_id; /* identification */
92: short ip_off; /* fragment offset field */
93: #define IP_DF 0x4000 /* dont fragment flag */
94: #define IP_MF 0x2000 /* more fragments flag */
95: #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
96: u_char ip_ttl; /* time to live */
97: u_char ip_p; /* protocol */
98: u_short ip_sum; /* checksum */
99: struct in_addr ip_src,ip_dst; /* source and dest address */
100: };
101: #define ip_v ip_vhltl.ip_x.ip_xv
102: #define ip_hl ip_vhltl.ip_x.ip_xhl
103: #define ip_tos ip_vhltl.ip_x.ip_xtos
104: #define ip_len ip_vhltl.ip_x.ip_xlen
105:
106: #define IPPROTO_UDP 17
107: #define IPVERSION 4
108:
109: struct ether_header {
110: u_char ether_dhost[6];
111: u_char ether_shost[6];
112: u_short ether_type;
113: };
114:
115: typedef struct ether_header ether_header_t;
116:
117: #define ETHERTYPE_IP 0x0800 /* IP protocol */
118:
119: #define ntohs(x) OSSwapBigToHostInt16(x)
120: #define htons(x) OSSwapHostToBigInt16(x)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.