I've been playing with Pelles C for about a week now and I really like it, but I think I need some help with the C language part (or maybe the compiler). I have this function:
/******************************************************************************
GetIPFromHostName
******************************************************************************/
char* GetIPFromHostName (char* sHostName)
{
static LPHOSTENT host;
static char* addr;
static IN_ADDR iaHost;
iaHost.s_addr=inet_addr(sHostName);
host=gethostbyname(sHostName);
iaHost=*((LPIN_ADDR)*host->h_addr_list);
addr=inet_ntoa(iaHost);
return addr;
}
My project compiles without error, but it crashes when I click the button that runs this function. Commenting lines out 1 at a time, I concluded that it crashes on
iaHost=*((LPIN_ADDR)*host->h_addr_list); - I am new at C, but I've dealt with pointers before in other languages, so I don't figure out what's wrong with it. Am I missing a compiler option? Do I have a wrong include file? Or is my coding just poor and dysfunctional?
I attached the whole project in case the problem is not with the function code, if anyone could help me out I'd appreciate it.
Also, what would the suggested method be for me to solve issues like this on my own? I tried doing a debug mode, but that just dumped me to assembly when the program crashed - learning C is a stretch for me.
Is there an easy way I can make sure a legit value exists in the
host variable?
Thanks again,
Thad