#include <sys/socket.h> #include <netinet/in.h> struct sockaddr_in sin;
s = socket(AF_INET, type, 0); ... sin.sin_addr.s_addr = htonl(INADDR_ANY); bind(s, (char *)&sin, sizeof(sin));
The loopback interface is known to the system as lon where n is typically 0.
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 name server lookups for the hostnames of other interfaces may fail.
The socket type should be SOCK_STREAM when using TCP, SOCK_DGRAM when using UDP, and SOCK_RAW when using IP.