#include <sys/socket.h> #include <netinet/in.h> struct sockaddr_in sin;s = socket(AF_INET, SOCK_xxx, 0); . . . sin.sin_addr.s_addr = htonl(INADDR_ANY); bind(s, (char *)&sin, sizeof(sin));
The loopback interface is known to the system as ``lo0''.
By default, the loopback interface is accessible at Internet address 127.0.0.1 (INADDR_LOOPBACK). This address is official and should not normally be changed.
The kernel installs routes that cause locally-generated traffic destined for other local addresses to be sent via the loopback interface. This is a performance optimization.
The loopback interface should be the first interface configured, otherwise nameserver lookups for hostnames of other interfaces may fail.
The string ``xxx'' in the parameter SOCK_xxx should be ``STREAM'' when using TCP, ``DGRAM'' when using UDP, and ``RAW'' when using IP.
RFC 1340