#include <winsock2.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    // Declare and initialize variables
    WSADATA wsaData;
	struct protoent *servptr;
	// http://www.iana.org/assignments/port-numbers
	char protocol[12][10] = {"ip","icmp","ggp","tcp", "egp","pup","udp","hmp","xns-idp",
		"rdp","rvd" };
	int i;

	// Initialize Winsock
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
        printf("WSAStartup() failed with error code %ld\n", WSAGetLastError());
        return 1;
    }
	else
		printf("WSAStartup() looks fine!\n");

	// Traverse the array content...
	//Be careful with the array index...
	for(i=0; i <= 10;i++)
	{
		servptr = getprotobyname(protocol[i]);
		
		if (servptr == NULL)
			printf ("\ngetprotobyname() - %d failed with error code %ld\n", protocol[i], WSAGetLastError());
		else
		{
			// Print the related info
			printf("getprotobyname() is OK - %s\n", protocol[i]);
			printf(" Official name is %s\n", servptr->p_name);
			printf(" Protocol number is %d\n", servptr->p_proto);
		}
	}

	WSACleanup();
    return 0;
}
