// EnumProtocol.cpp : 定义控制台应用程序的入口点。
//
// Get Procotol installed in os
// code @ VS2005
// by lym
#include "stdafx.h"
#include <iostream>
#include <Winsock2.h>
using namespace std;
#pragma comment(lib, "Ws2_32")
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsd;
DWORD dwSize=0;
WSAPROTOCOL_INFO* lpWsaprotocolInfo=NULL;
int ret, i;
// Load Winsock
//
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("WSAStartup() failed: %d\n", GetLastError());
return -1;
}
// first call this funciton for get protocols size
ret = WSAEnumProtocols(NULL,lpWsaprotocolInfo,&dwSize);
if (ret == SOCKET_ERROR)
{
// new memory
lpWsaprotocolInfo = new WSAPROTOCOL_INFO[dwSize];
if (!lpWsaprotocolInfo)
{
printf("Msg: new memory failed!\n");
return 0;
}
// second call this funcion for get protocols info
ret = WSAEnumProtocols(NULL, lpWsaprotocolInfo, &dwSize);
if (ret>0)
{
for (i=0;i<ret;i++)
{
printf("Install Protocol (%d): %s\n", i+1, lpWsaprotocolInfo[i].szProtocol);
}
}
}
// free memory
if (lpWsaprotocolInfo)
{
delete []lpWsaprotocolInfo;
}
// Clean Winsock
WSACleanup();
// for pause
cin >> i;
return 0;
}
评论