inet(3) Library Functions Manual inet(3) inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, inet_netof - C (libc, -lc) #include #include #include int inet_aton(const char *cp, struct in_addr *inp); in_addr_t inet_addr(const char *cp); in_addr_t inet_network(const char *cp); [[deprecated]] char *inet_ntoa(struct in_addr in); [[deprecated]] struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host); [[deprecated]] in_addr_t inet_lnaof(struct in_addr in); [[deprecated]] in_addr_t inet_netof(struct in_addr in); glibc (. feature_test_macros(7)): inet_aton(), inet_ntoa(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _BSD_SOURCE || _BSD_SOURCE inet_aton() - cp IPv4 (IPv4 numbers-and-dots) ( ) , inp. inet_aton() , , , . , cp, : a.b.c.d ; . a.b.c a b . c 16- , . c () B. a.b a . b 24- , . () A. a a 32- , . , ( 0) ( 0X) . , , IPv4 . , , - IPv4 (IPv4 dotted-decimal notation) IPv4 dotted-quad notation. inet_aton() 1, , 0, ( errno ). inet_addr() - cp IPv4 . , , , INADDR_NONE ( -1). , .. -1 (255.255.255.255). , inet_aton(), inet_pton(3) getaddrinfo(3), . inet_network() cp, IPv4 , ( ), . . , -1. inet_ntoa() - in, , IPv4 . , . inet_lnaof() - in. . inet_netof() - in. . inet_makeaddr() inet_netof() inet_lnaof(). - , net host ( ). The structure in_addr as used in inet_ntoa(), inet_makeaddr(), inet_lnaof(), and inet_netof() is defined in as: typedef uint32_t in_addr_t; struct in_addr { in_addr_t s_addr; }; attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |inet_aton(), inet_addr(), | | MT-Safe locale | |inet_network(), inet_ntoa() | | | +----------------------------+----------------------------------------------------------+--------------------------+ |inet_makeaddr(), | | MT-Safe | |inet_lnaof(), inet_netof() | | | +----------------------------+----------------------------------------------------------+--------------------------+ inet_addr() inet_ntoa() POSIX.1-2008. inet_aton() . inet_addr() inet_ntoa() POSIX.1-2001, 4.3BSD. inet_lnaof(), inet_netof() inet_makeaddr() , , . IPv4 : A 0 ( ) . , . B 10 ( ) . , . C 110 ( ) . , . (CIDR), ( ). x86 , (little endian = ), , , (big endian = ). inet_aton() inet_ntoa(). : $ ./a.out 226.000.000.037 # 226.0.0.31 $ ./a.out 0x7f.1 # 127.0.0.1 #define _DEFAULT_SOURCE #include #include #include int main(int argc, char *argv[]) { struct in_addr addr; if (argc != 2) { fprintf(stderr, "%s \n", argv[0]); exit(EXIT_FAILURE); } if (inet_aton(argv[1], &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } printf("%s\n", inet_ntoa(addr)); exit(EXIT_SUCCESS); } byteorder(3), getaddrinfo(3), gethostbyname(3), getnameinfo(3), getnetent(3), inet_net_pton(3), inet_ntop(3), inet_pton(3), hosts(5), networks(5) () Azamat Hackimov , Dmitriy S. Seregin , Yuri Kozlov , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 15 2024 . inet(3)