linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn.clements@virgin.net>
To: Lejanson Go <lejanson@yahoo.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: INADDR_ANY
Date: Tue, 15 Jul 2003 15:36:10 +0100	[thread overview]
Message-ID: <16148.4442.650372.788264@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <20030715120742.94906.qmail@web12403.mail.yahoo.com>


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>

      reply	other threads:[~2003-07-15 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-15 12:07 INADDR_ANY Lejanson Go
2003-07-15 14:36 ` Glynn Clements [this message]

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=16148.4442.650372.788264@cerise.nosuchdomain.co.uk \
    --to=glynn.clements@virgin.net \
    --cc=lejanson@yahoo.com \
    --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).