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代码段一直没执行,请高手指点一下,怎么 样才能使中间执行。
{
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代码段一直没执行,请高手指点一下,怎么 样才能使中间执行。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货