Skip to contentSkip to conversation

Remote host name

DISCUSSION HIToC 2 participants 3 messages Dec 15, 2004

lore
Share & tools
lore

HIToC

author
#0 lore raw

Hi all.
I am writing a function that returns the name of the remote host which we are connected to. About the remote host I only know its IP address...I have tried to use function "gethostbyname" passing for argument the IP address in standard dot notation:

[man 3 gethostbyname: The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon (and possibly dot) notation.]

struct sockaddr_in destination;

char* get_remote_host_name()
{
hostent* remote_host_information;
char* host_IP;

  host_IP =  inet_ntoa(destination.sin_addr);
  remote_host_information = gethostbyname(host_IP);

return remote_host_information->h_name;
}

This function returns the IP address of the remote host, not its (DNS) name! Can anybody help me?

Signature · 3 lines
With regards,
				HIToC 
				[email protected]
#1 lore raw

use gethostbyname().....

example:
gethostname( strVariable, len );
printf( "hostname: %s\n", strVariable );

gethostbyname(), on the other hand, is for returning the equivalent ip address of the specified name.. hence the name "gethostbyname"...

Quoted 29 lines · HIToC

Hi all.
I am writing a function that returns the name of the remote host which we are connected to. About the remote host I only know its IP address...I have tried to use function "gethostbyname" passing for argument the IP address in standard dot notation:

[man 3 gethostbyname: The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon
(and possibly dot) notation.]

struct sockaddr_in destination;

char* get_remote_host_name()
{
hostent* remote_host_information;
char* host_IP;

host_IP = inet_ntoa(destination.sin_addr); remote_host_information = gethostbyname(host_IP);

return remote_host_information->h_name;
}

This function returns the IP address of the remote host, not its (DNS) name! Can anybody help me?

#2 lore raw

oops..
i meant [gethostname()] not [gethostbyname()]
=(

sorry

Quoted 50 lines · Ron Michael Khu

use gethostbyname().....

example:
gethostname( strVariable, len );
printf( "hostname: %s\n", strVariable );

gethostbyname(), on the other hand, is for returning the equivalent ip address of the specified name.. hence the name "gethostbyname"...

Quoted 21 lines · HIToC

Hi all.
I am writing a function that returns the name of the remote host which we are connected to. About the remote host I only know its IP address...I have tried to use function "gethostbyname" passing for argument the IP address in standard dot notation:

[man 3 gethostbyname: The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon
(and possibly dot) notation.]

struct sockaddr_in destination;

char* get_remote_host_name()
{
hostent* remote_host_information;
char* host_IP;

host_IP = inet_ntoa(destination.sin_addr); remote_host_information = gethostbyname(host_IP);

Quoted 8 lines

return remote_host_information->h_name;
}

This function returns the IP address of the remote host, not its (DNS) name! Can anybody help me?

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html