home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / LMUTIL.ZIP / MACHNAME.C < prev    next >
C/C++ Source or Header  |  1991-03-19  |  2KB  |  107 lines

  1. /*
  2. ** Program: MACHNAME
  3. **
  4. ** Author:  Roger L Soles
  5. **
  6. ** Description:
  7. **
  8. ** This example C program uses the NetWkstaGetInfo call to obtain
  9. ** information about the local work station.
  10. **
  11. ** Instructions:
  12. **
  13. ** MACHNAME [-?]
  14. **
  15. */
  16.  
  17. #define LINT_ARGS
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #define INCL_NETWKSTA
  21. #define INCL_NETERRORS
  22. #include <lan.h>
  23.  
  24. void main (int argc, char * argv[])
  25. {
  26.  
  27.    /*
  28.    ** Information structures
  29.    */
  30.    struct wksta_info_0 far * WkstaInfo0;
  31.  
  32.    char far * cptr;
  33.  
  34.    API_RET_TYPE uRetCode = 0;
  35.  
  36.    char far * pszServer = "";
  37.    short sLevel = 0;
  38.    char far * pbBuffer;
  39.    unsigned short cbBuflen = 0;
  40.    unsigned short cbTotalAvail = 0;
  41.  
  42.    /*
  43.    ** Process Command Line Options
  44.    */
  45.    argc--; argv++;
  46.  
  47.    cptr = argv[0];
  48.    if ( *cptr++ == '-' )
  49.    {
  50.       switch (*cptr)
  51.       {
  52.       case '?':
  53.       default:
  54.          printf ("\nUSAGE:  MACHNAME [-?]\n");
  55.          exit (1);
  56.       }
  57.  
  58.    }
  59.  
  60.    /*
  61.    ** Determine how large buffer needs to be
  62.    */
  63.    uRetCode = NetWkstaGetInfo ( pszServer,
  64.                                 sLevel,
  65.                                 NULL,
  66.                                 0,
  67.                                 &cbTotalAvail);
  68.  
  69.    if (uRetCode == NERR_BufTooSmall)
  70.    {
  71.       cbBuflen = cbTotalAvail;
  72.       pbBuffer = (char *) malloc (cbBuflen);
  73.    }
  74.    else
  75.    {
  76.       printf ("Error %04x\n", uRetCode);
  77.       exit(1);
  78.    }
  79.  
  80.    /*
  81.    ** Allocate storage
  82.    */
  83.    uRetCode = NetWkstaGetInfo ( pszServer,
  84.                                 sLevel,
  85.                                 pbBuffer,
  86.                                 cbBuflen,
  87.                                 &cbTotalAvail);
  88.  
  89.  
  90.  
  91.    if (uRetCode != NERR_Success)
  92.    {
  93.       printf ("Error %04x\n", uRetCode);
  94.       exit(1);
  95.    }
  96.  
  97.  
  98.    /*
  99.    ** Print Out Level 0 information
  100.    */
  101.    WkstaInfo0 = (struct wksta_info_0 *) pbBuffer;
  102.    printf ("%Fs\n", WkstaInfo0->wki0_computername);
  103.  
  104.    exit (0);
  105. }
  106.  
  107.