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

  1. /* $Id: dliwrite.c,v 2.1 89/10/23 15:42:09 dupuy Exp $ */
  2.  
  3. #include <sys/param.h>            /* NOFILE */
  4. #include <sys/socket.h>            /* sockaddr_dl (sockaddr) */
  5.  
  6. #include <net/if.h>            /* ifdevea */
  7. #include <netinet/in.h>            /* (ether_header) (in_addr) */
  8. #include <netinet/if_ether.h>        /* sockaddr_dl (ether_header) */
  9. #include <netdnet/dli_var.h>        /* sockaddr_dl */
  10.  
  11. #include <errno.h>            /* EWOULDBLOCK */
  12.  
  13. #include "libether.h"
  14.  
  15. extern struct sockaddr_dl _ether_sockaddrs[NOFILE];
  16.  
  17. #define sad (_ether_sockaddrs[fd])
  18.  
  19. /*
  20.  * Writes a single packet, filling src and type fields.
  21.  */
  22.  
  23. int
  24. ether_write (fd, packet)
  25. int fd;
  26. ether_packet *packet;
  27. {
  28.     int result;
  29.  
  30.     bcopy ((char *) &packet->dest,
  31.        (char *) sad.choose_addr.dli_eaddr.dli_target, DLI_EADDRSIZE);
  32.  
  33.     result = sendto (fd, packet->pktbuf, (int) packet->pktlen, 0,
  34.              (struct sockaddr *) &sad, sizeof (struct sockaddr_dl));
  35.  
  36.     if (result < 0 && errno == EWOULDBLOCK)
  37.     errno = EAGAIN;
  38.  
  39.     return (result);
  40. }
  41.