12632SN/A/*
22632SN/A * eth.h
32632SN/A *
42632SN/A * Ethernet.
52632SN/A *
62632SN/A * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
72632SN/A *
82632SN/A * $Id: eth.h,v 1.15 2004/01/03 08:47:23 dugsong Exp $
92632SN/A */
102632SN/A
112632SN/A#ifndef DNET_ETH_H
122632SN/A#define DNET_ETH_H
132632SN/A
142632SN/A#define ETH_ADDR_LEN	6
152632SN/A#define ETH_ADDR_BITS	48
162632SN/A#define ETH_TYPE_LEN	2
172632SN/A#define ETH_CRC_LEN	4
182632SN/A#define ETH_HDR_LEN	14
192632SN/A
202632SN/A#define ETH_LEN_MIN	64		/* minimum frame length with CRC */
212632SN/A#define ETH_LEN_MAX	1518		/* maximum frame length with CRC */
222632SN/A
232632SN/A#define ETH_MTU		(ETH_LEN_MAX - ETH_HDR_LEN - ETH_CRC_LEN)
242632SN/A#define ETH_MIN		(ETH_LEN_MIN - ETH_HDR_LEN - ETH_CRC_LEN)
252632SN/A
262632SN/Atypedef struct eth_addr {
272632SN/A        uint8_t		data[ETH_ADDR_LEN];
282632SN/A} eth_addr_t;
292632SN/A
302632SN/Astruct eth_hdr {
312632SN/A        eth_addr_t	eth_dst;	/* destination address */
322632SN/A        eth_addr_t	eth_src;	/* source address */
332632SN/A        uint16_t	eth_type;	/* payload type */
342632SN/A};
352632SN/A
362632SN/A/*
372632SN/A * Ethernet payload types - http://standards.ieee.org/regauth/ethertype
382632SN/A */
392632SN/A#define ETH_TYPE_PUP	0x0200		/* PUP protocol */
402632SN/A#define ETH_TYPE_IP	0x0800		/* IP protocol */
412632SN/A#define ETH_TYPE_ARP	0x0806		/* address resolution protocol */
422632SN/A#define ETH_TYPE_REVARP	0x8035		/* reverse addr resolution protocol */
432632SN/A#define ETH_TYPE_8021Q	0x8100		/* IEEE 802.1Q VLAN tagging */
442632SN/A#define ETH_TYPE_IPV6	0x86DD		/* IPv6 protocol */
452632SN/A#define ETH_TYPE_MPLS	0x8847		/* MPLS */
462632SN/A#define ETH_TYPE_MPLS_MCAST	0x8848	/* MPLS Multicast */
472632SN/A#define ETH_TYPE_PPPOEDISC	0x8863	/* PPP Over Ethernet Discovery Stage */
482632SN/A#define ETH_TYPE_PPPOE	0x8864		/* PPP Over Ethernet Session Stage */
492632SN/A#define ETH_TYPE_LOOPBACK	0x9000	/* used to test interfaces */
502632SN/A
512632SN/A#define ETH_IS_MULTICAST(ea)	(*(ea) & 0x01) /* is address mcast/bcast? */
522632SN/A
532632SN/A#define ETH_ADDR_BROADCAST	"\xff\xff\xff\xff\xff\xff"
542632SN/A
552632SN/A#define eth_pack_hdr(h, dst, src, type) do {			\
562632SN/A        struct eth_hdr *eth_pack_p = (struct eth_hdr *)(h);	\
572632SN/A        memmove(&eth_pack_p->eth_dst, &(dst), ETH_ADDR_LEN);	\
582632SN/A        memmove(&eth_pack_p->eth_src, &(src), ETH_ADDR_LEN);	\
592632SN/A        eth_pack_p->eth_type = htons(type);			\
602632SN/A} while (0)
612632SN/A
622632SN/Atypedef struct eth_handle eth_t;
632632SN/A
642632SN/A__BEGIN_DECLS
652632SN/Aeth_t	*eth_open(const char *device);
662632SN/Aint	 eth_get(eth_t *e, eth_addr_t *ea);
672632SN/Aint	 eth_set(eth_t *e, const eth_addr_t *ea);
682632SN/Asize_t	 eth_send(eth_t *e, const void *buf, size_t len);
692632SN/Aeth_t	*eth_close(eth_t *e);
702632SN/A
712632SN/Achar	*eth_ntop(const eth_addr_t *eth, char *dst, size_t len);
722632SN/Aint	 eth_pton(const char *src, eth_addr_t *dst);
732632SN/Achar	*eth_ntoa(const eth_addr_t *eth);
742632SN/A#define	 eth_aton eth_pton
752632SN/A__END_DECLS
762632SN/A
772632SN/A#endif /* DNET_ETH_H */
78