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

  1.  
  2. #include        <string.h>
  3. #include        "netbios.h"
  4.  
  5. /*********************************************************
  6. * dg_write - write a datagram over the network
  7. * Parameters:
  8. *    number (in) - your name table address number
  9. *    destination (in) - destination name (1-15 characters)
  10. *    buffer (in) - data to be transmitted
  11. *    length (in) - number of bytes to transmit
  12. *  Global: net_error - global integer used to return net 
  13. *                      error codes. net_error is set to 
  14. *                      zero for normal return
  15. * Returns: Number of bytes transmitted for success. 
  16. *          -1 for failure. In the event of failure, the 
  17. *          global variable net_error is set to the NetBIOS 
  18. *          return code for error processing.
  19. * Notes: Destination must have already executed an
  20. *        NCB_RECEIVE_DATAGRAM command. Number is the value 
  21. *        returned from a successful init_netbios().
  22. *        This code assumes that you are using a memory model 
  23. *        which will result in buffer being a far pointer.
  24. * History: Original code by William H. Roetzheim, 1990
  25. *************************************************************/
  26.  
  27. int dg_write(unsigned int number, char *destination, 
  28.              char *buffer, int length)
  29. {
  30.    struct  net_control_block       ncb;
  31.    char    dest_name[16];
  32.    int             i;
  33.  
  34.    memset(dest_name, 0, 16);
  35.    for (i = 0; i < 15; i++)
  36.    {
  37.       if (destination[i] == 0) break;
  38.       else dest_name[i] = destination[i];
  39.    }
  40.  
  41.    init_ncb(&ncb);
  42.    ncb.command = NCB_SEND_DATAGRAM;
  43.    ncb.length = length;
  44.    ncb.buffer = buffer;
  45.    ncb.number = number;
  46.    strcpy(ncb.r_name, dest_name);
  47.    int_netbios(&ncb);
  48.    if (ncb.retcode == 0) return length;
  49.    else return -1;
  50. }
  51.  
  52.