ETHER

Section: Network Functions (3N)
Updated: 29 June 1989
Index Return to Main Contents
 

NAME

ether - raw ethernet access functions  

SYNOPSIS

#include <ether.h>

typedef union etheraddr {
        char bytes[6];
        char shorts[3];
} ether_addr;

extern ether_addr ether_bcast_addr;

typedef struct etherpacket {
        ether_addr dest;
        ether_addr src;
        char type[2];
        unsigned short pktlen;
        char *pktbuf;
} ether_packet;

typedef struct ethervec {
        ether_addr dest;
        ether_addr src;
        char type[2];
        unsigned short iovcnt;
        struct iovec *iov;
} ether_vec;

int ether_open(name, type, address)
char *name;
int type;
ether_addr *address;

char **ether_interfaces();

ether_addr *ether_address(fd, address)
int fd;
ether_addr *address;

ether_addr *ether_intfaddr(name, address)
char *name;
ether_addr *address;

int ether_write(fd, packet)
int fd;
ether_packet *packet;

int ether_read(fd, packet)
int fd;
ether_packet *packet;

int ether_blocking(fd, state)
int fd;
int state;

int ether_send_self(fd)
int fd;

int ether_mcast_self(fd)
int fd;

int ether_bcast_self(fd)
int fd;

#include <sys/types.h>
#include <sys/uio.h>

int ether_writev(fd, packetvec)
int fd;
ether_vec *packetvec;

int ether_readv(fd, packetvec)
int fd;
ether_vec *packetvec;
 

DESCRIPTION

These functions provide access to the raw ethernet for user-level programs. On Suns, they are implemented using NIT(4p) (network interface tap). While they do not provide the full functionality of NIT , these functions do run on both the socket- and streams-based NIT implementations. On Ultrix systems, they are implemented using DLI (data link interface). On 4.3 BSD systems, they are implemented using the Stanford enetfilter device driver in the user-contributed software. These functions are not designed to be used for ethernet monitoring, but rather for programs implementing ethernet protocols such as RARP , or the Ethernet configuration test protocol.

The function ether_open returns a file descriptor for the ethernet device specified by name (such as "le0" or "ie1"). If no name is given, the default ethernet interface is used. Packets for the ethernet address address will be received in addition to packets for the local ethernet address and broadcasts; this is useful for multicast protocols. Superuser privilege is needed to use this feature. Only packets with a protocol type of type will be received or sent. This value should be passed in host byte order, not in network byte order.

In order to allow some basic ethernet monitoring capability on Sun NIT -based systems and BSD enetfilter systems, if address is all zeros, or if type is ETHER_ALLTYPES (defined in ether.h), address and/or type matching will be disabled. This will not work on Ultrix DLI -based systems, so using the NIT interface directly is nearly as portable, and gives better filtering and buffering.

The ether_interfaces function can be used to determine the valid interface names available. It returns an array of strings (with the last element set to NULL), each entry of which is an ethernet interface name valid for use in ether_open.

The ether_address function returns the local ethernet address for the ethernet interface on the file descriptor fd. The result is stored in the structure given by address; if none is given, malloc(3) is used to allocate space.

The ether_read and ether_write functions read or write a single ethernet packet. When writing, the dest, pktlen and pktbuf fields must be provided; the src and type fields are set to the local ethernet address and the ethernet type passed to ether_open(). When reading, only pktlen and pktbuf are looked at; the src, dest, and type fields are set from the packet on a successful return. If pktbuf is non-NULL, up to pktlen bytes will be read in to the buffer space specified by pktbuf. If pktbuf is NULL, pktlen is ignored and malloc(3) is used to allocate enough space for the packet. The value of pktlen is set to the lesser of its original value and the actual packet size (exclusive of the ethernet header). The size of the original ethernet packet is returned.

The ether_readv and ether_writev functions operate in the same way as ether_read and ether_write, but use an interface like that provided by the readv and writev system calls. The iov and iovcnt fields specify the length and location of an array of struct iovec. Each iovec entry specifies the base address and length of an area in memory where data is read from or written to.

The ether_blocking function can be used to make the ethernet file descriptor fd non-blocking. If state is zero, the file descriptor is set non-blocking with fcntl(2); if state is non-zero, the file descriptor is set to be blocking.

The ether_send_self, ether_mcast_self and ether_bcast_self functions return 1 if the interface will receive packets that it sends to itself, multicasts or broadcasts, respectively, and will return 0 if the interface will not receive such packets.

In addition, there are a number of auxiliary routines for manipulating ethernet addresses. Although they are not documented here, the ether.h header file describes them.  

DIAGNOSTICS

All functions which return an integer value return a negative number if there is an error. A zero return indicates no error. The ether_interfaces and ether_addresses functions return NULL if there is an error. All functions leave an error code in the external variable errno if an error occurs. If an attempt to read an ethernet file descriptor which has been set to non-blocking mode fails because the operation would block, errno will be set to EAGAIN (not EWOULDBLOCK).  

BUGS

Doesn't support IEEE 802.3 based protocols.

Because of restrictions in the DLI and socket based NIT implementations, the ether_open function may require superuser privilege on some machines. On SunOS 4.0 machines, it is sufficient to be able to open the /dev/nit special file. On machines with the Stanford enetfilter, it is sufficient to be able to open the interface's special file in /dev/enet/.

Due to limitations in the Stanford enetfilter, using select to determine if an ethernet device is ready to accept writes will always return true. Also, using ether_blocking(0) will not prevent blocking on writes. Since writes almost always complete quickly, this isn't a major problem, but applications may block if the ethernet is jammed.

The basic monitoring capabilities provided are a hack. Something like NIT should be standardized as a monitoring interface.

The auxiliary address routines should be better documented.  

SEE ALSO

nit(4p), nit_if(4p), nit_pf(4p), enet(4), fcntl(2), fcntl(5)  

AUTHORS

Alexander Dupuy, Robert Mokry, Columbia University Computer Science Department. Thanks to Charlie Kim for ideas stolen from his ethernet access implementation. Some of the auxiliary ethernet address routines are derived from code written by Philip Budne, Boston University Computer Science Department.


 

Index

NAME
SYNOPSIS
DESCRIPTION
DIAGNOSTICS
BUGS
SEE ALSO
AUTHORS

This document was created by man2html, using the manual pages.
Time: 10:50:32 GMT, December 12, 2024