eth.h revision 2632
12SN/A/*
21762SN/A * eth.h
32SN/A *
42SN/A * Ethernet.
52SN/A *
62SN/A * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
72SN/A *
82SN/A * $Id: eth.h,v 1.15 2004/01/03 08:47:23 dugsong Exp $
92SN/A */
102SN/A
112SN/A#ifndef DNET_ETH_H
122SN/A#define DNET_ETH_H
132SN/A
142SN/A#define ETH_ADDR_LEN	6
152SN/A#define ETH_ADDR_BITS	48
162SN/A#define ETH_TYPE_LEN	2
172SN/A#define ETH_CRC_LEN	4
182SN/A#define ETH_HDR_LEN	14
192SN/A
202SN/A#define ETH_LEN_MIN	64		/* minimum frame length with CRC */
212SN/A#define ETH_LEN_MAX	1518		/* maximum frame length with CRC */
222SN/A
232SN/A#define ETH_MTU		(ETH_LEN_MAX - ETH_HDR_LEN - ETH_CRC_LEN)
242SN/A#define ETH_MIN		(ETH_LEN_MIN - ETH_HDR_LEN - ETH_CRC_LEN)
252SN/A
262SN/Atypedef struct eth_addr {
272665Ssaidi@eecs.umich.edu        uint8_t		data[ETH_ADDR_LEN];
282665Ssaidi@eecs.umich.edu} eth_addr_t;
292SN/A
302SN/Astruct eth_hdr {
312439SN/A        eth_addr_t	eth_dst;	/* destination address */
322984Sgblack@eecs.umich.edu        eth_addr_t	eth_src;	/* source address */
33146SN/A        uint16_t	eth_type;	/* payload type */
34146SN/A};
35146SN/A
36146SN/A/*
37146SN/A * Ethernet payload types - http://standards.ieee.org/regauth/ethertype
38146SN/A */
391717SN/A#define ETH_TYPE_PUP	0x0200		/* PUP protocol */
40146SN/A#define ETH_TYPE_IP	0x0800		/* IP protocol */
411717SN/A#define ETH_TYPE_ARP	0x0806		/* address resolution protocol */
42146SN/A#define ETH_TYPE_REVARP	0x8035		/* reverse addr resolution protocol */
431977SN/A#define ETH_TYPE_8021Q	0x8100		/* IEEE 802.1Q VLAN tagging */
442623SN/A#define ETH_TYPE_IPV6	0x86DD		/* IPv6 protocol */
452683Sktlim@umich.edu#define ETH_TYPE_MPLS	0x8847		/* MPLS */
461717SN/A#define ETH_TYPE_MPLS_MCAST	0x8848	/* MPLS Multicast */
47146SN/A#define ETH_TYPE_PPPOEDISC	0x8863	/* PPP Over Ethernet Discovery Stage */
482683Sktlim@umich.edu#define ETH_TYPE_PPPOE	0x8864		/* PPP Over Ethernet Session Stage */
493348Sbinkertn@umich.edu#define ETH_TYPE_LOOPBACK	0x9000	/* used to test interfaces */
502036SN/A
51146SN/A#define ETH_IS_MULTICAST(ea)	(*(ea) & 0x01) /* is address mcast/bcast? */
5256SN/A
5356SN/A#define ETH_ADDR_BROADCAST	"\xff\xff\xff\xff\xff\xff"
5456SN/A
55695SN/A#define eth_pack_hdr(h, dst, src, type) do {			\
562901Ssaidi@eecs.umich.edu        struct eth_hdr *eth_pack_p = (struct eth_hdr *)(h);	\
572SN/A        memmove(&eth_pack_p->eth_dst, &(dst), ETH_ADDR_LEN);	\
581858SN/A        memmove(&eth_pack_p->eth_src, &(src), ETH_ADDR_LEN);	\
593565Sgblack@eecs.umich.edu        eth_pack_p->eth_type = htons(type);			\
603565Sgblack@eecs.umich.edu} while (0)
612171SN/A
622170SN/Atypedef struct eth_handle eth_t;
633562Sgblack@eecs.umich.edu
64146SN/A__BEGIN_DECLS
652462SN/Aeth_t	*eth_open(const char *device);
66146SN/Aint	 eth_get(eth_t *e, eth_addr_t *ea);
672SN/Aint	 eth_set(eth_t *e, const eth_addr_t *ea);
682SN/Asize_t	 eth_send(eth_t *e, const void *buf, size_t len);
692449SN/Aeth_t	*eth_close(eth_t *e);
701355SN/A
712623SN/Achar	*eth_ntop(const eth_addr_t *eth, char *dst, size_t len);
724495Sacolyte@umich.eduint	 eth_pton(const char *src, eth_addr_t *dst);
73224SN/Achar	*eth_ntoa(const eth_addr_t *eth);
741858SN/A#define	 eth_aton eth_pton
752683Sktlim@umich.edu__END_DECLS
762420SN/A
772683Sktlim@umich.edu#endif /* DNET_ETH_H */
784997Sgblack@eecs.umich.edu