plibsys 0.0.5
|
Socket address wrapper. More...
Go to the source code of this file.
Typedefs | |
typedef enum PSocketFamily_ | PSocketFamily |
Socket address family. | |
typedef struct PSocketAddress_ | PSocketAddress |
Socket address opaque structure. | |
Enumerations | |
enum | PSocketFamily_ { P_SOCKET_FAMILY_UNKNOWN = 0 , P_SOCKET_FAMILY_INET = AF_INET , P_SOCKET_FAMILY_INET6 = -1 } |
Socket address family. More... | |
Functions | |
P_LIB_API PSocketAddress * | p_socket_address_new_from_native (pconstpointer native, psize len) |
Creates new PSocketAddress from the native socket address raw data. | |
P_LIB_API PSocketAddress * | p_socket_address_new (const pchar *address, puint16 port) |
Creates new PSocketAddress. | |
P_LIB_API PSocketAddress * | p_socket_address_new_any (PSocketFamily family, puint16 port) |
Creates new PSocketAddress for the any-address representation. | |
P_LIB_API PSocketAddress * | p_socket_address_new_loopback (PSocketFamily family, puint16 port) |
Creates new PSocketAddress for the loopback interface. | |
P_LIB_API pboolean | p_socket_address_to_native (const PSocketAddress *addr, ppointer dest, psize destlen) |
Converts PSocketAddress to the native socket address raw data. | |
P_LIB_API psize | p_socket_address_get_native_size (const PSocketAddress *addr) |
Gets the size of the native socket address raw data, in bytes. | |
P_LIB_API PSocketFamily | p_socket_address_get_family (const PSocketAddress *addr) |
Gets a family of a socket address. | |
P_LIB_API pchar * | p_socket_address_get_address (const PSocketAddress *addr) |
Gets a socket address in a string representation, i.e. | |
P_LIB_API puint16 | p_socket_address_get_port (const PSocketAddress *addr) |
Gets a port number of a socket address. | |
P_LIB_API puint32 | p_socket_address_get_flow_info (const PSocketAddress *addr) |
Gets IPv6 traffic class and flow information. | |
P_LIB_API puint32 | p_socket_address_get_scope_id (const PSocketAddress *addr) |
Gets an IPv6 set of interfaces for a scope. | |
P_LIB_API void | p_socket_address_set_flow_info (PSocketAddress *addr, puint32 flowinfo) |
Sets IPv6 traffic class and flow information. | |
P_LIB_API void | p_socket_address_set_scope_id (PSocketAddress *addr, puint32 scope_id) |
Sets an IPv6 set of interfaces for a scope. | |
P_LIB_API pboolean | p_socket_address_is_flow_info_supported (void) |
Checks whether flow information is supported in IPv6. | |
P_LIB_API pboolean | p_socket_address_is_scope_id_supported (void) |
Checks whether a set of interfaces for a scope is supported in IPv6. | |
P_LIB_API pboolean | p_socket_address_is_ipv6_supported (void) |
Checks whether IPv6 protocol is supported. | |
P_LIB_API pboolean | p_socket_address_is_any (const PSocketAddress *addr) |
Checks whether a given socket address is an any-address representation. | |
P_LIB_API pboolean | p_socket_address_is_loopback (const PSocketAddress *addr) |
Checks whether a given socket address is for the loopback interface. | |
P_LIB_API void | p_socket_address_free (PSocketAddress *addr) |
Frees a socket address structure and its resources. | |
Socket address wrapper.
A socket address is usually represented by a network address (IPv4 or IPv6) and a port number (though some other naming schemes and parameters are possible).
Socket address parameters are stored inside a special system (native) structure in the binary (raw) form. The native structure varies with an operating system and a network protocol. PSocketAddress acts like a thin wrapper around that native address structure and unifies manipulation of socket address data.
PSocketAddress supports IPv4 and IPv6 addresses which consist of an IP address and a port number. IPv6 support is system dependent and not provided for all the platforms. Sometimes you may also need to enable IPv6 support in the system to make it working.
Convenient methods to create special addresses are provided: for the loopback interface use p_socket_address_new_loopback(), for the any-address interface use p_socket_address_new_any().
If you want to get the underlying native address structure for further usage in system calls use p_socket_address_to_native(), and p_socket_address_new_from_native() for a vice versa conversion.
Definition in file psocketaddress.h.
typedef struct PSocketAddress_ PSocketAddress |
Socket address opaque structure.
Definition at line 85 of file psocketaddress.h.
enum PSocketFamily_ |
Socket address family.
Enumerator | |
---|---|
P_SOCKET_FAMILY_UNKNOWN | Unknown family. |
P_SOCKET_FAMILY_INET | IPv4 family.
|
P_SOCKET_FAMILY_INET6 | No IPv6 family. |
Definition at line 74 of file psocketaddress.h.
P_LIB_API void p_socket_address_free | ( | PSocketAddress * | addr | ) |
Frees a socket address structure and its resources.
addr | PSocketAddress to free. |
P_LIB_API pchar * p_socket_address_get_address | ( | const PSocketAddress * | addr | ) |
Gets a socket address in a string representation, i.e.
"172.146.45.5".
addr | PSocketAddress to get address string for. |
P_LIB_API PSocketFamily p_socket_address_get_family | ( | const PSocketAddress * | addr | ) |
Gets a family of a socket address.
addr | PSocketAddress to get the family for. |
P_LIB_API puint32 p_socket_address_get_flow_info | ( | const PSocketAddress * | addr | ) |
Gets IPv6 traffic class and flow information.
addr | PSocketAddress to get flow information for. |
P_LIB_API psize p_socket_address_get_native_size | ( | const PSocketAddress * | addr | ) |
Gets the size of the native socket address raw data, in bytes.
addr | PSocketAddress to get the size of native address raw data for. |
P_LIB_API puint16 p_socket_address_get_port | ( | const PSocketAddress * | addr | ) |
Gets a port number of a socket address.
addr | PSocketAddress to get the port number for. |
P_LIB_API puint32 p_socket_address_get_scope_id | ( | const PSocketAddress * | addr | ) |
Gets an IPv6 set of interfaces for a scope.
addr | PSocketAddress to get the set of interfaces for. |
P_LIB_API pboolean p_socket_address_is_any | ( | const PSocketAddress * | addr | ) |
Checks whether a given socket address is an any-address representation.
Such an address is a 0.0.0.0.
addr | PSocketAddress to check. |
Checks whether flow information is supported in IPv6.
Checks whether IPv6 protocol is supported.
P_LIB_API pboolean p_socket_address_is_loopback | ( | const PSocketAddress * | addr | ) |
Checks whether a given socket address is for the loopback interface.
Such an address is a 127.x.x.x.
addr | PSocketAddress to check. |
Checks whether a set of interfaces for a scope is supported in IPv6.
P_LIB_API PSocketAddress * p_socket_address_new | ( | const pchar * | address, |
puint16 | port ) |
Creates new PSocketAddress.
address | String representation of an address (i.e. "172.146.45.5"). |
port | Port number. |
If the address is an IPv6 address, it can also contain a scope index separated from the address by the '' literal). Most target platforms should correctly parse such an address though some old operating systems may fail in case of lack of the getaddrinfo() call.
P_LIB_API PSocketAddress * p_socket_address_new_any | ( | PSocketFamily | family, |
puint16 | port ) |
Creates new PSocketAddress for the any-address representation.
family | Socket family. |
port | Port number. |
P_LIB_API PSocketAddress * p_socket_address_new_from_native | ( | pconstpointer | native, |
psize | len ) |
Creates new PSocketAddress from the native socket address raw data.
native | Pointer to the native socket address raw data. |
len | Raw data length, in bytes. |
P_LIB_API PSocketAddress * p_socket_address_new_loopback | ( | PSocketFamily | family, |
puint16 | port ) |
Creates new PSocketAddress for the loopback interface.
family | Socket family. |
port | Port number. |
P_LIB_API void p_socket_address_set_flow_info | ( | PSocketAddress * | addr, |
puint32 | flowinfo ) |
Sets IPv6 traffic class and flow information.
addr | PSocketAddress to set flow information for. |
flowinfo | Flow information to set. |
P_LIB_API void p_socket_address_set_scope_id | ( | PSocketAddress * | addr, |
puint32 | scope_id ) |
Sets an IPv6 set of interfaces for a scope.
addr | PSocketAddress to set the set of interfaces for. |
scope_id | Index that identifies the set of interfaces for a scope. |
P_LIB_API pboolean p_socket_address_to_native | ( | const PSocketAddress * | addr, |
ppointer | dest, | ||
psize | destlen ) |
Converts PSocketAddress to the native socket address raw data.
addr | PSocketAddress to convert. | |
[out] | dest | Output buffer for raw data. |
destlen | Length in bytes of the dest buffer. |