亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? rnrcs.c

?? 《Windows網絡編程技術》附書源碼源碼. 運行環境:9x/Me/NT/2000/XP/ 源碼語言:簡體中文 第十四章
?? C
?? 第 1 頁 / 共 2 頁
字號:
// Module: rnrcs.c
//
// Description:
//    This sample illustrates how a server can create a socket and
//    advertise the existance of the service to clients.  It also
//    shows how a client with knowledge of the server's name only
//    can find out how to connect to the server in order to transmit
//    data. The server accomplishes this by installing a service
//    class which describes the basic characteristics of the service
//    and then registering an instance of the server which references
//    the given class. The service can be registered for multiple
//    name spaces such as IPX and NTDS.
//
//    The client can query the available name spaces for knowledge
//    of a service of the given name. If the query completes 
//    successfully, the address of the service is returned.  All
//    the client needs to do is use that address in either a
//    connect or sendto call.
//
// Compile:
//     cl rnrcs.c ws2_32.lib user32.lib ole32.lib
//
// Command Line Arguments/Parameters
//     rnrcs -c:ServiceName -s:ServiceName -t:ID -n:NameSpace
//       -c:ServiceName      Act as client and query for this service name
//       -s:ServiceName      Act as server and register service as this name
//       -t:ID               SAP ID to register under
//       -n:NameSpace        Name space to register service under
//                             Supported namespaces are NS_ALL, NS_SAP, NS_NTDS
//       -d                  Delete the service if found
//

#include <winsock2.h>
#include <windows.h>

#include <ws2tcpip.h>
#include <nspapi.h>

#include <svcguid.h>

#include "mynsp.h"

#include <stdio.h>
#include <stdlib.h>

#define MAX_NUM_CSADDRS        20
#define MAX_INTERFACE_LIST     20
#define MAX_NUM_SOCKETS        20

#define MAX_BUFFER_SZ         512

#define MAX_SERVER_NAME_SZ     64

#define DEFAULT_SERVER_NAME    "JunkServer"

char    szServerName[MAX_SERVER_NAME_SZ];   // Server name
BOOL    bServer,                            // Client or server?
        bDeleteService;
DWORD   dwUniqueId;                         // Used to create a GUID
SOCKET  sock;

//
// Function: usage
//
// Description:
//    Print usage information.
//
void usage(char *progname)
{
    printf("usage: %s  -c:Service -s  -t:ID\n",
        progname);
    printf("  -c:ServiceName Act as client and query for this service name\n");
    printf("  -s:ServiceName Act as server and register service as this name\n");
    printf("  -t:ID          Unique ID to register under\n");
    printf("  -d             Delete the service on a successful query\n");
    ExitProcess(-1);
}

//
// Function: ValidateArgs
//
// Description:
//    Parse command line parameters and set some global variables used
//    by the application.
//
void ValidateArgs(int argc, char **argv)
{
    int    i;

    // Set some default values
    //
    lstrcpy(szServerName, TEXT(DEFAULT_SERVER_NAME));
    dwUniqueId = 200;
    bDeleteService = FALSE;

    for (i=1; i < argc ;i++) 
    {
        if ((argv[i][0] == '-') || (argv[i][0] == '/')) 
        {
            switch (tolower(argv[i][1])) 
            {
                case 't':        // SAP id used to generate GUID
                    //if (lstrlen(argv[i]) > 3)
                    //    dwUniqueId = atoi(&argv[i][3]);
                    break;
                case 'c':        // Client, query for given service
                    bServer = FALSE;
                    if (lstrlen(argv[i]) > 3)
                        lstrcpy(szServerName, &argv[i][3]);
                    break;
                case 's':        // Server, register as the given service
                    bServer = TRUE;
                    if (lstrlen(argv[i]) > 3)
                        lstrcpy(szServerName, &argv[i][3]);
                    break;
                case 'd':
                    bDeleteService = TRUE;
                    break;
                default:
                    usage(argv[0]);
                    return;
            }
        }
        else
            usage(argv[0]);
    }
    return;
}

