Home > Article > Operation and Maintenance > What is linux inet addr
linux inet addr is a function. The function of inet_addr() is to convert a dotted decimal IP into a long integer; the syntax is such as "in addr t inet addr(const char *cp)", This function interprets the string in the cp parameter, which represents a numeric Internet address using the Internet's "." separated format.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is linux inet addr?
The function of inet_addr() is to convert a dotted decimal IP into a long integer (u_long type)
inet addr function
The inet addr function converts the network host address (such as 192.168.1.10) into a network byte order binary value. If the parameter char*cp is invalid, the function returns - 1 (NADDR NONE), this function also returns when processing the address 255.255.255.255 - 1,255.255.255.255 is a valid address, but inet addr cannot handle
in addr t inet addr(const char *cp)
This function interprets the string in the cp parameter, This string represents a numeric Internet address using the Internet's "." separated format. The return value can be used as an Internet address. All Internet addresses are returned in network byte order (bytes are arranged from left to right).
Internet addresses separated by "." can be expressed in the following ways:
a.b.c.d,a.b.c,a.b,a
When the four parts have fixed values, each is interpreted as one byte of data. The Internet four-byte address is composed from left to right. Please note that when an Internet address is represented as a 32-bit integer on an Intel machine, the above bytes are "d.c.b.a". This is because bytes in Intel processors are arranged from right to left.
Please note: Only Berkeley supports the following expressions, and is not supported anywhere else on the Internet. Taking into account compatibility with the software, it should be used as specified.
For a three-part address, the last part is interpreted as 16-bit data and used as the rightmost two bytes of the network address. In this way, a three-part address can easily represent a Group B network address, such as "128.net.host".
For a two-part address, the last part is interpreted as 24-bit data and serves as the rightmost three parts of the network address. bytes, so that the two-part address can easily represent a Group C network address, such as "net.host".
For an address with only one part, its value is directly stored in the network address without any byte reorganization.
Return value:
If no error occurs, inet_addr() returns an unsigned long integer, which stores the Internet address in appropriate byte order. If the incoming string is not a legal Internet address, such as any item in the "a.b.c.d" address exceeds 255, then inet_addr() returns INADDR_NONE. When there is only one part of the IP (that is, when there is no "."), if the IP string consists only of numbers, inet_addr() does not check whether the number is greater than 255.
Recommended learning: "linux video tutorial"
The above is the detailed content of What is linux inet addr. For more information, please follow other related articles on the PHP Chinese website!