Author Topic: gethostbyname  (Read 3327 times)


  • Guest
« on: January 21, 2007, 03:52:36 pm »
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:
Code: [Select]


char* GetIPFromHostName (char* sHostName)
static LPHOSTENT host;
static  char*  addr;
static  IN_ADDR  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,

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1899
« Reply #1 on: January 21, 2007, 04:49:54 pm »
Remember to use these in your code:
May the source be with you


  • Guest
« Reply #2 on: January 21, 2007, 05:16:47 pm »
ooops... thanks.