#include <sys.socket.h>
#include <netinet.in.h>
#include <arpa.inet.h>
Kernighan-Ritchie-C:
unsigned long inet_addr(cp);
char *cp;
int inet_lnaof(in);
struct in_addr in;
struct in_addr inet_makeaddr(net, lna);
int net;
int lna;
int inet_netof(in);
struct in_addr in;
unsigned long inet_network(cp);
char *cp;
char *inet_ntoa(in);
struct in_addr in;
ANSI-C:
unsigned long inet_addr(char* cp);
int inet_lnaof(struct in_addr in);
struct in_addr inet_makeaddr(int net, int lna);
int inet_netof(struct in_addr in);
unsigned long inet_network(char* cp);
char* inet_ntoa(struct in_addr in);
Description
Use of the inet_addr(), inet_lnaof(), inet_makeaddr(), inet_netof() inet_network() and inet_ntoa() functions only makes sense in the AF_INET address family.
The inet_addr() function converts the character string to which the cp parameter points from the normal Internet dotted notation to an integer value which can then be used as the Internet address.
The inet_lnaof() function extracts the local network address in the byte order of the host from the Internet host address passed in the in parameter.
The inet_makeaddr() function creates an Internet address from the following
the subnetwork section of the Internet address specified in the net parameter and
the subnetwork local address section specified in the lna parameter.
The subnetwork section of the Internet address and subnetwork local address section are both passed in the byte order of the host.
The inet_netof() function extracts the network number in the byte order of the host from the Internet host address passed in the in parameter.
The inet_network() function converts the character string to which pointer cp points from the normal Internet dotted notation to an integer value which can then be used as the subnetwork section of the Internet address.
The inet_ntoa() function converts the Internet host address passed in the in parameter into a character string in the normal Internet dotted notation.
All Internet addresses are returned in network byte order in which the bytes are arranged from left to right.
Values can be specified in the following dotted notation formats:
a.b.c.d
If a four-part address is specified, each part is interpreted as one data byte and assigned from left to right to the four bytes of an Internet address.a.b.c
If a three-part address is specified, the last part is interpreted as a 16-bit sequence and transferred to the two right bytes of the Internet address. This allows three-part address formats to be used without problems for specifying class B addresses
(e.g. 128.net.host).a.b
If a two-part address is specified, the last part is interpreted as a 24-bit sequence and transferred to the right three bytes of an Internet address. This allows two-part address formats to be used without problems for specifying class A addresses (e.g. net.host).a
If a single-part address is specified, the value is transferred without changing the byte order directly to the network address.
The numbers specified as address parts in dotted notation may be either decimal, octal or hexadecimal numbers:
Numbers not prefixed with either 0, 0x or 0X are interpreted as decimal numbers.
Numbers prefixed with 0 are interpreted as octal numbers.
Numbers prefixed with 0x or 0X are interpreted as hexadecimal numbers.
Return value
After successful execution, inet_addr() returns the Internet address.
Otherwise, -1 is returned.After successful execution, inet_network() returns the subnetwork portion of the Internet address. Otherwise, -1 is returned.
The inet_makeaddr() function returns the created Internet address.
The inet_lnaof() returns the local network address.
The inet_netof() function returns the network number.
The inet_ntoa() returns a pointer to the network address in the normal Internet dotted notation.
Errors indicated by errno
No errors are defined.
Note
The return value of inet_ntoa() points to static data that may be overwritten by subsequent inet_ntoa() calls. This information must therefore be copied if it needs to be saved.