/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * ethernet.h header for common Ethernet declarations.
 */

#ifndef	_SYS_ETHERNET_H
#define	_SYS_ETHERNET_H

#pragma ident	"@(#)ethernet.h	1.19	05/09/01 SMI"

#ifdef	__cplusplus
extern "C" {
#endif

#define	ETHERADDRL	(6)		/* ethernet address length in octets */
#define	ETHERFCSL	(4)		/* ethernet FCS length in octets */

/*
 * Ethernet address - 6 octets
 */
typedef uchar_t ether_addr_t[ETHERADDRL];

/*
 * Ethernet address - 6 octets
 */
struct	ether_addr {
	ether_addr_t	ether_addr_octet;
};

/*
 * Structure of a 10Mb/s Ethernet header.
 */
struct	ether_header {
	struct	ether_addr	ether_dhost;
	struct	ether_addr	ether_shost;
	ushort_t		ether_type;
};

#define	ETHER_CFI	0

struct	ether_vlan_header {
	struct	ether_addr	ether_dhost;
	struct	ether_addr	ether_shost;
	ushort_t		ether_tpid;
	ushort_t		ether_tci;
	ushort_t		ether_type;
};

#define	ETHERTYPE_PUP		(0x0200)	/* PUP protocol */
#define	ETHERTYPE_802_MIN	(0x0600)	/* Min valid ethernet type */
						/* under IEEE 802.3 rules */
#define	ETHERTYPE_IP		(0x0800)	/* IP protocol */
#define	ETHERTYPE_ARP		(0x0806)	/* Addr. resolution protocol */
#define	ETHERTYPE_REVARP	(0x8035)	/* Reverse ARP */
#define	ETHERTYPE_AT		(0x809b)	/* AppleTalk protocol */
#define	ETHERTYPE_AARP		(0x80f3)	/* AppleTalk ARP */
#define	ETHERTYPE_IPV6		(0x86dd)	/* IPv6 */
#define	ETHERTYPE_SLOW		(0x8809)	/* Slow Protocol */
#define	ETHERTYPE_PPPOED	(0x8863)	/* PPPoE Discovery Stage */
#define	ETHERTYPE_PPPOES	(0x8864)	/* PPPoE Session Stage */
#define	ETHERTYPE_MAX		(0xffff)	/* Max valid ethernet type */

/*
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
 * by an ETHER type (as given above) and then the (variable-length) header.
 */
#define	ETHERTYPE_TRAIL		(0x1000)	/* Trailer packet */
#define	ETHERTYPE_NTRAILER	(16)

#define	ETHERMTU		(1500)	/* max frame w/o header or fcs */
#define	ETHERMIN		(60)	/* min frame w/header w/o fcs */
#define	ETHERMAX		(1514)	/* max frame w/header w/o fcs */

/*
 * Compare two Ethernet addresses - assumes that the two given
 * pointers can be referenced as shorts.  On architectures
 * where this is not the case, use bcmp instead.  Note that like
 * bcmp, we return zero if they are the SAME.
 */

#if defined(__sparc) || defined(__i386) || defined(__amd64)
#define	ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \
	((short *)b)[1] != ((short *)a)[1] || \
	((short *)b)[0] != ((short *)a)[0])
#else
#define	ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6))
#endif

/*
 * Copy Ethernet addresses from a to b - assumes that the two given
 * pointers can be referenced as shorts.  On architectures
 * where this is not the case, use bcopy instead.
 */

#if defined(__sparc) || defined(__i386) || defined(__amd64)
#define	ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \
	((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; }
#else
#define	ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6))
#endif

#ifdef	_KERNEL
extern int localetheraddr(struct ether_addr *, struct ether_addr *);
extern char *ether_sprintf(struct ether_addr *);
extern int ether_aton(char *, uchar_t *);
#else	/* _KERNEL */
#ifdef  __STDC__
extern char *ether_ntoa(const struct ether_addr *);
extern struct ether_addr *ether_aton(const char *);
extern int ether_ntohost(char *, const struct ether_addr *);
extern int ether_hostton(const char *, struct ether_addr *);
extern int ether_line(const char *, struct ether_addr *, char *);
#else	/* __STDC__ */
extern char *ether_ntoa();
extern struct ether_addr *ether_aton();
extern int ether_ntohost();
extern int ether_hostton();
extern int ether_line();
#endif	/* __STDC__ */
#endif	/* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_ETHERNET_H */