//
// Function: EnumNameSpaceProviders
//
// Description:
//    Returns an array of those name spaces which our application
//    supports. If one day, NS_DNS becomes dynamic, modify this
//    function to return that structure as well. 
//
WSANAMESPACE_INFO *EnumNameSpaceProviders(int *count)
{
    WSANAMESPACE_INFO *nsinfo,
                      *nsinfocpy;
    BYTE              *pbuf=NULL,
                      *pbufcpy=NULL;
    DWORD              dwBytes;
    int                i, j,
                       ret;

    *count = 0;
    dwBytes = 0;
    //
    // First find out how big of a buffer we need
    //
    ret = WSAEnumNameSpaceProviders(&dwBytes, NULL);
    if (ret == SOCKET_ERROR)
    {
        if (WSAGetLastError() != WSAEFAULT)
        {
            printf("WSAEnumNameSpaceProviders() failed: %d\n",
                WSAGetLastError());
            return NULL;
        }
    }
    // Allocate this buffer and call the function again
    //
    pbuf = (BYTE *)GlobalAlloc(GPTR, dwBytes);
    if (!pbuf)
    {
        printf("GlobaAlloc() failed: %d\n", GetLastError());
        return NULL;
    }
    nsinfo = (WSANAMESPACE_INFO *)pbuf;
    ret = WSAEnumNameSpaceProviders(&dwBytes, nsinfo);
    if (ret == SOCKET_ERROR)
    {
        printf("WSAEnumNameSpaceProviders() failed: %d\n",
            WSAGetLastError());
        HeapFree(GetProcessHeap(), 0, pbuf);
        return NULL;
    }
    // Make a copy buffer which we will return our data in
    //
    pbufcpy = GlobalAlloc(GPTR, dwBytes);
    if (!pbufcpy)
    {
        printf("GlobaAlloc() failed: %d\n", GetLastError());
        return NULL;
    }
    // Loop throug the returned name space structures picking
    // those which our app supports
    //
    nsinfocpy = (WSANAMESPACE_INFO *)pbufcpy;
    printf("%d name spaces are available\n", ret);

    j = 0;
    for(i=0; i < ret ;i++)
    {
        switch (nsinfo[i].dwNameSpace)
        {
            // In this example all we want is our own name space 
            //
            case NS_MYNSP:
                printf("Found a match: %S\n", nsinfo[i].lpszIdentifier); 
                memcpy(&nsinfocpy[j++], &nsinfo[i], sizeof(WSANAMESPACE_INFO));
                break;
	    default:
		break;
        }
    }
    // Free the original buffer and return our copy of useable name spaces
    //
    GlobalFree(pbuf);

    printf("Found %d useable name spaces\n\n", j);

    *count = j;
    return nsinfocpy;
}

//
// Function: InstallServiceClass
//
// Description:
//    This function installs the service class which is required before
//    registering an instance of a service. A service class defines the
//    generic attributes of a class of services such as whether it is
//    connection oriented or not as well as what protocols is supports
//    (IPX, IP, etc).
//
BOOL InstallServiceClass(GUID *svcguid, WSANAMESPACE_INFO *nsinfo, int nscount)
{
    WSASERVICECLASSINFO  sci;
    WSANSCLASSINFO      *nsclass=NULL;
    DWORD                dwOne=1;
    TCHAR                szServiceClassName[64];
    int                  i,
                         ret;
    BOOL                 bRet;

    bRet = TRUE;
    //
    // Generate a name of our service class
    //
    wsprintf(szServiceClassName, TEXT("Service Class/TCP Port: %003d"), dwUniqueId);
    printf("Installing service class: '%s'\n", szServiceClassName);
    //
    // There are 2 attributes we need to set for every name space
    // we want to register in: Connection Oriented/Connectionless as
    // well as the address family of the protocols we support.
    //
    nsclass = GlobalAlloc(GPTR, sizeof(WSANSCLASSINFO) * nscount * 2);
    if (!nsclass)
    {
        printf("GlobalAlloc() failed: %d\n", GetLastError());
        return FALSE;
    }
    // Initialize the structure
    //
    memset(&sci, 0, sizeof(sci));
    sci.lpServiceClassId = svcguid;
    sci.lpszServiceClassName = szServiceClassName;
    sci.dwCount = nscount * 2;
    sci.lpClassInfos = nsclass;

    printf("Namespace count: %d, Namespace: %d\n", nscount, nsinfo[0].dwNameSpace);
    for(i=0; i < nscount ;i++)
    {
        // No matter what name space we use we set the connection
        // oriented attribute to false (i.e. connectionless)
        //
        nsclass[i*2].lpszName = SERVICE_TYPE_VALUE_CONN;
        nsclass[i*2].dwNameSpace = nsinfo[i].dwNameSpace;
        nsclass[i*2].dwValueType = REG_DWORD;
        nsclass[i*2].dwValueSize = sizeof(DWORD);
        nsclass[i*2].lpValue = &dwOne;

        if (nsinfo[i].dwNameSpace == NS_MYNSP)
        {
            // If NS_MYNSP is available we will be running a UDP
            // based service on the given port number
            //
            printf("Setting NS_MYNSP info...\n");
            nsclass[(i*2)+1].lpszName = SERVICE_TYPE_VALUE_TCPPORT;
            nsclass[(i*2)+1].dwNameSpace = nsinfo[i].dwNameSpace;
            nsclass[(i*2)+1].dwValueType = REG_DWORD;
            nsclass[(i*2)+1].dwValueSize = sizeof(DWORD);
            nsclass[(i*2)+1].lpValue = &dwUniqueId;            
        }
    }
    // Install the service class
    //
    ret = WSAInstallServiceClass(&sci);
    if (ret == SOCKET_ERROR)
    {
        if (WSAGetLastError() == WSAEALREADY)
        {
            printf("Service class already registered\n");
            bRet = TRUE;
        }
        else
        {
            printf("WSAInstallServiceClass() failed: %d\n",
                WSAGetLastError());
            bRet = FALSE;
        }
    }
    GlobalFree(nsclass);

    return bRet;
}

