#include <libsa/types.h>
#include <libkern/OSByteOrder.h>
#define ETHERMTU 1500
#define ETHERHDRSIZE 14
#define ETHERCRC 4
#define KDP_MAXPACKET (ETHERHDRSIZE + ETHERMTU + ETHERCRC)
struct in_addr {
u_long s_addr;
};
struct ether_addr {
u_char ether_addr_octet[6];
};
typedef struct ether_addr enet_addr_t;
extern struct ether_addr kdp_get_mac_addr(void);
unsigned int kdp_get_ip_address(void);
struct ipovly {
caddr_t ih_next, ih_prev;
u_char ih_x1;
u_char ih_pr;
short ih_len;
struct in_addr ih_src;
struct in_addr ih_dst;
};
struct udphdr {
u_short uh_sport;
u_short uh_dport;
short uh_ulen;
u_short uh_sum;
};
struct udpiphdr {
struct ipovly ui_i;
struct udphdr ui_u;
};
#define ui_next ui_i.ih_next
#define ui_prev ui_i.ih_prev
#define ui_x1 ui_i.ih_x1
#define ui_pr ui_i.ih_pr
#define ui_len ui_i.ih_len
#define ui_src ui_i.ih_src
#define ui_dst ui_i.ih_dst
#define ui_sport ui_u.uh_sport
#define ui_dport ui_u.uh_dport
#define ui_ulen ui_u.uh_ulen
#define ui_sum ui_u.uh_sum
struct ip {
union {
u_long ip_w;
struct {
unsigned int
#ifdef __LITTLE_ENDIAN__
ip_xhl:4,
ip_xv:4,
ip_xtos:8,
ip_xlen:16;
#endif
#ifdef __BIG_ENDIAN__
ip_xv:4,
ip_xhl:4,
ip_xtos:8,
ip_xlen:16;
#endif
} ip_x;
} ip_vhltl;
u_short ip_id;
short ip_off;
#define IP_DF 0x4000
#define IP_MF 0x2000
#define IP_OFFMASK 0x1fff
u_char ip_ttl;
u_char ip_p;
u_short ip_sum;
struct in_addr ip_src,ip_dst;
};
#define ip_v ip_vhltl.ip_x.ip_xv
#define ip_hl ip_vhltl.ip_x.ip_xhl
#define ip_tos ip_vhltl.ip_x.ip_xtos
#define ip_len ip_vhltl.ip_x.ip_xlen
#define IPPROTO_UDP 17
#define IPVERSION 4
struct ether_header {
u_char ether_dhost[6];
u_char ether_shost[6];
u_short ether_type;
};
typedef struct ether_header ether_header_t;
#define ETHERTYPE_IP 0x0800
#define ntohs(x) OSSwapBigToHostInt16(x)
#define ntohl(x) OSSwapBigToHostInt32(x)
#define htons(x) OSSwapHostToBigInt16(x)
#define htonl(x) OSSwapHostToBigInt32(x)
#define ETHERTYPE_ARP 0x0806
struct arphdr {
u_short ar_hrd;
#define ARPHRD_ETHER 1
#define ARPHRD_FRELAY 15
u_short ar_pro;
u_char ar_hln;
u_char ar_pln;
u_short ar_op;
#define ARPOP_REQUEST 1
#define ARPOP_REPLY 2
#define ARPOP_REVREQUEST 3
#define ARPOP_REVREPLY 4
#define ARPOP_INVREQUEST 8
#define ARPOP_INVREPLY 9
};
#define ETHER_ADDR_LEN 6
struct ether_arp {
struct arphdr ea_hdr;
u_char arp_sha[ETHER_ADDR_LEN];
u_char arp_spa[4];
u_char arp_tha[ETHER_ADDR_LEN];
u_char arp_tpa[4];
};
#define arp_hrd ea_hdr.ar_hrd
#define arp_pro ea_hdr.ar_pro
#define arp_hln ea_hdr.ar_hln
#define arp_pln ea_hdr.ar_pln
#define arp_op ea_hdr.ar_op