Hey guys,
No matter what I do, I can't get this code to stop segfaulting, and as you can see by the debugging printf's, it does so at the assignment of `in' .. there's another warning on compilation:
Code:
tmp.c:25: warning: assignment makes pointer from integer without a cast
.. this quick code was written to re-create the segfault (the program I'm writing is quite long, so I decided instead of pasting all of it, or a snipped portion of it, i'd write a quick example to show you what happens), so you could all see when in the execution the segfault occurs, and hopefully offer up some suggestions as you how I could fix this =\ .. anyway, any ideas would be greatly appreciated! Thanks =]
Here's the code:
Code:
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
int resolve(char *, struct hostent *, struct in_addr **);
int main(int argc, char *argv[])
{
struct hostent *hent;
struct in_addr **in;
printf("DEBUG: Defined structures.\n");
in = (struct in_addr **)hent->h_addr_list;
printf("DEBUG: Passed `in' initialization.\n");
resolve(argv[1], hent, in);
return 0;
}
int resolve(char *host, struct hostent *hent, struct in_addr **in)
{
char *addr;
addr = inet_ntoa(**in);
if((hent = gethostbyname(host)) == NULL) {
fprintf(stderr, "Error: gethostbyname() failed\n");
return -1;
}
printf("%s\t\t%s\n", host, addr[0]);
return 0;
}