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

  1. /* $Id: enetwritev.c,v 2.2 89/10/24 17:53:10 dupuy Exp $ */
  2.  
  3. #include <sys/types.h>            /* iovec (caddr_t) */
  4. #include <sys/uio.h>            /* iovec */
  5.  
  6. #include "libether.h"
  7.  
  8. #ifdef __GNUC__
  9. #define alloca __builtin_alloca
  10. #else
  11. #ifdef lint
  12. extern double *dalloca ();
  13. #define alloca dalloca
  14. #else
  15. #ifdef sparc
  16. #include <alloca.h>
  17. #endif
  18. extern char *alloca ();
  19. #endif
  20. #endif
  21.  
  22. extern unsigned _ether_types[FD_SETSIZE];
  23.  
  24. #define ether_type (_ether_types[fd])
  25.  
  26. #define HEADER    0
  27. #define USER    1
  28.  
  29. /*
  30.  * Writes a single packet, filling src and type fields.     We have to fill in
  31.  * the src field in user space, since the enetfilter doesn't do it for us, and
  32.  * at least some VAX interface devices don't do it either.
  33.  */
  34.  
  35. int
  36. ether_writev (fd, packet)
  37. int fd;
  38. ether_vec *packet;
  39. {
  40.     int count = 1 + packet->iovcnt;
  41.     struct iovec *iov =
  42.     (struct iovec *) alloca (sizeof (struct iovec) * count);
  43.  
  44.     iov[HEADER].iov_len = ETHER_PKT;
  45.     iov[HEADER].iov_base = (char *) packet;
  46.  
  47.     (void) bcopy ((char *) packet->iov, (char *) &iov[USER],
  48.           (int) packet->iovcnt * sizeof (struct iovec));
  49.  
  50.     if (ether_type != ETHER_ALLTYPES)
  51.     {
  52.     packet->type[0] = (ether_type >> 8) & 0xff;
  53.     packet->type[1] = ether_type & 0xff;
  54.     }
  55.  
  56.     (void) ether_address (fd, (ether_addr *) &packet->src);
  57.  
  58.     return (writev (fd, iov, count));
  59. }
  60.