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

  1. /* $Id: nit4writev.c,v 2.0 89/10/20 19:02:48 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <sys/stropts.h>
  6. #include <sys/uio.h>
  7.  
  8. #include "libether.h"
  9.  
  10. extern unsigned _ether_types[FD_SETSIZE];
  11.  
  12. #define ether_type (_ether_types[fd])
  13.  
  14. /*
  15.  * Writes a single packet, filling src and type fields.
  16.  */
  17.  
  18. int
  19. ether_writev (fd, packet)
  20. int fd;
  21. ether_vec *packet;
  22. {
  23.     struct sockaddr sa;
  24.     struct strbuf cbuf;
  25.     struct strbuf dbuf;
  26.     char buffer[ETHER_MAX];
  27.     char *bufp = buffer;
  28.     int count;
  29.  
  30.     sa.sa_family = AF_UNSPEC;
  31.     bcopy ((char *) packet, sa.sa_data, ETHER_TYPE);
  32.  
  33.     if (ether_type != ETHER_ALLTYPES)
  34.     {
  35.     sa.sa_data[12] = (ether_type >> 8) & 0xff;
  36.     sa.sa_data[13] = ether_type & 0xff;
  37.     }
  38.  
  39.     cbuf.maxlen = cbuf.len = sizeof (sa);
  40.     cbuf.buf = (char *) &sa;
  41.  
  42.     dbuf.len = 0;
  43.     dbuf.buf = bufp;
  44.  
  45.     for (count = 0; count < packet->iovcnt; count++)
  46.     if (packet->iov[count].iov_len)
  47.     {
  48.         bcopy ((char *) packet->iov[count].iov_base, bufp,
  49.            (int) packet->iov[count].iov_len);
  50.         bufp += packet->iov[count].iov_len;
  51.         dbuf.len += packet->iov[count].iov_len;
  52.     }
  53.  
  54.     return (putmsg (fd, &cbuf, &dbuf, 0));
  55. }
  56.