我知道好像是用WSAEnumProtocol,不知道拼错了没有,但是具体怎么使用呢?
怎么能读出各种协议的信息呢?
     我也看了MSDN,但是那么多的参数,我的英文又很pool,实在没有头绪,哪位
大侠能提提供线索,或者是有现成的例子,请发到 [email protected]
     急用,谢谢!

解决方案 »

  1.   

    其实MSDN上已经说得非常详细了,不过还是帮楼主翻译解释一下吧呵呵^_^int WSAEnumProtocols(
      LPINT lpiProtocols,
      LPWSAPROTOCOL_INFO lpProtocolBuffer,
      LPDWORD lpdwBufferLength
    );其中:
         lpiProtocols  是一个以NULL结尾的协议标识号数组,一般设置为NULL就行
         lpProtocolBuffer 是一个用WSAPROTOCOL_INFO  结构填充的缓冲区,比较复杂,
                          后面再说^_^
         lpdwBufferLength 是个out参数,用于存储 lpProtocolBuffer所需要的缓冲长度
      
          如果一切正常,这个函数将返回协议的数目,否则就是INVALID_SOCKET错误一般都是这样第一次调用以获得需要的缓冲大小,当然自己设置一个足够大的缓冲也是可以的^_^DWORD dwLen;
    WSAEnumProtocols(NULL,NULL,&dwlen);   //  获得缓冲大小然后再根据缓冲大小来分配实际调用需要的空间^_^
      

  2.   

    实际调用的时候是这样
    LPBYTE pBuf;
    LPWSAPROTOCOL_INFO pInfo;WSAEnumprotocols(NULL,(LPWSAPROTOCOL_INFO)pBuf,&dwLen);
    pInfo = (LPWSAPROTOCOL_INFO)pBuf ;
    然后一点点读取pInfo中的信息就好了然后就是非常复杂的结构体了
    typedef struct _WSAPROTOCOL_INFO {  
    DWORD dwServiceFlags1;  
    DWORD dwServiceFlags2;  
    DWORD dwServiceFlags3; 
     DWORD dwServiceFlags4; 
     DWORD dwProviderFlags;  
    GUID ProviderId;  
    DWORD dwCatalogEntryId;  
    WSAPROTOCOLCHAIN ProtocolChain;  
    int iVersion;  
    int iAddressFamily;  
    int iMaxSockAddr;  
    int iMinSockAddr;  
    int iSocketType;  
    int iProtocol;  
    int iProtocolMaxOffset;  
    int iNetworkByteOrder;  
    int iSecurityScheme;  
    DWORD dwMessageSize;  
    DWORD dwProviderReserved;  
    TCHAR szProtocol[WSAPROTOCOL_LEN+1];
    } WSAPROTOCOL_INFO, *LPWSAPROTOCOL_INFO;举些例子
    pInfo->szProtocol   就是协议的名字
    pinfo->iSocketType  是协议类型
    pInfo->dwMessageSize 是报文最大尺寸等等比较难搞的就是dwServiceFlag1比如里面的 XP1_CONNECTIONLESS 是无连接服务
    XP1_SUPPORT_BROADCAST 是支持广播
    XP1_SUPPORT_MULTIPOINT 是支持多播

    如果需要的话我可以帮你写一个例子呵呵^_^
      

  3.   

    谢谢楼上这么详细的解释,照着你的说法,不少信息都读出来了,但是有些地方还是不对还有一些信息比如 iNetworkByteOrder 和 iSecurityScheme 不知道是什么意思我很菜的,不知道能不能帮我写个例子,谢谢了,我很急呀[email protected]
      

  4.   

    Sample Code
       if (WSAStartup(MAKEWORD(2,2), &WSAData))
          printf("WSAStartup %d", WSAGetLastError());
       else
          {
          // First, have WSAEnumProtocols tell you how big a buffer you need.
          nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
          if (SOCKET_ERROR != nRet)
             printf("WSAEnumProtocols: should not have succeeded\n");
          else if (WSAENOBUFS != (dwErr = WSAGetLastError()))
             // WSAEnumProtocols failed for some reason not relating to buffer
             // size - also odd.
             printf("WSAEnumProtocols(1): %d\n", WSAGetLastError());
          else
             {
             // WSAEnumProtocols failed for the "expected" reason. Therefore,
             // you need to allocate a buffer of the appropriate size.
             lpProtocolBuf = (WSAPROTOCOL_INFO *)malloc(dwBufLen);
             if (lpProtocolBuf)
                {
                // Now you can call WSAEnumProtocols again with the expectation
                // that it will succeed because you have allocated a big enough
                // buffer.
                nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
                if (SOCKET_ERROR == nRet)
                   printf("WSAEnumProtocols(3): %d\n", WSAGetLastError());
                else
                   {
                   // Loop through protocols, looking for the first service
                   // provider that meets the matching criteria.
                   bProtocolFound = FALSE;
                   for (i=0; i<nRet; i++)
                      {
                      if ((IPPROTO_TCP == lpProtocolBuf[i].iProtocol) &&
                          (XP1_QOS_SUPPORTED == (XP1_QOS_SUPPORTED &
                           lpProtocolBuf[i].dwServiceFlags1)))
                         {
                         bProtocolFound = TRUE;
                         break;
                         }
                      }
                   }
                }
             }
          }http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q192/1/20.ASP&NoWebContent=1
      

  5.   

    谢谢 gracezhu(eutom)的回答继续苦等代码.......
      

  6.   

    建议你下个《Widows网络编程》看看
      上面有很详细的解释!
      

  7.   

    写好了^_^给你发过去了,请查收对了,我是用VC.net写的,不知道楼主能不能打开