Google Answers Logo
View Question
 
Q: determining IP address when using INADDR_ANY ( No Answer,   2 Comments )
Question  
Subject: determining IP address when using INADDR_ANY
Category: Computers > Programming
Asked by: althepal-ga
List Price: $20.00
Posted: 16 Jan 2005 00:45 PST
Expires: 16 Jan 2005 19:57 PST
Question ID: 457982
I'm writing a server in Perl, and I use INADDR_ANY to accept the
connection on any one of several IP addresses.

Is there any way to determine which IP address the connection was made
on? I know I could run multiple instances of the server on each of the
IP addresses, but I'd rather run one instance, and have different
output depending on which IP address was contacted.

Along similar lines, I would like to be able to determine all the IP
addresses that I was listening on when using INADDR_ANY.

I'd need to know how to do this in perl.

Clarification of Question by althepal-ga on 16 Jan 2005 00:47 PST
Just to be sure this is understood, I want my IP address that the
connection is made on, not the remote IP address.
Answer  
There is no answer at this time.

Comments  
Subject: Re: determining IP address when using INADDR_ANY
From: vladimir-ga on 16 Jan 2005 04:15 PST
 
Try using the getsockname() function, like this:

$mysockaddr = getsockname(SOCK);
($port, $myaddr) = sockaddr_in($mysockaddr);
printf "Connect to %s [%s]\n",
  scalar gethostbyaddr($myaddr, AF_INET),
  inet_ntoa($myaddr);

Vladimir
Subject: Re: determining IP address when using INADDR_ANY
From: althepal-ga on 16 Jan 2005 19:56 PST
 
I think that's what I was looking for. Thank you so much.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy