home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / loginos2.c < prev    next >
C/C++ Source or Header  |  1992-01-05  |  2KB  |  75 lines

  1. /* getlogin for Novell + OS/2 */
  2.  
  3. /* by Frank Whaley */
  4. /* further hacking by Paul Eggert and Kai Uwe Rommel */
  5.  
  6.     /* $Id: loginos2.c,v 1.2 1992/01/06 03:18:26 eggert Exp $ */
  7.  
  8. #include <string.h>
  9.  
  10. #define INCL_NOPM
  11. #define INCL_DOS
  12. #include <os2.h>
  13.  
  14. #define DOS_MODE    0
  15. #define OS2_MODE    1
  16. extern unsigned char _osmode;
  17.  
  18. /*
  19.  * The OS/2 getlogin() calls functions located in the NWCALLS.DLL library
  20.  * to fetch the default connection number, and the current connection status.
  21.  * Because importing the functions directly would prevent the ececutables
  22.  * from loading on systems without NetWare, me must link them in during
  23.  * runtime manually with DosLoadModule/DosGetProcAddress/DosFreeModule.
  24.  */
  25.  
  26. struct info {
  27.     unsigned connectionID;
  28.     unsigned connectFlags;
  29.     unsigned sessionID;
  30.     unsigned connectionNumber;
  31.     char serverAddr[12];
  32.     unsigned serverType;
  33.     char serverName[48];
  34.     unsigned clientType;
  35.     char clientName[48];
  36. };
  37.  
  38. typedef struct info far *PINFO;
  39.  
  40.     char *
  41. getlogin()
  42. {
  43.     static struct info ci;
  44.  
  45.     USHORT (APIENTRY *NWGetDefaultConnectionID)(PUSHORT);
  46.     USHORT (APIENTRY *NWGetConnectionStatus)(USHORT, PINFO, USHORT);
  47.     HMODULE NWCalls;
  48.     char buf[256];
  49.     unsigned id;
  50.  
  51.     if (
  52.         _osmode != DOS_MODE &&
  53.         DosLoadModule(buf, sizeof(buf), "NWCALLS", &NWCalls) == 0
  54.     ) {
  55.         if (
  56.         DosGetProcAddr(NWCalls,
  57.             "NWGETDEFAULTCONNECTIONID",
  58.             &NWGetDefaultConnectionID
  59.         ) == 0 &&
  60.         DosGetProcAddr(NWCalls,
  61.             "NWGETCONNECTIONSTATUS",
  62.             &NWGetConnectionStatus
  63.         ) == 0 &&
  64.         NWGetDefaultConnectionID(&id) == 0 &&
  65.         NWGetConnectionStatus(id, &ci, sizeof(ci)) == 0
  66.         ) {
  67.         strlwr(ci.clientName);
  68.         return ci.clientName;
  69.         }
  70.         DosFreeModule(NWCalls);
  71.     }
  72.  
  73.     return 0;
  74. }
  75.