home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / ENETHDR.C < prev    next >
C/C++ Source or Header  |  1991-01-27  |  801b  |  42 lines

  1. /* Ethernet header conversion routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "enet.h"
  7.  
  8. /* Convert Ethernet header in host form to network mbuf */
  9. struct mbuf *
  10. htonether(ether,data)
  11. struct ether *ether;
  12. struct mbuf *data;
  13. {
  14.     struct mbuf *bp;
  15.     register char *cp;
  16.  
  17.     if((bp = pushdown(data,ETHERLEN)) == NULLBUF)
  18.         return NULLBUF;
  19.  
  20.     cp = bp->data;
  21.  
  22.     memcpy(cp,ether->dest,EADDR_LEN);
  23.     cp += EADDR_LEN;
  24.     memcpy(cp,ether->source,EADDR_LEN);
  25.     cp += EADDR_LEN;
  26.     put16(cp,ether->type);
  27.  
  28.     return bp;
  29. }
  30. /* Extract Ethernet header */
  31. int
  32. ntohether(ether,bpp)
  33. struct ether *ether;
  34. struct mbuf **bpp;
  35. {
  36.     pullup(bpp,ether->dest,EADDR_LEN);
  37.     pullup(bpp,ether->source,EADDR_LEN);
  38.     ether->type = pull16(bpp);
  39.     return ETHERLEN;
  40. }
  41.  
  42.