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

  1. /* $Id: nit3write.c,v 2.0 89/10/20 19:02:41 dupuy Exp $ */
  2.  
  3. #include <sys/param.h>
  4. #include <sys/socket.h>
  5.  
  6. #include "libether.h"
  7.  
  8. extern unsigned _ether_types[NOFILE];
  9.  
  10. #define ether_type (_ether_types[fd])
  11.  
  12. /*
  13.  * Writes a single packet, filling src and type fields.
  14.  */
  15.  
  16. int
  17. ether_write (fd, packet)
  18. int fd;
  19. ether_packet *packet;
  20. {
  21.     struct sockaddr sa;
  22.  
  23.     sa.sa_family = AF_UNSPEC;
  24.     bcopy ((char *) packet, sa.sa_data, ETHER_TYPE);
  25.  
  26.     if (ether_type != ETHER_ALLTYPES)
  27.     {
  28.     sa.sa_data[12] = (ether_type >> 8) & 0xff;
  29.     sa.sa_data[13] = ether_type & 0xff;
  30.     }
  31.  
  32.     return (sendto (fd, packet->pktbuf, (int) packet->pktlen, 0, &sa,
  33.             sizeof (sa)) < 0 ? -1 : 0);
  34. }
  35.