Win32 NetWare Core Protocol Revisited
by Sven B. Schreiber


Listing One
// =================================================================
// PLATFORM-DEPENDENT SERVICES
// =================================================================

BOOL WINAPI
NwlibIsWinNT (void)
    {
    return fWinNT;
    }
// -----------------------------------------------------------------
PWSTR WINAPI
NwlibGetServerName (NWCONN_HANDLE hConnection)
    {
    return (fWinNT ? hConnection->ServerName.sBuffer : L"");
    }
// -----------------------------------------------------------------
HANDLE WINAPI
NwlibGetServerHandle (NWCONN_HANDLE hConnection)
    {
    return (fWinNT ? hConnection->hServer : hConnection);
    }
// -----------------------------------------------------------------
BYTE WINAPI
NwlibGetNcpFunction (DWORD dNcpFunctionId)
    {
    return (BYTE) (dNcpFunctionId >> 8);
    }
// -----------------------------------------------------------------

BYTE WINAPI
NwlibGetNcpSubFunction (DWORD dNcpFunctionId)
    {
    return (BYTE) dNcpFunctionId;
    }
// -----------------------------------------------------------------
DWORD WINAPI
NwlibGetNcpControlCode (DWORD dNcpFunctionId)
    {
    DWORD dNcpFunction = NwlibGetNcpFunction (dNcpFunctionId);
    return (fWinNT ? 0x00141003 | (dNcpFunction << 2)
                   : 0x000000CC + (dNcpFunction));
    }


Listing Two
// =================================================================
// NETWARE API FUNCTIONS
// =================================================================

DWORD WINAPI
NWGetConnectionNumber (NWCONN_HANDLE hConnection,
                       PDWORD        pdConnection)
    {
    WORD  wReserved;
    DWORD dStatus;

    *pdConnection = 0;

    dStatus =
    NwlibMakeNcp
        (NwlibGetServerHandle (hConnection),
         NwlibGetNcpControlCode (_GET_STATION_NUMBER),
         RqSize (0),
         RpSize (WORD_+BYTE_),
         "|wb",

         &wReserved,
         pdConnection);
    return dStatus;
    }
// -----------------------------------------------------------------
DWORD WINAPI
NWGetConnectionInformation (NWCONN_HANDLE  hConnection,
                            DWORD          dConnection,
                            NWOBJECT_NAME  ObjectName,
                            PWORD          pwObjectType,
                            PDWORD         pdObjectId,
                            PNWDATE_TIME   pLoginTime)
    {
    DWORD dStatus;

    dStatus =
    NwlibMakeNcp
        (NwlibGetServerHandle (hConnection),

         NwlibGetNcpControlCode (_GET_STATION_LOGGED_INFORMATION),
         RqSize (BYTE_+DWORD_),
         RpSize (DWORD_+WORD_+NWOBJECT_NAME_+NWDATE_TIME_+BYTE_),
         "br|dwrr",

         NwlibGetNcpSubFunction (_GET_STATION_LOGGED_INFORMATION),
         &dConnection, DWORD_,

         pdObjectId,
         pwObjectType,
         ObjectName, NWOBJECT_NAME_,
         pLoginTime, NWDATE_TIME_);
    return dStatus;
    }


Listing Three
// =================================================================
// MAIN ROUTINES
// =================================================================

void DisplayVolumeNames (NWCONN_HANDLE hConnection)
    {
    BYTE          bVolume;
    NWVOLUME_NAME VolumeName;
    DWORD         dStatus;

    printf ("\n\nEnumerating volumes ...");
    for (bVolume = 0; bVolume < NW_MAX_VOLUMES; bVolume++)
        {
        dStatus = NWGetVolumeName (hConnection, bVolume, VolumeName);
        if (!dStatus)
            {
            if (VolumeName [0])
                {
                printf ("\n Volume #%02lu = \"%s\"",
                        bVolume+1,
                        VolumeName);
                }
            }
        }
    return;
    }
// -----------------------------------------------------------------
void DisplayConnectionData (NWCONN_HANDLE hConnection)
    {
    DWORD         dConnection;

    NWOBJECT_NAME ObjectName;
    WORD          wObjectType;
    DWORD         dObjectId;
    NWDATE_TIME   LoginTime;
    DWORD         dStatus;

    printf ("\n\nRetrieving the connection number ...");
    dStatus = NWGetConnectionNumber (hConnection, &dConnection);

    if (!dStatus)
        {
        printf ("\n Connection number = %lu", dConnection);

        printf ("\n\nRetrieving connection information ...");
        dStatus = NWGetConnectionInformation (hConnection, dConnection,
                                              ObjectName, &wObjectType,
                                              &dObjectId, &LoginTime);
        if (!dStatus)
            {
            printf ("\n Object name = \"%s\"", ObjectName);
            printf ("\n Object type = 0x%04X", wObjectType);
            printf ("\n Object ID   = 0x%08X", dObjectId);
            }
        }
    return;
    }


Example 1: 

DWORD WINAPI
NwlibMakeNcp (HANDLE hDevice,
              DWORD  dIoControlCode,
              DWORD  dInBufferSize,
              DWORD  dOutBufferSize,
              PSTR   psFragmentControl,
              ...);

Example 2: 


WORD WINAPI
NWAttachToFileServer (PSTR           psServerName,
                      WORD           wScopeFlag,
                      PNWCONN_HANDLE phConnection);


Example 3:
(a)
typedef NWCONN_HANDLE_DATA *NWCONN_HANDLE;


(b)
typedef struct _NWCONN_HANDLE_DATA
    {
    HANDLE         hServer;
    UNICODE_STRING ServerName;
    }
    NWCONN_HANDLE_DATA, *PNWCONN_HANDLE_DATA;

(c)
typedef struct _UNICODE_STRING
    {
    WORD  wLength;
    WORD  wMaximumLength;
    PWSTR sBuffer;
    }
    UNICODE_STRING, *PUNICODE_STRING;

(d)
WORD WINAPI
NWDetachFromFileServer (NWCONN_HANDLE hConnection);




3



