5
4

1 回答 1

5

inet_pton() turns a human-readable IP address into a 4-byte binary string used for network operations, usually involving raw sockets. Those "strange characters" are the ASCII character representations of the numbers 219, 225, 174, and 153 and may or may not have their byte order reversed to reflect the 'endian-ness' of your system.

Every IPv4 address is essentially a 32-bit unsigned integer, and we create an easy-to understand representation of this number by splitting it into 4 separate 8-bit numbers [0 to 255] for what is called "dotted quad" notation.

dotted quad example

I would suggest looking at and/or using ip2long() and long2ip() if you're simply looking for a more efficient storage of IP address data, and not raw network programming.

于 2013-10-07T19:28:49.133 回答