LLA and DLPI Example Programs

LLA Example Program

/*

*Read a packet from the device.

*/

/* call read and check for an error */

if((recv_cnt = read(fd, data_area, MAX_PKT_SIZE)) < 0) { printf(”error: read failed, errno = %d\n”, errno); exit(1);

}

return(recv_cnt);

}

/************************************************************************** Send a packet over LLA

***************************************************************************/

void

 

 

put_data(fd, length)

 

int

fd;

/* file descriptor */

int

length;

/* length of data message */

{

 

 

/* call putmsg and check for an error */ if(write(fd, data_area, length) < 0) {

printf(”error: put_data putmsg failed, errno = %d\n”, errno); exit(1);

}

}

/*************************************************************************** Send a control request to the driver.

****************************************************************************/

void

 

 

put_ctrl(fd, cmd)

 

 

int

fd;

/* file descriptor */

int

cmd;

/* NETCTRL or NETSTAT */

{

 

 

/* Send control request to driver */ if(ioctl(fd, cmd, &ctrl_buf) < 0) {

printf(”error: put_ctrl putmsg failed, errno = %d\n”, errno); exit(1);

}

}

/**************************************************************************** Open an LLA device. The device file specifies which device you attaching to. There is no need to issue a seperate attach control request to designate which device you are using. In this example

we will default to /dev/lan0.

*****************************************************************************

*/ int attach() {

Chapter 2

33