Internetprotocol-Address | |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Internetprotocol-Address. |
C-kern/ | Linux specific implementation Internetprotocol-Address Linux. |
Types | |
struct ipport_t | Export ipport_t into global namespace. |
struct ipaddr_t | Export ipaddr_t. |
struct ipaddr_list_t | Export ipaddr_list_t. |
struct ipaddr_storage_t | Export ipaddr_storage_t to allow static allocation of an ipaddr_t. |
Enumerations | |
ipversion_e | Selects the version of the ip address. |
ipprotocol_e | Currently supported internet protocols. |
Functions | |
test | |
unittest_io_ipaddr | Unittest for resolving dns names into ip addresses. |
ipport_t | The UDP or TCP port number. |
lifetime | |
ipport_ANY | System chooses free port number for you. |
initnamed_ipport | Returns the tcp and udp port numbers of a named IP service. |
ipaddr_t | Stores description of an internet protocol address. |
protocol | Indicates a specific internet protocol. |
addrlen | Length of internal address representation addr. |
addr | Opaque representation of internet address (IPv4 or IPv6). |
lifetime | |
new_ipaddr | Create a new internet address and init it with the given values. |
newdnsquery_ipaddr | Resolves a hostname into its first queried ip address. |
newaddr_ipaddr | Create a new internet address and init it a system specific socket address value. |
newany_ipaddr | Create a new internet address suitable to listen on any network interface. |
newloopback_ipaddr | Returns an ip address suitable for host only inter process communications. |
newcopy_ipaddr | Copy an internet address to store it for later usage. |
delete_ipaddr | Deletes a created or copied address. |
query | |
compare_ipaddr | Returns result of comparison (0 == equal). |
isvalid_ipaddr | Checks that internal fields are ok. |
port_ipaddr | Returns the port number of the address. |
protocol_ipaddr | Returns the specified protocol for this ip address. |
version_ipaddr | Returns the supported version of the address. |
dnsname_ipaddr | Tries a reverse mapping from a binary ip address into its dns name representation. |
dnsnameace_ipaddr | Tries a reverse mapping from a binary ip address into its dns name representation. |
numericname_ipaddr | Returns the numeric ascii representation of the ip address. |
log | |
logurl_ipaddr | Writes “varname: [tcp|udp]://[ip]:[port]” to logchannel. |
change | |
copy_ipaddr | Copies the ip number, protocol and port from source to dest. |
setprotocol_ipaddr | Changes ip address’ protocol value. |
setport_ipaddr | Changes ip address’ port value. |
setaddr_ipaddr | Sets the ip number, protocol and port. |
ipaddr_storage_t | Holds enough memory for every possible version of ipaddr_t. |
protocol | Same as ipaddr_t.protocol. |
addrlen | Same as ipaddr_t.addrlen. |
addr | Same as ipaddr_t.addr. |
storage | Additional space used by socket addr version with maximum size. |
lifetime | |
initany_ipaddrstorage | Inits ipaddr_storage_t as an ip addr of type ipaddr_t with given ipversion_e. |
ipaddr_list_t | Stores list of ipaddr_t. |
lifetime | |
newdnsquery_ipaddrlist | Resolves a host name into a list of internet addresses. |
delete_ipaddrlist | Frees memory of internal list of ipaddr_list_t. |
read | |
gofirst_ipaddrlist | Resets iterator to first ipaddr_t of internal list of addresses. |
next_ipaddrlist | Returns next ipaddr_t from of internal list. |
inline implementation |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file of Internetprotocol-Address.
Linux specific implementation Internetprotocol-Address Linux.
Export ipport_t into global namespace.
typedef struct ipaddr_t ipaddr_t
Export ipaddr_t.
typedef struct ipaddr_list_t ipaddr_list_t
Export ipaddr_list_t.
typedef struct ipaddr_storage_t ipaddr_storage_t
Export ipaddr_storage_t to allow static allocation of an ipaddr_t.
Selects the version of the ip address.
Currently supported internet protocols.
test | |
unittest_io_ipaddr | Unittest for resolving dns names into ip addresses. |
The UDP or TCP port number. Declares ipport_t as unsigned 16 bit. The port is an id which identifies a running process on a host. To communicate to a process on a remote system you need the IP address of that system, its port and the protocol (UDP or TCP).
Every application on a host must have a unique port number in the protocol domain to be unambiguously identifiable by the system network layer. If you do not know the correct port number but the service name use initnamed_ipport first to determine it.
lifetime | |
ipport_ANY | System chooses free port number for you. |
initnamed_ipport | Returns the tcp and udp port numbers of a named IP service. |
#define ipport_ANY 0
System chooses free port number for you. If you assign ipport_ANY to your own port number the system chooses the next free port number > 0 for you if you create an ipsocket_t.
int initnamed_ipport( /*out*/ipport_t * port, const char * servicename, ipprotocol_e protocol )
Returns the tcp and udp port numbers of a named IP service. A returned value of 0 in tcp_port or udp_port means this kind of protocol is not supported by the service. You can set tcp_port or udp_port to NULL if you want to query only for one protocol.
ENOENT | Service name does not exist. |
EPROTONOSUPPORT | UDP or TCP protocol is not supported by service. |
struct ipaddr_t
Stores description of an internet protocol address. This object supports handling of IPv4 and IPv6 addresses.
version | Stores the protocol version; see ipversion_e. |
protocol | Stores the protocol; see ipprotocol_e. |
port | Stores the 16 bit port number. |
internet addr. | IPv4 (32 bit) or IPv6 (128 bit) number |
protocol | Indicates a specific internet protocol. |
addrlen | Length of internal address representation addr. |
addr | Opaque representation of internet address (IPv4 or IPv6). |
lifetime | |
new_ipaddr | Create a new internet address and init it with the given values. |
newdnsquery_ipaddr | Resolves a hostname into its first queried ip address. |
newaddr_ipaddr | Create a new internet address and init it a system specific socket address value. |
newany_ipaddr | Create a new internet address suitable to listen on any network interface. |
newloopback_ipaddr | Returns an ip address suitable for host only inter process communications. |
newcopy_ipaddr | Copy an internet address to store it for later usage. |
delete_ipaddr | Deletes a created or copied address. |
query | |
compare_ipaddr | Returns result of comparison (0 == equal). |
isvalid_ipaddr | Checks that internal fields are ok. |
port_ipaddr | Returns the port number of the address. |
protocol_ipaddr | Returns the specified protocol for this ip address. |
version_ipaddr | Returns the supported version of the address. |
dnsname_ipaddr | Tries a reverse mapping from a binary ip address into its dns name representation. |
dnsnameace_ipaddr | Tries a reverse mapping from a binary ip address into its dns name representation. |
numericname_ipaddr | Returns the numeric ascii representation of the ip address. |
log | |
logurl_ipaddr | Writes “varname: [tcp|udp]://[ip]:[port]” to logchannel. |
change | |
copy_ipaddr | Copies the ip number, protocol and port from source to dest. |
setprotocol_ipaddr | Changes ip address’ protocol value. |
setport_ipaddr | Changes ip address’ port value. |
setaddr_ipaddr | Sets the ip number, protocol and port. |
uint16_t protocol
Indicates a specific internet protocol. See ipprotocol_e for a list of possible values.
uint16_t addrlen
Length of internal address representation addr.
sys_socketaddr_t addr[]
Opaque representation of internet address (IPv4 or IPv6). The size in bytes is stored in addrlen.
int new_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, const char * numeric_addr, ipport_t port, ipversion_e version )
Create a new internet address and init it with the given values. If you do not longer need it do not forget to free it with delete_ipaddr.
protocol | Either ipprotocol_UDP or ipprotocol_TCP. |
numeric_addr | The numeric representation of the internet address ( “200.123.56.78” or “::1” ...) |
port | A port which identifies this process between all processes on this network node. If set to <ipport_ANY> (== 0) a free port is randomly chosen by the system during socket creation. |
version | IP version: Either ipversion_4 or ipversion_6. |
int newaddr_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, uint16_t sock_addr_len, const sys_socketaddr_t * sock_addr )
Create a new internet address and init it a system specific socket address value. Same as new_ipaddr except that port, numeric_address and version are represented by system specific type sys_socketaddr_t. If you do not longer need it do not forget to free it with delete_ipaddr.
int newany_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Create a new internet address suitable to listen on any network interface. Same as new_ipaddr except that numeric_addr is set to “0.0.0.0” or “::” depending on the protocol version. If you do not longer need it do not forget to free it with delete_ipaddr.
int newloopback_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Returns an ip address suitable for host only inter process communications. The loopback address allows to send messages between processes on the same local system (host). Connection to remote network nodes are not supported. Same as new_ipaddr except that numeric_addr is set to the loopback address “127.0.0.1” for IPv4 or “::1” for IPv6.
int newcopy_ipaddr( /*out*/ipaddr_t ** dest, const ipaddr_t * source )
Copy an internet address to store it for later usage. If you do no longer need it do not forget to free it with delete_ipaddr.
int delete_ipaddr( ipaddr_t ** addr )
Deletes a created or copied address. Never free an address returned by ipaddr_list_t.
ipprotocol_e protocol_ipaddr( const ipaddr_t * addr )
Returns the specified protocol for this ip address. See also ipprotocol_e.
ipprotocol_TCP | Connection oriented protocol |
ipprotocol_UDP | Connectionless protocol |
int dnsname_ipaddr( const ipaddr_t * addr, cstring_t * dns_name )
Tries a reverse mapping from a binary ip address into its dns name representation. The returned name is converted into the current character encoding in case the returned name is an ACE encoded IDN (internat. domain name). ACE stands for ASCII Compatible Encoding and is used to represent an IDN which contains unicode characters.
The name is returned in dns_name. This string must in a initialized state. Previous content is overwritten.
int dnsnameace_ipaddr( const ipaddr_t * addr, cstring_t * dns_name )
Tries a reverse mapping from a binary ip address into its dns name representation. Same as dnsname_ipaddr except that IDN represented in ACE are left untouched (not converted into unicode). The name is returned in dns_name. This string must in a initialized state. Previous content is overwritten.
int numericname_ipaddr( const ipaddr_t * addr, cstring_t * numeric_name )
Returns the numeric ascii representation of the ip address. The returned names are composed of four decimal numbers for IPv4, i.e. ‘192.168.20.10’, or 8 16bit hexadecimal numbers separated by ‘:’ for IPv6, i.e. ‘2010:0dcc:3543:0000:0000:4e9f:0370:2668’. The name is returned in numeric_name. This string must in a initialized state. Previous content is overwritten.
void logurl_ipaddr( const ipaddr_t * addr, const char * varname, uint8_t logchannel )
Writes “varname: [tcp|udp]://[ip]:[port]” to logchannel. Parameter logchannel is of type log_channel_e.
int setprotocol_ipaddr( ipaddr_t * addr, ipprotocol_e protocol )
Changes ip address’ protocol value. Returns 0 in case of success else EINVAL if protocol is not a value from ipprotocol_e.
struct ipaddr_storage_t
Holds enough memory for every possible version of ipaddr_t. Use function initany_ipaddrstorage to cast this object into an ipaddr_t with the correct ipversion_e.
protocol | Same as ipaddr_t.protocol. |
addrlen | Same as ipaddr_t.addrlen. |
addr | Same as ipaddr_t.addr. |
storage | Additional space used by socket addr version with maximum size. |
lifetime | |
initany_ipaddrstorage | Inits ipaddr_storage_t as an ip addr of type ipaddr_t with given ipversion_e. |
uint16_t protocol
Same as ipaddr_t.protocol.
uint16_t addrlen
Same as ipaddr_t.addrlen.
sys_socketaddr_t addr[1]
Same as ipaddr_t.addr.
ipaddr_t * initany_ipaddrstorage( ipaddr_storage_t * addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Inits ipaddr_storage_t as an ip addr of type ipaddr_t with given ipversion_e. In case any parameter is invalid the value NULL is returned. The returned address is the same as a call to newany_ipaddr.
Never delete the returned ipaddr_t pointer. It points to the given addr (ipaddr_storage_t) and is only valid as long as addr is not changed or deleted.
struct ipaddr_list_t
Stores list of ipaddr_t. Allows to iterate over every entry.
lifetime | |
newdnsquery_ipaddrlist | Resolves a host name into a list of internet addresses. |
delete_ipaddrlist | Frees memory of internal list of ipaddr_list_t. |
read | |
gofirst_ipaddrlist | Resets iterator to first ipaddr_t of internal list of addresses. |
next_ipaddrlist | Returns next ipaddr_t from of internal list. |
int newdnsquery_ipaddrlist( /*out*/ipaddr_list_t ** addrlist, const char * hostname_or_numeric, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Resolves a host name into a list of internet addresses.
EADDRNOTAVAIL | IP version for numeric name not supported (name == “127.0.0.1” && version == ipversion_6) |
EAFNOSUPPORT | Value in version is not supported. |
EPROTONOSUPPORT | Value in protocol is not supported. |
ENOENT | The dns name is not known. |
ENODATA | No data received (timeout) or the specified network host exists, but does not have any network addresses defined. |
int delete_ipaddrlist( ipaddr_list_t ** addrlist )
Frees memory of internal list of ipaddr_list_t. Calling it more than once is safe.
void gofirst_ipaddrlist( ipaddr_list_t * addrlist )
Resets iterator to first ipaddr_t of internal list of addresses. After calling this function the next call to next_ipaddrlist returns the first address in the buffer.
const ipaddr_t * next_ipaddrlist( ipaddr_list_t * addrlist )
Returns next ipaddr_t from of internal list. Only valid until next call to next_ipaddrlist or delete_ipaddrlist.
Export ipaddr_t.
typedef struct ipaddr_t ipaddr_t
Stores description of an internet protocol address.
struct ipaddr_t
Export ipaddr_list_t.
typedef struct ipaddr_list_t ipaddr_list_t
Stores list of ipaddr_t.
struct ipaddr_list_t
Export ipaddr_storage_t to allow static allocation of an ipaddr_t.
typedef struct ipaddr_storage_t ipaddr_storage_t
Holds enough memory for every possible version of ipaddr_t.
struct ipaddr_storage_t
Unittest for resolving dns names into ip addresses.
int unittest_io_ipaddr( void )
System chooses free port number for you.
#define ipport_ANY 0
Returns the tcp and udp port numbers of a named IP service.
int initnamed_ipport( /*out*/ipport_t * port, const char * servicename, ipprotocol_e protocol )
Indicates a specific internet protocol.
uint16_t protocol
Length of internal address representation addr.
uint16_t addrlen
Opaque representation of internet address (IPv4 or IPv6).
sys_socketaddr_t addr[]
Create a new internet address and init it with the given values.
int new_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, const char * numeric_addr, ipport_t port, ipversion_e version )
Resolves a hostname into its first queried ip address.
int newdnsquery_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, const char * hostname, ipport_t port, ipversion_e version )
Create a new internet address and init it a system specific socket address value.
int newaddr_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, uint16_t sock_addr_len, const sys_socketaddr_t * sock_addr )
Create a new internet address suitable to listen on any network interface.
int newany_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Returns an ip address suitable for host only inter process communications.
int newloopback_ipaddr( /*out*/ipaddr_t ** addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Copy an internet address to store it for later usage.
int newcopy_ipaddr( /*out*/ipaddr_t ** dest, const ipaddr_t * source )
Deletes a created or copied address.
int delete_ipaddr( ipaddr_t ** addr )
Returns result of comparison (0 == equal).
int compare_ipaddr( const ipaddr_t * left, const ipaddr_t * right )
Checks that internal fields are ok.
bool isvalid_ipaddr( const ipaddr_t * addr )
Returns the port number of the address.
ipport_t port_ipaddr( const ipaddr_t * addr )
Returns the specified protocol for this ip address.
ipprotocol_e protocol_ipaddr( const ipaddr_t * addr )
Returns the supported version of the address.
ipversion_e version_ipaddr( const ipaddr_t * addr )
Tries a reverse mapping from a binary ip address into its dns name representation.
int dnsname_ipaddr( const ipaddr_t * addr, cstring_t * dns_name )
Tries a reverse mapping from a binary ip address into its dns name representation.
int dnsnameace_ipaddr( const ipaddr_t * addr, cstring_t * dns_name )
Returns the numeric ascii representation of the ip address.
int numericname_ipaddr( const ipaddr_t * addr, cstring_t * numeric_name )
Writes “varname: [tcp|udp]://[ip]:[port]” to logchannel.
void logurl_ipaddr( const ipaddr_t * addr, const char * varname, uint8_t logchannel )
Copies the ip number, protocol and port from source to dest.
int copy_ipaddr( ipaddr_t * dest, const ipaddr_t * source )
Changes ip address’ protocol value.
int setprotocol_ipaddr( ipaddr_t * addr, ipprotocol_e protocol )
Changes ip address’ port value.
int setport_ipaddr( ipaddr_t * addr, ipport_t port )
Sets the ip number, protocol and port.
int setaddr_ipaddr( ipaddr_t * addr, ipprotocol_e protocol, uint16_t sock_addr_len, const sys_socketaddr_t * sock_addr )
Same as ipaddr_t.protocol.
uint16_t protocol
Same as ipaddr_t.addrlen.
uint16_t addrlen
Same as ipaddr_t.addr.
sys_socketaddr_t addr[1]
Additional space used by socket addr version with maximum size.
uint8_t storage[sys_socketaddr_MAXSIZE - sizeof(sys_socketaddr_t)]
Inits ipaddr_storage_t as an ip addr of type ipaddr_t with given ipversion_e.
ipaddr_t * initany_ipaddrstorage( ipaddr_storage_t * addr, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Resolves a host name into a list of internet addresses.
int newdnsquery_ipaddrlist( /*out*/ipaddr_list_t ** addrlist, const char * hostname_or_numeric, ipprotocol_e protocol, ipport_t port, ipversion_e version )
Frees memory of internal list of ipaddr_list_t.
int delete_ipaddrlist( ipaddr_list_t ** addrlist )
Resets iterator to first ipaddr_t of internal list of addresses.
void gofirst_ipaddrlist( ipaddr_list_t * addrlist )
Returns next ipaddr_t from of internal list.
const ipaddr_t * next_ipaddrlist( ipaddr_list_t * addrlist )
Defines ipsocket_t as alias for sys_iochannel_t.
typedef sys_iochannel_t ipsocket_t