//
// Function: main
//
// Description:
//    Initialize the NetBIOS interface, allocate some resources, add
//    the server name to each LANA, post an asynch NCBLISTEN on each
//    LANA with the appropriate callback.  Then wait for incoming
//    client connections at which time, spawn a worker thread to handle
//    it. The main thread simply waits while the server threads are 
//    handling client requests.  You wouldn't do this in a real app, 
//    but this sample is for illustrative purposes only... 
//
int main(int argc, char **argv)
{
    LANA_ENUM   lenum;
    int         i,
                num=0;

    // Enumerate all LANAs and reset each one
    //
    if (LanaEnum(&lenum) != NRC_GOODRET)
        return 1;
    if (ResetAll(&lenum, 254, 254, FALSE) != NRC_GOODRET)
        return 1;
    //
    // Add the server name to each LANA and issue a listen on each
    //
    for(i=0; i < lenum.length ;i++)
    {
        printf("Registering name '%s' on lana %d\n", SERVER_NAME, num);
        AddName(lenum.lana[i], SERVER_NAME, &num);
        Listen(lenum.lana[i], SERVER_NAME);
    }

    while (1)
    {        
        Sleep(5000);
    }
}
//
// Function: main
//
// Description:
//    Setup the NetBIOS interface, parse the arguments, and call the
//    adapter status command either locally or remotely depending on
//    the user supplied arguments.
//
int main(int argc, char **argv)
{
    LANA_ENUM   lenum;
    int         i, num;

    ValidateArgs(argc, argv);
    //
    // Make sure both command line flags weren't set
    //
    if (bLocalName && bRemoteName)
    {
        printf("usage: astat [/l:LOCALNAME | /r:REMOTENAME]\n");
        return 1;
    }
    // Enumerate all LANAs and reset each one
    //
    if (LanaEnum(&lenum) != NRC_GOODRET)
        return 1;
    if (ResetAll(&lenum, (UCHAR)MAX_SESSIONS, (UCHAR)MAX_NAMES, 
            FALSE) != NRC_GOODRET)
        return 1;
    //
    // If we're called with a local name we need to add it to
    // the name table.
    //
    if (bRemoteName == FALSE)
    {
        for(i=0; i < lenum.length ;i++)
        {
            if (bLocalName)
                AddName(lenum.lana[i], szLocalName, &num);
            LanaStatus(lenum.lana[i], szLocalName);
        }
    }
    else
    {
        for(i=0; i < lenum.length ;i++)
            LanaStatus(lenum.lana[i], szRemoteName);
    }
    return 0;
}
Пример #3
0
//
// Function: main
//
// Description:
//    Initialize the NetBIOS interface, allocate some resources, and
//    post asynchronous listens on each LANA using events. Wait for
//    an event to be triggered, and then handle the client 
//    connection.
//
int main(int argc, char **argv)
{
    PNCB        pncb=NULL;
    HANDLE      hArray[64],
                hThread;
    DWORD       dwHandleCount=0,
                dwRet,
                dwThreadId;
    int         i,
                num;
    LANA_ENUM   lenum;

    // Enumerate all LANAs and reset each one
    //
    if (LanaEnum(&lenum) != NRC_GOODRET)
        return 1;
    if (ResetAll(&lenum, (UCHAR)MAX_SESSIONS, (UCHAR)MAX_NAMES,
            FALSE) != NRC_GOODRET)
        return 1;
    //
    // Allocate an array of NCB structures (one for each LANA)
    // 
    g_Clients = (PNCB)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
            sizeof(NCB) * lenum.length);
    //
    // Create the events, add the server name to each LANA, and issue
    // the asynchronous listens on each LANA.
    //
    for(i = 0; i < lenum.length; i++)
    {
        hArray[i] = g_Clients[i].ncb_event = CreateEvent(NULL, TRUE, 
            FALSE, NULL);

        AddName(lenum.lana[i], SERVER_NAME, &num);
        Listen(&g_Clients[i], lenum.lana[i], SERVER_NAME);
    }
    while (1)
    {        
        // Wait until a client connects
        //
        dwRet = WaitForMultipleObjects(lenum.length, hArray, FALSE, 
            INFINITE);
        if (dwRet == WAIT_FAILED)
        {
            printf("ERROR: WaitForMultipleObjects: %d\n", 
                GetLastError());
            break;
        }
        // Go through all the NCB structures to see if more that one
        // succeeded.  If ncb_cmd_plt is not NRC_PENDING then there
		// is a client, create a thread and hand off a new NCB
		// structure to the thread.  We need to re-use the original
		// NCB for other client connections.
        //
        for(i = 0; i < lenum.length; i++)
        {
            if (g_Clients[i].ncb_cmd_cplt != NRC_PENDING) 
            {
                pncb = (PNCB)GlobalAlloc(GMEM_FIXED, sizeof(NCB));
                memcpy(pncb, &g_Clients[i], sizeof(NCB));
                pncb->ncb_event = 0;

                hThread = CreateThread(NULL, 0, ClientThread, 
                    (LPVOID)pncb, 0, &dwThreadId);
                CloseHandle(hThread);
                //
                // Reset the handle and post another listen 
                //
                ResetEvent(hArray[i]);
                Listen(&g_Clients[i], lenum.lana[i], SERVER_NAME);
            }
        }
    }
    // Clean up
    //
    for(i = 0; i < lenum.length; i++)
    {
        DelName(lenum.lana[i], SERVER_NAME);
        CloseHandle(hArray[i]);
    }
    GlobalFree(g_Clients);

    return 0;
}