IPv4 Internet host addresses are represented in some contexts as integers
uint32_t). In other contexts, the integer is
packaged inside a structure of type
struct in_addr. It would
be better if the usage were made consistent, but it is not hard to extract
the integer from the structure or put the integer into a structure.
You will find older code that uses
unsigned long int for
IPv4 Internet host addresses instead of
unsigned long int was a 32-bit number but
with 64-bit machines this has changed. Using
unsigned long int
might break the code if it is used on machines where this type doesn't
have 32 bits.
uint32_t is specified by Unix98 and guaranteed to have
IPv6 Internet host addresses have 128 bits and are packaged inside a
structure of type
The following basic definitions for Internet addresses are declared in the header file netinet/in.h:
This data type is used in certain contexts to contain an IPv4 Internet host address. It has just one field, named
s_addr, which records the host address number as an
You can use this constant to stand for “the address of this machine,” instead of finding its actual address. It is the IPv4 Internet address ‘127.0.0.1’, which is usually called ‘localhost’. This special constant saves you the trouble of looking up the address of your own machine. Also, the system usually implements
INADDR_LOOPBACKspecially, avoiding any network traffic for the case of one machine talking to itself.
You can use this constant to stand for “any incoming address” when binding to an address. See Setting Address. This is the usual address to give in the
struct sockaddr_inwhen you want to accept Internet connections.
This constant is the address you use to send a broadcast message.
This data type is used to store an IPv6 address. It stores 128 bits of data, which can be accessed (via a union) in a variety of ways.
This constant is the IPv6 address ‘::1’, the loopback address. See above for a description of what this means. The macro
IN6ADDR_LOOPBACK_INITis provided to allow you to initialize your own variables to this value.