1NE_IADDR_MAKE(3)              neon API reference              NE_IADDR_MAKE(3)
2
3
4

NAME

6       ne_iaddr_make, ne_iaddr_cmp, ne_iaddr_print, ne_iaddr_typeof,
7       ne_iaddr_parse, ne_iaddr_raw, ne_iaddr_reverse, ne_iaddr_free -
8       functions to manipulate network addresses
9

SYNOPSIS

11       #include <ne_socket.h>
12
13       typedef enum {
14           ne_iaddr_ipv4 = 0,
15           ne_iaddr_ipv6
16       } ne_iaddr_type;
17
18       ne_inet_addr *ne_iaddr_make(ne_iaddr_type type,
19                                   const unsigned char *raw);
20
21       int ne_iaddr_cmp(const ne_inet_addr *ia1, const ne_inet_addr *ia2);
22
23       char *ne_iaddr_print(const ne_inet_addr *ia, char *buffer,
24                            size_t bufsiz);
25
26       ne_iaddr_type ne_iaddr_typeof(const ne_inet_addr *ia);
27
28       ne_inet_addr *ne_iaddr_parse(const char *address, ne_iaddr_type type);
29
30       unsigned char *ne_iaddr_raw(const ne_inet_addr *ia,
31                                   unsigned char *buffer);
32
33       int ne_iaddr_reverse(const ne_inet_addr *ia, char *buffer,
34                            size_t buflen);
35
36       void ne_iaddr_free(const ne_inet_addr *ia);
37

DESCRIPTION

39       ne_iaddr_make creates an ne_inet_addr object from a raw binary network
40       address; for instance the four bytes 0x7f 0x00 0x00 0x01 represent the
41       IPv4 address 127.0.0.1. The object returned is suitable for passing to
42       ne_sock_connect. A binary IPv4 address contains four bytes; a binary
43       IPv6 address contains sixteen bytes; addresses passed must be in
44       network byte order.
45
46       ne_iaddr_cmp compares two network address objects; returning zero only
47       if they are identical. The objects need not have the same address type;
48       if the addresses are not of the same type, the return value is
49       guaranteed to be non-zero.
50
51       ne_iaddr_print prints a human-readable string representation of a
52       network address into a buffer, for instance the string "127.0.0.1".
53
54       ne_iaddr_typeof returns the type of the given network address object.
55
56       ne_iaddr_parse parses a string representation of a network address
57       (such as "127.0.0.1" and creates a network address object to represent
58       the parsed address.
59
60       ne_iaddr_raw writes the raw byte representation of a network address to
61       the provided buffer. The bytes are written in network byte order; the
62       buffer must be of suitable length for the type of address (4 bytes for
63       an IPv4 address, 16 bytes for an IPv6 address).
64
65       ne_iaddr_reverse performs a reverse name lookup on the address object,
66       writing the (first) hostname associated with the IP address to the
67       provided buffer. If the hostname is longer than the buffer it will be
68       silently truncated; on success the string written to the buffer is
69       always NUL-terminated.
70
71       ne_iaddr_free releases the memory associated with a network address
72       object.
73

RETURN VALUE

75       ne_iaddr_make returns NULL if the address type passed is not supported
76       (for instance on a platform which does not support IPv6).
77
78       ne_iaddr_print returns the buffer pointer, and never NULL.
79
80       ne_iaddr_parse returns a network address object on success, or NULL on
81       failure to parse the address parameter.
82
83       ne_iaddr_reverse returns zero on success or non-zero if no hostname is
84       associated with the address.
85
86       ne_iaddr_raw returns the buffer parameter, and never NULL.
87

EXAMPLES

89       The following example connects a socket to port 80 at the address
90       127.0.0.1.
91
92           unsigned char addr[] = "\0x7f\0x00\0x00\0x01";
93           ne_inet_addr *ia;
94
95           ia = ne_iaddr_make(ne_iaddr_ipv4, addr);
96           if (ia != NULL) {
97               ne_socket *sock = ne_sock_connect(ia, 80);
98               ne_iaddr_free(ia);
99               /* ... */
100           } else {
101               /* ... */
102           }
103

SEE ALSO

105       ne_addr_resolve
106

AUTHOR

108       Joe Orton
109           Author.
110
112neon 0.32.5                     21 January 2023               NE_IADDR_MAKE(3)
Impressum