linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
To: HIToC <hitoc_mail@yahoo.it>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Remote host name
Date: Thu, 16 Dec 2004 00:02:08 +0800	[thread overview]
Message-ID: <41C06000.4040503@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <200412151636.28714.hitoc_mail@yahoo.it>

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"...



HIToC wrote:

>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?
>  
>



  reply	other threads:[~2004-12-15 16:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-15 15:45 Remote host name HIToC
2004-12-15 16:02 ` Ron Michael Khu [this message]
2004-12-15 17:41   ` Ron Michael Khu
     [not found] <31E38B53D182D51195FA00508BE3A33405200607@zwnbc004.cala.nortel.com>
2004-12-16 15:03 ` HIToC

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41C06000.4040503@hq.ntsp.nec.co.jp \
    --to=ronkhu@ntsp.nec.co.jp \
    --cc=hitoc_mail@yahoo.it \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).