Next: , Previous: , Up: Embedding API   [Contents][Index]

5.2.4 svz_address_t

A network address comprises a family, such as AF_INET (also known as IPv4), and its bits in network byte order, such as the bytes 127, 0, 0 and 1 (also known as the IPv4 loopback address). Many libserveez functions take svz_address_t *.

Please note: Although svz_address_t supports1 IPv6, the rest of libserveez it does not (yet). This means you can freely create and manipulate address objects with the functions described in this section, but any attempt to pass to the rest of libserveez an address with a family other than AF_INET will immediately abort the process. When full IPv6 support is in place, this blurb will be deleted and the list returned by svz_library_features will include an appropriate indicator (see Library features).

Function: svz_address_t * svz_address_make (int family, const void *bits)

Return an address object to hold an address in family, represented by bits. family must be one of:


An IPv4 address; bits is in_addr_t *.


(if supported by your system) An IPv6 address; bits is struct in6_addr *.

The bits are expected in network byte order. If there are problems, return NULL.

Function: int svz_address_family (const svz_address_t *addr)

Return the address family of addr.

Function: int svz_address_to (void *dest, const svz_address_t *addr)

Copy the address bits out of addr to dest. Return 0 on success, -1 if either addr or dest is NULL, or the addr family is AF_UNSPEC.

Function: int svz_address_same (const svz_address_t *a, const svz_address_t *b)

Return 1 if a and b represent the same address (identical family and bits), otherwise 0.

Function: const char * svz_pp_address (char *buf, size_t size, const svz_address_t *addr)

Format an external representation of addr into buf, of size bytes. The format depends on the family of addr. For IPv4, this is numbers-and-dots. For IPv6, it is “the most appropriate IPv6 network address format for addr”, according to the manpage of inet_ntop, the function that actually does the work.

If buf or addr is NULL, or size is not big enough, return NULL. Otherwise, return buf.

Function: const char * svz_pp_addr_port (char *buf, size_t size, const svz_address_t *addr, in_port_t port)

Format an external representation of addr and port (in network byte order) into buf, of size bytes. The address xrep (external representation) is done by svz_pp_address, q.v. The rest of the formatting depends on the addr family.

AF_INET (IPv4)xrep:port
AF_INET6 (IPv6)[xrep]:port

If buf or addr is NULL, or size is not big enough, return NULL. Otherwise, return buf.

Function: svz_address_t * svz_address_copy (const svz_address_t *addr)

Return a copy of addr.

Macro: SVZ_SET_ADDR (place, family, bits)

Expand to a series of commands. First, if place is non-NULL, then svz_free it. Next, assign to place a new address object made by calling svz_address_make with family and bits.

Macro: SVZ_PP_ADDR (buf, addr)

Expand to a call to svz_pp_address, passing it buf and sizeof buf, in addition to addr.

Macro: SVZ_PP_ADDR_PORT (buf, addr, port)

Expand to a call to svz_pp_addr_port, passing it buf and sizeof buf, in addition to addr and port.



that is, if your system supports it

Next: Utility functions, Previous: Data structures, Up: Embedding API   [Contents][Index]