// PROGRAMMER: Faraz Kamal

#include <unistd.h>
#include <iostream>
#include <netdb.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/socket.h>
#include <vector>
#include <errno.h>
#include <string>


using namespace std;

bool isNumeric(const char * input, bool decimalOK)
{
	if (strlen(input) == 0)
	{
		return false;
	}

	bool retval = true;

	for (int i = 0; i < strlen(input); i++)
	{
		if (input[i] == '.')
		{
			if (!decimalOK)
			{
				retval = false;
			}
		}
		else if (!isdigit(input[i]))
		{
			retval = false;
		}
	}

	return retval;
}

//return local IP in network byte order
unsigned long GetLocalIP()
{
	unsigned long retVal;
	char hostname[255];
	gethostname(hostname, 255);

	struct hostent *hostInfo;
	if ((hostInfo = gethostbyname(hostname)) == NULL)
	{
		cout << "ERROR: error getting local host's IP." << endl;
		return -1;
	}

	memcpy((char *) &retVal, hostInfo->h_addr_list[0], sizeof(retVal));
	return retVal;
}
