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

  1. /* $Id: dliwritev.c,v 2.1 89/10/23 15:42:10 dupuy Exp $ */
  2.  
  3. #include <sys/param.h>            /* NOFILE */
  4. #include <sys/socket.h>            /* sockaddr_dl (sockaddr) */
  5. #include <sys/uio.h>            /* iovec */
  6.  
  7. #include <net/if.h>            /* ifdevea */
  8. #include <netinet/in.h>            /* (ether_header) (in_addr) */
  9. #include <netinet/if_ether.h>        /* sockaddr_dl (ether_header) */
  10. #include <netdnet/dli_var.h>        /* sockaddr_dl */
  11.  
  12. #include <errno.h>            /* EWOULDBLOCK */
  13.  
  14. #include "libether.h"
  15.  
  16. extern struct sockaddr_dl _ether_sockaddrs[NOFILE];
  17.  
  18. #define sad (_ether_sockaddrs[fd])
  19.  
  20. /*
  21.  * Writes a single packet, filling src and type fields.
  22.  */
  23.  
  24. int
  25. ether_writev (fd, packet)
  26. int fd;
  27. ether_vec *packet;
  28. {
  29.     struct msghdr msg;
  30.     int result;
  31.  
  32.     bcopy ((char *) &packet->dest,
  33.        (char *) sad.choose_addr.dli_eaddr.dli_target, DLI_EADDRSIZE);
  34.  
  35.     msg.msg_iov = packet->iov;
  36.     msg.msg_iovlen = packet->iovcnt;
  37.     msg.msg_name = (caddr_t) &sad;
  38.     msg.msg_namelen = sizeof (sad);
  39.     msg.msg_accrights = 0;
  40.     msg.msg_accrightslen = 0;
  41.  
  42.     result = sendmsg (fd, &msg, 0);
  43.  
  44.     if (result < 0 && errno == EWOULDBLOCK)
  45.     errno = EAGAIN;
  46.  
  47.     return (result);
  48. }
  49.