All of lore.kernel.org
 help / color / mirror / Atom feed
* INADDR_ANY
@ 2003-07-15 12:07 Lejanson Go
  2003-07-15 14:36 ` INADDR_ANY Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Lejanson Go @ 2003-07-15 12:07 UTC (permalink / raw)
  To: linux-c-programming


Hello good day to everyone.

my other email ad is a member of this list but im 
just confuse so i use this email ad instead to ask
some questions.

i have a question regarding network programming.
my program connects to a server using INADDR_ANY
as the host address.

does the macro INADDR_ANY points to loopback
interface?

what if the /etc/hosts fileis edited and the value of
localhost is changed to "50.50.50.20" from "127.0.0.1"
  
is it possible the program will fail? considering that
using 127.0.0.1 as "localhost" ip add the program
functions well.

it puzzles me. since the program was supposed to work.

any help would be very much appreciated. 

thanks a lot.


lejanson





__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: INADDR_ANY
  2003-07-15 12:07 INADDR_ANY Lejanson Go
@ 2003-07-15 14:36 ` Glynn Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2003-07-15 14:36 UTC (permalink / raw)
  To: Lejanson Go; +Cc: linux-c-programming


Lejanson Go wrote:

> my other email ad is a member of this list but im 
> just confuse so i use this email ad instead to ask
> some questions.
> 
> i have a question regarding network programming.
> my program connects to a server using INADDR_ANY
> as the host address.
> 
> does the macro INADDR_ANY points to loopback
> interface?

No. INADDR_ANY is just zero. The normal use of this macro is binding
server sockets, when you need to bind to a specific port (with bind())
but don't wish to bind to a specific address (i.e. you wish to accept
connections on any local IP address). E.g.

	struct sockaddr_in addr;
	int sock;

	sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = INADDR_ANY;
	bind(sock, (struct sockaddr *) &addr, sizeof(addr));

	listen(sock, 0);

INADDR_ANY isn't meaningful in most other contexts, e.g. in the
address passed to connect().

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-07-15 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15 12:07 INADDR_ANY Lejanson Go
2003-07-15 14:36 ` INADDR_ANY Glynn Clements

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.