BOOL FindProtocol(WSAPROTOCOL_INFO *lpProto) 

    WSAPROTOCOL_INFO *lpProtocolBuf=NULL; 
    DWORD             dwErr, 
                      dwRet, 
                      dwBufLen=0, 
                      i;     if (WSAEnumProtocols(NULL, lpProtocolBuf,  
        &dwBufLen) != SOCKET_ERROR) 
    { 
        // This should never happen as there is a NULL buffer 
        // 
    printf("WSAEnumProtocols failed!\n"); 
    return FALSE; 
    }     
    else if ((dwErr = WSAGetLastError()) != WSAENOBUFS) 
    { 
    // We failed for some reason not relating to buffer size -  
        // also odd 
        // 
    printf("WSAEnumProtocols failed: %d\n", dwErr); 
    return FALSE; 
    }     // Allocate the correct buffer size for WSAEnumProtocols as 
    // well as the buffer to return 
    // 
    lpProtocolBuf = (WSAPROTOCOL_INFO *)GlobalAlloc(GMEM_FIXED,  
        dwBufLen);     if (lpProtocolBuf == NULL) 
    { 
    printf("GlobalAlloc failed: %d\n", GetLastError()); 
    return FALSE; 
    } 
    dwRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen); 
    if (dwRet == SOCKET_ERROR) 
    { 
    printf("WSAEnumProtocols failed: %d\n", WSAGetLastError()); 
    GlobalFree(lpProtocolBuf); 
    return FALSE; 
    } 
    // Loop through the returned protocol information looking for those 
    // that are in the AF_NETBIOS address family. 
    // 
    for (i=0; i < dwRet ;i++) 
    { 
    if ( (lpProtocolBuf[i].iAddressFamily == AF_ATM) && 
             (lpProtocolBuf[i].iSocketType == SOCK_RAW)  && 
             (lpProtocolBuf[i].iProtocol == ATMPROTO_AAL5) ) 
        { 
            memcpy(lpProto, &lpProtocolBuf[i], sizeof(WSAPROTOCOL_INFO));                GlobalFree(lpProtocolBuf);                return TRUE;         } 
    } 
    GlobalFree(lpProtocolBuf);     return FALSE; 

  
上面这段代码中执行后,返回的是FALSE,if代码段一直没执行,请高手指点一下,怎么 样才能使中间执行。 

解决方案 »

  1.   

    查看一下dwRet的值是多少。再看看lpProtocolBuf的值都有哪些
      

  2.   

    dwRet值是16, for循环从开始到结束都没有进入到if代码段中
      

  3.   

    调用WSAEnumProtocols()得到了主机中安装了什么类型的协议,上面程序段中运行结果表明没有安装ATM多播协议,请教高手怎么安装ATM协议啊,大家帮帮忙啊