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

  1. /* $Id: nit4write.c,v 2.0 89/10/20 19:02:47 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <sys/stropts.h>
  6.  
  7. #include "libether.h"
  8.  
  9. extern unsigned _ether_types[FD_SETSIZE];
  10.  
  11. #define ether_type (_ether_types[fd])
  12.  
  13. /*
  14.  * Writes a single packet, filling src and type fields.
  15.  */
  16.  
  17. int
  18. ether_write (fd, packet)
  19. int fd;
  20. ether_packet *packet;
  21. {
  22.     struct sockaddr sa;
  23.     struct strbuf cbuf;
  24.     struct strbuf dbuf;
  25.  
  26.     sa.sa_family = AF_UNSPEC;
  27.     bcopy ((char *) packet, sa.sa_data, ETHER_TYPE);
  28.  
  29.     if (ether_type != ETHER_ALLTYPES)
  30.     {
  31.     sa.sa_data[12] = (ether_type >> 8) & 0xff;
  32.     sa.sa_data[13] = ether_type & 0xff;
  33.     }
  34.  
  35.     cbuf.maxlen = cbuf.len = sizeof (sa);
  36.     cbuf.buf = (char *) &sa;
  37.  
  38.     /*
  39.      * The interface output routines will paste the ether header back onto the
  40.      * front of the message.
  41.      */
  42.  
  43.     dbuf.len = packet->pktlen;
  44.     dbuf.buf = packet->pktbuf;
  45.  
  46.     return (putmsg (fd, &cbuf, &dbuf, 0));
  47. }
  48.