#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "SDL.h"
#include "SDL_net.h"

int main(int argc, char **argv)
{
	IPaddress ip;
	Uint32 ipI;
	int ip1, ip2, ip3, ip4;
	char *hostname;
	

	
	if (argc < 2)
	{
		fprintf(stderr, "Usage: %s host\n", argv[0]);
		exit(EXIT_FAILURE);
	}


	
	if (SDL_Init(0) < 0)
	{
		fprintf(stderr, "SDL_Init: %s\n", SDLNet_GetError());
		exit(EXIT_FAILURE);
	}
	
	if (SDLNet_Init() < 0)
	{
		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
		exit(EXIT_FAILURE);
	}

	
	if (SDLNet_ResolveHost(&ip, argv[1], 0))
	{
		fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
		exit(EXIT_FAILURE);
	}
	

	if( !(hostname = SDLNet_ResolveIP(&ip)))
	{
		fprintf(stderr, "SDLNet_ResolveIP: %s\n", SDLNet_GetError());
	}
	else
	{
		ipI = SDLNet_Read32(&ip.host);
		
		ip1 = (ipI>>24)&0xFF;
		ip2 = (ipI>>16)&0xFF;
		ip3 = (ipI>>8)&0xFF;
		ip4 = ipI&0xFF;
		
		printf("Hostname is : %s\n", hostname);
		printf("IP adress is : %d.%d.%d.%d\n", ip1, ip2, ip3, ip4);
	}

	
	SDLNet_Quit();
	return 0;
}
