[comp.unix.wizards] What is INADDR_LOOPBACK for in sockets?

dieter@lynn.cs.ucla.edu (Dieter Rothmeier) (12/02/89)

While reading some code, I came across the following
construct:

struct sockaddr_in sin;
....
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
...


I know about INADDR_ANY, but I've never seen this one.
It's defined in <netinet/in.h>. I looked through the
documentation (this is on a Sun 3/80) quite extensively,
but couldn't find anything.

Any help would be appreciated.
Dieter

mcgrath@paris.Berkeley.EDU (Roland McGrath) (12/02/89)

INADDR_LOOPBACK is 0x7f000001, Internet address 127.0.0.1, usually called
`localhost'.  Talking to this address gets you back to where you started from,
without going through the network hardware.
--
	Roland McGrath
	Free Software Foundation, Inc.
roland@ai.mit.edu, uunet!ai.mit.edu!roland

housel@en.ecn.purdue.edu (Peter S. Housel) (12/02/89)

In article <MCGRATH.89Dec1142539@paris.Berkeley.EDU>, mcgrath@paris (Roland McGrath) writes:
>INADDR_LOOPBACK is 0x7f000001, Internet address 127.0.0.1, usually called
>`localhost'.  Talking to this address gets you back to where you started from,
>without going through the network hardware.

	The nifty thing is that (on many systems with BSD-derived
networking) you can disable the loopback-net, through which address
127.0.0.1 is routed. Running "ifconfig lo0 down" will disable the
"loopback interface" and the machine will be unable to talk to itself.

	We once had cause to do this. Due to some kernel bug, packets
were occasionally getting stuck in loops within the loopback. The
system would get very sluggish, forwarding packets in tight little
circles.  Until the problem was fixed we just disabled the "interface"
for 30 seconds or so until the offending packet timed out.

-Peter S. Housel-	housel@ecn.purdue.edu		...!pur-ee!housel