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

  1. /* $Id: nit3readv.c,v 2.0 89/10/20 19:02:38 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>            /* iovec (caddr_t) */
  4. #include <sys/uio.h>            /* iovec */
  5.  
  6. #include "libether.h"
  7.  
  8. /*
  9.  * Reads and returns a single packet, filling in all fields.  Since read() may
  10.  * return several packets at a time, we have to buffer them as well.  Since
  11.  * socket based nit doesn't handle multicast addresses, we have to check them
  12.  * at the user level.
  13.  *
  14.  * NOTE - the buffering code is not re-entrant, although different fd's will
  15.  * not conflict.
  16.  */
  17.  
  18. int
  19. ether_readv (fd, packet)
  20. int fd;
  21. ether_vec *packet;
  22. {
  23.     char *pbuf;
  24.     int index = 0;
  25.     int count;
  26.     int bytes;
  27.  
  28.     if ((bytes = _ether_next_packet (fd, &pbuf)) < 0)
  29.     return (-1);
  30.  
  31.     bcopy (pbuf, (char *) packet, ETHER_PKT);
  32.     pbuf += ETHER_PKT;
  33.  
  34.     for (count = 0; count < packet->iovcnt && index < bytes; count++)
  35.     if (packet->iov[count].iov_len)
  36.     {
  37.         if (bytes - index < packet->iov[count].iov_len)
  38.         {
  39.         bcopy (&pbuf[index], (char *) packet->iov[count].iov_base,
  40.                bytes - index);
  41.         break;
  42.         }
  43.         else
  44.         {
  45.         bcopy (&pbuf[index], (char *) packet->iov[count].iov_base,
  46.                (int) packet->iov[count].iov_len);
  47.         index += packet->iov[count].iov_len;
  48.         }
  49.     }
  50.  
  51.     return (bytes);
  52. }
  53.