我知道好像是用WSAEnumProtocol,不知道拼错了没有,但是具体怎么使用呢?
怎么能读出各种协议的信息呢?
我也看了MSDN,但是那么多的参数,我的英文又很pool,实在没有头绪,哪位
大侠能提提供线索,或者是有现成的例子,请发到 [email protected]
急用,谢谢!
解决方案 »
- 数据类型转换的问题。关于数据库的
- 面试题
- 终于升到星星了,散分,庆祝
- 求教:CListView中如何实现Ctrl+A全选?在线等
- 菜鸟的数据库打开问题
- 在使用ado时,我不用_variant_t,有没有其它替代的函数
- 为什么安装完3721以后ie的网络实名可以马上生效呢?而我自己做的插件必须使ie重新启动一次才可以呢?
- 客户端Connet()返回错误10035代表什么意思 ErrerLook 查不到
- 那里有vc对声音、音频信息的编程资料、文档?谢谢!(100分不够可加)
- 如何在程序中更改当前系统打印设置值
- 请高手解决下怎么样想金山游侠那样动态修改内存
- 请问:如何从EXE把一个对象传入DLL文件的接口函数呢〉
LPINT lpiProtocols,
LPWSAPROTOCOL_INFO lpProtocolBuffer,
LPDWORD lpdwBufferLength
);其中:
lpiProtocols 是一个以NULL结尾的协议标识号数组,一般设置为NULL就行
lpProtocolBuffer 是一个用WSAPROTOCOL_INFO 结构填充的缓冲区,比较复杂,
后面再说^_^
lpdwBufferLength 是个out参数,用于存储 lpProtocolBuffer所需要的缓冲长度
如果一切正常,这个函数将返回协议的数目,否则就是INVALID_SOCKET错误一般都是这样第一次调用以获得需要的缓冲大小,当然自己设置一个足够大的缓冲也是可以的^_^DWORD dwLen;
WSAEnumProtocols(NULL,NULL,&dwlen); // 获得缓冲大小然后再根据缓冲大小来分配实际调用需要的空间^_^
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 是支持多播
。
如果需要的话我可以帮你写一个例子呵呵^_^
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
上面有很详细的解释!