D
Daniel Rudy
Hello,
Consider the following code:
/* resolve_hostname
this resolves the hostname into an ip address.
*/
static void resolve_hostname(char result[MAXSIZE], const char
hostname[MAXSIZE], const char server[MAXSIZE])
{
struct hostent *hp_ptr; /* pointer for query structure */
struct hostent hp; /* static structure in memory to hold
query results */
unsigned char *chptr; /* character pointer for address list */
struct in_addr in; /* inet_ntoa conversion structure */
unsigned int temp;
/* this is to silence the compiler on a unused variable
warning. */
strcpy(result, server);
/* network call: resolve hostname to ip address using
DNS forward lookup */
hp_ptr = gethostbyname2(hostname, AF_INET);
/* process results */
hp = *hp_ptr;
chptr = (unsigned char *)*hp.h_addr_list;
temp = *chptr;
chptr++;
temp = temp + *chptr * 256;
chptr++;
temp = temp + *chptr * 65536;
chptr++;
temp = temp + *chptr * 16777216;
in.s_addr = temp;
result = inet_ntoa(in);
if (!check_ip_addr(result)) showerror(1, verbose);
}
The problem is that the result is not returned through the parameter
result. Now if I put this statement, fprintf(stdout, "%s\n", result);,
before the closing brace, I get the result printed out, but it doesn't
return to the calling routine. Now I have done something like this
before, and I did check my old code, but I don't see what the problem
is.
Any ideas?
Consider the following code:
/* resolve_hostname
this resolves the hostname into an ip address.
*/
static void resolve_hostname(char result[MAXSIZE], const char
hostname[MAXSIZE], const char server[MAXSIZE])
{
struct hostent *hp_ptr; /* pointer for query structure */
struct hostent hp; /* static structure in memory to hold
query results */
unsigned char *chptr; /* character pointer for address list */
struct in_addr in; /* inet_ntoa conversion structure */
unsigned int temp;
/* this is to silence the compiler on a unused variable
warning. */
strcpy(result, server);
/* network call: resolve hostname to ip address using
DNS forward lookup */
hp_ptr = gethostbyname2(hostname, AF_INET);
/* process results */
hp = *hp_ptr;
chptr = (unsigned char *)*hp.h_addr_list;
temp = *chptr;
chptr++;
temp = temp + *chptr * 256;
chptr++;
temp = temp + *chptr * 65536;
chptr++;
temp = temp + *chptr * 16777216;
in.s_addr = temp;
result = inet_ntoa(in);
if (!check_ip_addr(result)) showerror(1, verbose);
}
The problem is that the result is not returned through the parameter
result. Now if I put this statement, fprintf(stdout, "%s\n", result);,
before the closing brace, I get the result printed out, but it doesn't
return to the calling routine. Now I have done something like this
before, and I did check my old code, but I don't see what the problem
is.
Any ideas?