home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / etherlib / part01 / src / enetwrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-24  |  1012 b   |  45 lines

  1. /* $Id: enetwrite.c,v 2.1 89/10/24 17:53:05 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>            /* iovec (caddr_t) */
  4. #include <sys/uio.h>            /* iovec */
  5.  
  6. #include "libether.h"
  7.  
  8. extern unsigned _ether_types[FD_SETSIZE];
  9.  
  10. #define ether_type (_ether_types[fd])
  11.  
  12. #define HEADER    0
  13. #define DATA    1
  14. #define MAXIOV    2
  15.  
  16. /*
  17.  * Writes a single packet, filling src and type fields.     We have to fill in
  18.  * the src field in user space, since the enetfilter doesn't do it for us, and
  19.  * at least some VAX interface devices don't do it either.
  20.  */
  21.  
  22. int
  23. ether_write (fd, packet)
  24. int fd;
  25. ether_packet *packet;
  26. {
  27.     struct iovec iov[MAXIOV];
  28.  
  29.     iov[HEADER].iov_len = ETHER_PKT;
  30.     iov[HEADER].iov_base = (char *) packet;
  31.  
  32.     iov[DATA].iov_len = packet->pktlen;
  33.     iov[DATA].iov_base = packet->pktbuf;
  34.  
  35.     if (ether_type != ETHER_ALLTYPES)
  36.     {
  37.     packet->type[0] = (ether_type >> 8) & 0xff;
  38.     packet->type[1] = ether_type & 0xff;
  39.     }
  40.  
  41.     (void) ether_address (fd, (ether_addr *) &packet->src);
  42.  
  43.     return (writev (fd, iov, MAXIOV));
  44. }
  45.