home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02049a < prev    next >
Text File  |  1990-12-30  |  1KB  |  40 lines

  1.  
  2. #include        <string.h>
  3. #include        "netbios.h"
  4.  
  5. /******************************************************
  6. * dg_read - read a datagram over the network
  7. * Parameters:
  8. *   number (in) - your name table address number
  9. *   from (out)  - name of user sending datagram
  10. *   buffer (in) - location to put received data
  11. *   length (in) - maximum number of bytes to receive
  12. * Global: net_error - used to store NetBIOS return 
  13. *                     code for error processing.
  14. * Returns: Number of bytes received for success, 
  15. *          -1 for failure
  16. * Notes: Number is the value returned from a successful 
  17. *        init_netbios(). This code assumes that you are 
  18. *        using a memory model which will result in 
  19. *        buffer being a far pointer. From must point to 
  20. *        a block of memory at least 16 bytes long.
  21. * History: Original code by William H. Roetzheim, 1990
  22. *******************************************************/
  23.  
  24. int dg_read(unsigned int number, char *from, 
  25.             char *buffer, int length)
  26. {
  27.    struct  net_control_block       ncb;
  28.  
  29.    init_ncb(&ncb);
  30.    ncb.command = NCB_RECEIVE_DATAGRAM;
  31.    ncb.length = length;
  32.    ncb.buffer = buffer;
  33.    ncb.number = number;
  34.    int_netbios(&ncb);
  35.    memcpy(from, ncb.l_name, 16);
  36.    if (ncb.retcode == 0) return ncb.length;
  37.    else return -1;
  38. }
  39.  
  40.