home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / msk316src.zip / MSNSED.C < prev    next >
C/C++ Source or Header  |  1999-04-24  |  4KB  |  156 lines

  1. /* File MSNSED.C
  2.  * Ethernet Driver support routines
  3.  *
  4.  * Copyright (C) 1991, University of Waterloo.
  5.  *    Copyright (C) 1982, 1999, Trustees of Columbia University in the 
  6.  *    City of New York.  The MS-DOS Kermit software may not be, in whole 
  7.  *    or in part, licensed or sold for profit as a software product itself,
  8.  *    nor may it be included in or distributed with commercial products
  9.  *    or otherwise distributed by commercial concerns to their clients 
  10.  *    or customers without written permission of the Office of Kermit 
  11.  *    Development and Distribution, Columbia University.  This copyright 
  12.  *    notice must not be removed, altered, or obscured.
  13.  *
  14.  * Original version created by Erick Engelke of the University of
  15.  *  Waterloo, Waterloo, Ontario, Canada.
  16.  * Adapted and modified for MS-DOS Kermit by Joe R. Doupnik, 
  17.  *  Utah State University, jrd@cc.usu.edu, jrd@usu.Bitnet.
  18.  *
  19.  * Last edit
  20.  * 12 Jan 1995 v3.14
  21.  *
  22.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  23.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  24.  *
  25.  *  If you need to write a new driver, implement it at this level and use
  26.  *  the above mentioned constants as this program's constants, not device
  27.  *  dependant constants.
  28.  *
  29.  *  The packet driver code lies below this.
  30.  *
  31.  *  eth_addr    - Ethernet address of this host.
  32.  *  eth_brdcast    - Ethernet broadcast address.
  33.  */
  34.  
  35. #include "msntcp.h"
  36. #include "msnlib.h"
  37.  
  38. #define ETH_MIN    60              /* Minimum Ethernet packet size */
  39.  
  40. eth_address eth_addr = {0};    /* local ethernet address */
  41. eth_address eth_brdcast ={0xff,0xff,0xff,0xff,0xff,0xff};
  42.                 /* Ethernet broadcast address */
  43. word pktdevclass = 1;        /* Ethernet = 1, SLIP = 6 */
  44. extern word MAC_len;        /* length of a MAC address, bytes */
  45.  
  46. /* Ethernet Interface */
  47.  
  48. struct ether {
  49.     byte    dest[6];
  50.     byte    src[6];
  51.     word    type;
  52.     byte    data[ETH_MSS + 60];
  53. };
  54. static struct ether outbuf = {{0},{0},0,{0}};
  55.  
  56. /* Write Ethernet MAC header and return pointer to data field. */
  57. /* Uses single output frame buffer, named outbuf. */
  58. byte *
  59. eth_formatpacket(void *eth_dest, word eth_type)
  60. {
  61.     memset(&outbuf, 0, 6+6+2+64);        /* clear small frame */
  62.  
  63.     switch (pktdevclass) 
  64.             {
  65.         case PD_ETHER:
  66.             bcopy(eth_dest, outbuf.dest, 6);
  67.             bcopy(eth_addr, outbuf.src, 6);
  68.             outbuf.type = eth_type;
  69.             return(outbuf.data);    /* outbuf is permanent */
  70.         case PD_SLIP:
  71.             return(outbuf.dest);    /* really data because no header */
  72.             }
  73.     return (NULL);                /* default */
  74. }
  75.  
  76. /*
  77.  * eth_send does the actual transmission once we are complete with the
  78.  * buffer.  Do any last minute patches here, like fix the size.
  79.  */
  80. int
  81. eth_send(word len)
  82. {
  83.     if (len & 1) len++;        /* if odd make even */
  84.     if ((pktdevclass == PD_ETHER) && ((len += 14) < ETH_MIN))
  85.         len = ETH_MIN;
  86.     return (pkt_send((byte *) &outbuf, len));  /* send to link driver */
  87. }
  88.  
  89. /*
  90.  * eth_free - free an input buffer once it is no longer needed
  91.  * If pointer to NULL, release all buffers
  92.  */
  93. void 
  94. eth_free(void *buf)
  95. {
  96.     if (buf != NULL)
  97.         pkt_buf_release(buf);        /* free this buffer ptr */
  98.     else
  99.         pkt_buf_wipe();            /* if none then clear all */
  100. }
  101.  
  102. /*
  103.  * eth_arrived - if a new packet has arrived, read it and fill pointer
  104.  * with type of packet
  105.  */
  106.  
  107. byte * 
  108. eth_arrived(word *type_ptr)
  109. {
  110.     register int i;
  111.     register struct ether * temp;
  112.  
  113.     if (type_ptr == NULL) return (NULL);
  114.     if ((temp = (struct ether *)pkt_received()) == NULL)
  115.         return (NULL);            /* nothing there folks */
  116.  
  117.     switch (pktdevclass)
  118.         {
  119.         case PD_ETHER:
  120.             *type_ptr = temp->type;        /* value of TYPE */
  121.             if (MAC_len == 0)    /* no MAC address to test */
  122.                 return (temp->data);
  123.                 for (i = 5; i >= 0; i--)    /*source same as us?*/
  124.                     if (temp->src[i] != eth_addr[i])
  125.                     return(temp->data); /* ptr to data */
  126.                         /* NDIS echo stupidity */
  127.             eth_free(temp->data);        /* discard packet */
  128.             return (NULL);
  129.  
  130.         case PD_SLIP:
  131.                 *type_ptr = TYPE_IP;
  132.             return((byte *)temp);        /* no MAC to skip */
  133.         default:
  134.             return (NULL);
  135.             }
  136. }
  137.  
  138. /*
  139.  * eth_release - release the hardware
  140.  */
  141. void 
  142. eth_release(void)
  143. {
  144.     pkt_release();
  145. }
  146.  
  147. /*
  148.  * eth_hardware - return pointer to source hardware address of a frame
  149.  */
  150. void *
  151. eth_hardware(byte *p)
  152. {
  153.     if (p == NULL || pktdevclass == PD_SLIP) return (NULL);
  154.     return (p - 8);
  155. }
  156.