//
// Function: GetIPInterfaceList
//
// Description:
//    This function returns an array of SOCKADDR_IN structures,
//    one for every local IP interface on the machine. We use
//    the ioctl command SIO_GET_INTERFACE_LIST to do this although
//    we could have used any number of method such as gethostbyname(),
//    SIO_INTERFACE_LIST_QUERY, or the IP helper APIs.
//
SOCKADDR_IN *GetIPInterfaceList(SOCKET s, int *count)
{
    static SOCKADDR_IN  sa_in[MAX_NUM_CSADDRS];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美自拍偷拍午夜视频| 9久草视频在线视频精品| 亚洲另类色综合网站| 亚洲婷婷在线视频| 国产精品电影院| 亚洲婷婷国产精品电影人久久| 国产精品久久久久久久久果冻传媒| 久久天堂av综合合色蜜桃网| 久久丝袜美腿综合| 国产精品天美传媒沈樵| 国产精品久久久久久久第一福利| 亚洲日本在线a| 三级一区在线视频先锋| 精久久久久久久久久久| 成人丝袜视频网| 色视频欧美一区二区三区| 欧美精品丝袜中出| 久久精品综合网| 亚洲三级电影网站| 日本在线不卡视频| 成人理论电影网| 欧美日韩国产一二三| 日韩精品中文字幕在线一区| 国产女主播一区| 一区二区三区在线视频免费观看| 三级在线观看一区二区| 国产99久久久国产精品潘金 | 欧美一区二视频| 久久综合网色—综合色88| 国产精品国产a| 亚洲成a天堂v人片| 国产精品夜夜嗨| 精品视频色一区| 日本一区二区视频在线| 亚洲午夜久久久久| 高清在线成人网| 欧美特级限制片免费在线观看| 精品88久久久久88久久久| 亚洲欧美视频在线观看视频| 蜜臀久久99精品久久久久宅男| av高清不卡在线| 久久综合久久综合亚洲| 亚洲成人av免费| 91在线观看美女| 国产亚洲一区二区三区四区| 婷婷中文字幕综合| 北岛玲一区二区三区四区| 日韩一级二级三级精品视频| 亚洲精品国产无天堂网2021| 国产精品中文字幕日韩精品| 91精品国产91久久久久久一区二区| 国产精品国产三级国产有无不卡 | 亚洲国产精品麻豆| 成人亚洲精品久久久久软件| 日韩一区二区三免费高清| 亚洲精品伦理在线| 成人av网站在线观看免费| 久久综合九色综合97婷婷女人 | 99久久伊人网影院| 久久综合一区二区| 精品一区二区在线看| 欧美另类一区二区三区| 怡红院av一区二区三区| 99久久亚洲一区二区三区青草| 国产视频一区在线观看| 蜜臀a∨国产成人精品| 欧美日韩三级一区| 一片黄亚洲嫩模| 91久久国产综合久久| 亚洲欧美另类久久久精品2019| 成人午夜免费视频| 中文字幕在线一区| 91麻豆福利精品推荐| 中文字幕一区在线观看视频| jvid福利写真一区二区三区| 中文字幕一区二区不卡| www.欧美亚洲| 亚洲色图欧美激情| 在线亚洲高清视频| 亚洲国产精品久久久久婷婷884 | 亚洲激情自拍视频| 色婷婷综合久久久久中文一区二区| 1024成人网色www| 99精品欧美一区二区三区综合在线| 亚洲少妇中出一区| 色先锋久久av资源部| 午夜精品久久久久久久99樱桃| 7777精品伊人久久久大香线蕉最新版 | 秋霞影院一区二区| 26uuu色噜噜精品一区二区| 国产传媒欧美日韩成人| 中文字幕在线视频一区| 欧美少妇性性性| 伊人夜夜躁av伊人久久| 在线欧美日韩精品| 日韩电影在线一区二区| 2021中文字幕一区亚洲| www.视频一区| 天堂av在线一区| 26uuuu精品一区二区| 91一区在线观看| 五月天一区二区| 欧美激情综合五月色丁香| 日本久久精品电影| 久久国产免费看| 亚洲色图制服丝袜| 日韩一区国产二区欧美三区| 粉嫩aⅴ一区二区三区四区五区| 一区二区三区日本| 精品国产一区二区国模嫣然| 91小宝寻花一区二区三区| 免费观看在线综合色| 久久久久久黄色| 欧美色图免费看| 国产成人免费在线观看| 五月婷婷综合在线| 欧美韩日一区二区三区四区| 在线成人免费观看| av福利精品导航| 精品一区二区三区的国产在线播放| 亚洲欧美日韩国产手机在线| 欧美成人激情免费网| 91久久精品一区二区二区| 国产成人8x视频一区二区| 日本午夜精品视频在线观看 | 亚洲色图欧洲色图| 欧美变态凌虐bdsm| 欧美丝袜丝交足nylons图片| 9l国产精品久久久久麻豆| 韩国av一区二区三区在线观看| 一区二区三区在线观看动漫| 久久美女高清视频| 欧美一区二区三区日韩| 色婷婷久久综合| 99久久精品情趣| 国产精品一级二级三级| 久久精品国产网站| 日一区二区三区| 亚洲国产一区二区三区| 亚洲女厕所小便bbb| 中文字幕亚洲欧美在线不卡| 欧美国产国产综合| 国产天堂亚洲国产碰碰| xfplay精品久久| 欧美成人video| 欧美成人国产一区二区| 精品国产乱码久久久久久浪潮 | 亚洲精品成人天堂一二三| 国产精品视频一二| 中国av一区二区三区| 中文字幕欧美区| 亚洲同性gay激情无套| 亚洲精选一二三| 亚洲一区欧美一区| 视频一区欧美精品| 久久精品国产秦先生| 免费高清在线一区| 久久69国产一区二区蜜臀 | 国产喂奶挤奶一区二区三区| 久久精子c满五个校花| 国产精品天天摸av网| 亚洲欧洲99久久| 亚洲成a天堂v人片| 美国av一区二区| 国产酒店精品激情| 成人午夜在线播放| 色综合久久久久网| 在线播放日韩导航| 久久久不卡影院| 亚洲视频图片小说| 亚洲高清视频中文字幕| 麻豆视频一区二区| 国产福利一区二区三区视频| 国产99久久久精品| 欧美专区日韩专区| 欧美r级电影在线观看| 国产精品美女久久久久av爽李琼 | 亚洲一区二区三区视频在线| 亚洲婷婷在线视频| 亚洲午夜日本在线观看| 日本欧美加勒比视频| 国产成人午夜99999| 91免费观看视频在线| 日韩视频123| 中文字幕五月欧美| 青青草精品视频| a在线欧美一区| 日韩欧美综合在线| 中文字幕一区二区三区色视频| 日本不卡的三区四区五区| 国产一级精品在线| 精品视频在线免费观看| 国产日韩精品一区| 三级亚洲高清视频| 97久久精品人人澡人人爽| 精品久久久久久久人人人人传媒| 亚洲欧美日韩国产另类专区| 精品一区二区在线观看| 欧美午夜精品久久久久久孕妇| 亚洲国产经典视频|