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

  1. /* $Id: dlireadv.c,v 2.1 89/10/23 15:42:06 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 ether_addr _ether_multi_addrs[NOFILE];
  17.  
  18.  
  19. /*
  20.  * Reads and returns a single packet, filling in all fields.  Has to do
  21.  * address checking, since we are operating in DLI_EXCLUSIVE mode.
  22.  */
  23.  
  24. int
  25. ether_readv (fd, packet)
  26. int fd;
  27. ether_vec *packet;
  28. {
  29.     struct sockaddr_dl from;
  30.     struct msghdr msg;
  31.     int count;
  32.     char *dest;
  33.  
  34.     from.dli_family = AF_DLI;
  35.     msg.msg_iov = packet->iov;
  36.     msg.msg_iovlen = packet->iovcnt;
  37.     msg.msg_name = (caddr_t) &from;
  38.     msg.msg_namelen = sizeof (from);
  39.     msg.msg_accrights = 0;
  40.     msg.msg_accrightslen = 0;
  41.  
  42.     do                    /* ignore bogus multicast packets */
  43.     {
  44.     if ((count = recvmsg (fd, &msg, 0)) < 0)
  45.     {
  46.         if (errno == EWOULDBLOCK)
  47.         errno = EAGAIN;
  48.         return (-1);
  49.     }
  50.  
  51.     dest = (char *) from.choose_addr.dli_eaddr.dli_dest;
  52.     }
  53.     while (address_check (dest));    /* constant argument to NOT ??? */
  54.  
  55.     bcopy (dest, (char *) &packet->dest, sizeof (ether_addr));
  56.     bcopy ((char *) from.choose_addr.dli_eaddr.dli_target,
  57.        (char *) &packet->src, sizeof (ether_addr));
  58.     packet->type[0] = (from.choose_addr.dli_eaddr.dli_protype & 0xff00) >> 8;
  59.     packet->type[1] = from.choose_addr.dli_eaddr.dli_protype & 0xff;
  60.  
  61.     return (count);
  62. }
  63.