Asterisk - The Open Source Telephony Project
21.4.1
|
Network socket handling. More...
Go to the source code of this file.
Data Structures | |
struct | ast_sockaddr |
Socket address structure. More... | |
Macros | |
#define | AST_SOCKADDR_BUFLEN (45 + 2 + 1 + 5 + 1) |
#define | ast_sockaddr_port(addr) _ast_sockaddr_port(addr, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Get the port number of a socket address. More... | |
#define | ast_sockaddr_set_port(addr, port) _ast_sockaddr_set_port(addr,port,__FILE__,__LINE__,__PRETTY_FUNCTION__) |
Sets the port number of a socket address. More... | |
#define | AST_SOCKADDR_STR_ADDR (1 << 0) |
#define | AST_SOCKADDR_STR_ADDR_REMOTE (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_REMOTE) |
#define | AST_SOCKADDR_STR_BRACKETS (1 << 2) |
#define | AST_SOCKADDR_STR_DEFAULT (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT) |
#define | AST_SOCKADDR_STR_DEFAULT_REMOTE (AST_SOCKADDR_STR_DEFAULT | AST_SOCKADDR_STR_REMOTE) |
#define | AST_SOCKADDR_STR_FORMAT_MASK (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT | AST_SOCKADDR_STR_BRACKETS) |
#define | AST_SOCKADDR_STR_HOST (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_BRACKETS) |
#define | AST_SOCKADDR_STR_HOST_REMOTE (AST_SOCKADDR_STR_HOST | AST_SOCKADDR_STR_REMOTE) |
#define | AST_SOCKADDR_STR_PORT (1 << 1) |
#define | AST_SOCKADDR_STR_REMOTE (1 << 3) |
#define | V6_WORD(sin6, index) ((uint32_t *)&((sin6)->sin6_addr))[(index)] |
Isolate a 32-bit section of an IPv6 address. More... | |
Functions | |
uint16_t | _ast_sockaddr_port (const struct ast_sockaddr *addr, const char *file, int line, const char *func) |
void | _ast_sockaddr_set_port (struct ast_sockaddr *addr, uint16_t port, const char *file, int line, const char *func) |
int | ast_accept (int sockfd, struct ast_sockaddr *addr) |
Wrapper around accept(2) that uses struct ast_sockaddr. More... | |
int | ast_bind (int sockfd, const struct ast_sockaddr *addr) |
Wrapper around bind(2) that uses struct ast_sockaddr. More... | |
int | ast_connect (int sockfd, const struct ast_sockaddr *addr) |
Wrapper around connect(2) that uses struct ast_sockaddr. More... | |
int | ast_getsockname (int sockfd, struct ast_sockaddr *addr) |
Wrapper around getsockname(2) that uses struct ast_sockaddr. More... | |
ssize_t | ast_recvfrom (int sockfd, void *buf, size_t len, int flags, struct ast_sockaddr *src_addr) |
Wrapper around recvfrom(2) that uses struct ast_sockaddr. More... | |
ssize_t | ast_sendto (int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr) |
Wrapper around sendto(2) that uses ast_sockaddr. More... | |
int | ast_set_qos (int sockfd, int tos, int cos, const char *desc) |
Set type of service. More... | |
int | ast_sockaddr_apply_netmask (const struct ast_sockaddr *addr, const struct ast_sockaddr *netmask, struct ast_sockaddr *result) |
Apply a netmask to an address and store the result in a separate structure. More... | |
int | ast_sockaddr_cidr_bits (const struct ast_sockaddr *sa) |
Count the 1 bits in a netmask. More... | |
int | ast_sockaddr_cmp (const struct ast_sockaddr *a, const struct ast_sockaddr *b) |
Compares two ast_sockaddr structures. More... | |
int | ast_sockaddr_cmp_addr (const struct ast_sockaddr *a, const struct ast_sockaddr *b) |
Compares the addresses of two ast_sockaddr structures. More... | |
static void | ast_sockaddr_copy (struct ast_sockaddr *dst, const struct ast_sockaddr *src) |
Copies the data from one ast_sockaddr to another. More... | |
static void | ast_sockaddr_copy_sockaddr (struct ast_sockaddr *dst, struct sockaddr *src, socklen_t len) |
Copies the data from a sockaddr to an ast_sockaddr. More... | |
int | ast_sockaddr_hash (const struct ast_sockaddr *addr) |
Computes a hash value from the address. The port is ignored. More... | |
uint32_t | ast_sockaddr_ipv4 (const struct ast_sockaddr *addr) |
Get an IPv4 address of an ast_sockaddr. More... | |
int | ast_sockaddr_ipv4_mapped (const struct ast_sockaddr *addr, struct ast_sockaddr *ast_mapped) |
Convert an IPv4-mapped IPv6 address into an IPv4 address. More... | |
int | ast_sockaddr_is_any (const struct ast_sockaddr *addr) |
Determine if the address type is unspecified, or "any" address. More... | |
int | ast_sockaddr_is_ipv4 (const struct ast_sockaddr *addr) |
Determine if the address is an IPv4 address. More... | |
int | ast_sockaddr_is_ipv4_mapped (const struct ast_sockaddr *addr) |
Determine if this is an IPv4-mapped IPv6 address. More... | |
int | ast_sockaddr_is_ipv4_multicast (const struct ast_sockaddr *addr) |
Determine if an IPv4 address is a multicast address. More... | |
int | ast_sockaddr_is_ipv6 (const struct ast_sockaddr *addr) |
Determine if this is an IPv6 address. More... | |
int | ast_sockaddr_is_ipv6_link_local (const struct ast_sockaddr *addr) |
Determine if this is a link-local IPv6 address. More... | |
static int | ast_sockaddr_isnull (const struct ast_sockaddr *addr) |
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length. More... | |
int | ast_sockaddr_parse (struct ast_sockaddr *addr, const char *str, int flags) |
Parse an IPv4 or IPv6 address string. More... | |
int | ast_sockaddr_resolve (struct ast_sockaddr **addrs, const char *str, int flags, int family) |
Parses a string with an IPv4 or IPv6 address and place results into an array. More... | |
int | ast_sockaddr_resolve_first_af (struct ast_sockaddr *addr, const char *name, int flag, int family) |
Return the first entry from ast_sockaddr_resolve filtered by address family. More... | |
static void | ast_sockaddr_setnull (struct ast_sockaddr *addr) |
Sets address addr to null. More... | |
int | ast_sockaddr_split_hostport (char *str, char **host, char **port, int flags) |
Splits a string into its host and port components. More... | |
static char * | ast_sockaddr_stringify (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() with default format. More... | |
static char * | ast_sockaddr_stringify_addr (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only. More... | |
static char * | ast_sockaddr_stringify_addr_remote (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only. More... | |
char * | ast_sockaddr_stringify_fmt (const struct ast_sockaddr *addr, int format) |
Convert a socket address to a string. More... | |
static char * | ast_sockaddr_stringify_host (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6). More... | |
static char * | ast_sockaddr_stringify_host_remote (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6). More... | |
static char * | ast_sockaddr_stringify_port (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() to return a port only. More... | |
static char * | ast_sockaddr_stringify_remote (const struct ast_sockaddr *addr) |
Wrapper around ast_sockaddr_stringify_fmt() with default format. More... | |
const char * | ast_transport2str (enum ast_transport transport) |
Returns a string representation of an ast_transport. More... | |
#define | ast_sockaddr_to_sin(addr, sin) _ast_sockaddr_to_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Converts a struct ast_sockaddr to a struct sockaddr_in. More... | |
#define | ast_sockaddr_from_sin(addr, sin) _ast_sockaddr_from_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Converts a struct sockaddr_in to a struct ast_sockaddr. More... | |
#define | ast_addressfamily_to_sockaddrsize(family) _ast_addressfamily_to_sockaddrsize(family, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Takes an AF_XXX value as input and returns the size of the underlying sockaddr structure if known, or zero if not. More... | |
#define | ast_sockaddr_from_sockaddr(addr, sa) ast_sockaddr_copy_sockaddr(addr, sa, ast_addressfamily_to_sockaddrsize(((const struct sockaddr*)(sa))->sa_family)) |
Converts a struct sockaddr to a struct ast_sockaddr. More... | |
int | _ast_sockaddr_to_sin (const struct ast_sockaddr *addr, struct sockaddr_in *sin, const char *file, int line, const char *func) |
void | _ast_sockaddr_from_sin (struct ast_sockaddr *addr, const struct sockaddr_in *sin, const char *file, int line, const char *func) |
static int | _ast_addressfamily_to_sockaddrsize (int af, const char *file, int line, const char *func) |
Network socket handling.
Definition in file netsock2.h.
#define ast_addressfamily_to_sockaddrsize | ( | family | ) | _ast_addressfamily_to_sockaddrsize(family, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Takes an AF_XXX value as input and returns the size of the underlying sockaddr structure if known, or zero if not.
family | The AF_XXX value to determine the size of |
Definition at line 791 of file netsock2.h.
#define ast_sockaddr_from_sin | ( | addr, | |
sin | |||
) | _ast_sockaddr_from_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Converts a struct sockaddr_in to a struct ast_sockaddr.
addr | |
sin | The sockaddr_in to convert |
Definition at line 778 of file netsock2.h.
Referenced by ast_rtcp_read(), ast_rtp_read(), ast_rtp_stun_request(), ast_sockaddr_apply_netmask(), ast_sockaddr_ipv4_mapped(), and parse_cidr_mask().
#define ast_sockaddr_from_sockaddr | ( | addr, | |
sa | |||
) | ast_sockaddr_copy_sockaddr(addr, sa, ast_addressfamily_to_sockaddrsize(((const struct sockaddr*)(sa))->sa_family)) |
Converts a struct sockaddr to a struct ast_sockaddr.
Note that there is an underlying assumption that sockaddr data is valid, more specifically, if sa_family is set to AF_INET that it's actually a sockaddr_in, and in the case of AF_INET6 a valid sockaddr_in6 structure.
You can check for failure with ast_sockaddr_isnull.
[out] | addr | The address of the ast_sockaddr to store into |
sa | The sockaddr structure (sockaddr_in or sockaddr_in6) to convert |
Definition at line 819 of file netsock2.h.
Referenced by rtp_add_candidates_to_ice().
#define ast_sockaddr_port | ( | addr | ) | _ast_sockaddr_port(addr, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Get the port number of a socket address.
0 | Address is null |
non-zero | The port number of the ast_sockaddr |
Definition at line 517 of file netsock2.h.
Referenced by ast_apply_ha(), ast_audiosocket_connect(), ast_find_ourip(), ast_ha_join(), ast_ouraddrfor(), ast_rtp_ice_turn_request(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), build_peer(), create_outgoing_sdp_stream(), hep_queue_cb(), http_server_get_by_host(), multicast_send_control_packet(), realtime_peer(), rtp_reload(), set_config(), and update_registry().
#define ast_sockaddr_set_port | ( | addr, | |
port | |||
) | _ast_sockaddr_set_port(addr,port,__FILE__,__LINE__,__PRETTY_FUNCTION__) |
Sets the port number of a socket address.
addr | Address on which to set the port |
port | The port you wish to set the address to use |
Definition at line 532 of file netsock2.h.
Referenced by apply_negotiated_sdp_stream(), ast_apply_ha(), ast_find_ourip(), ast_get_ip_or_srv(), ast_ouraddrfor(), ast_rtp_ice_add_cand(), ast_rtp_ice_turn_request(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), build_peer(), http_server_get_by_host(), jingle_interpret_google_transport(), jingle_interpret_ice_udp_transport(), peer_set_srcaddr(), process_ice_attributes(), realtime_peer(), rtp_reload(), set_config(), stun_monitor_request(), and update_address_with_ice_candidate().
#define ast_sockaddr_to_sin | ( | addr, | |
sin | |||
) | _ast_sockaddr_to_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Converts a struct ast_sockaddr to a struct sockaddr_in.
These are backward compatibility functions that may be used by subsystems that have not yet been converted to IPv6. They will be removed when all subsystems are IPv6-ready.
addr | The ast_sockaddr to convert | |
[out] | sin | The resulting sockaddr_in struct |
nonzero | Success |
zero | Failure |
Definition at line 765 of file netsock2.h.
Referenced by ast_parse_arg(), ast_rtcp_read(), ast_rtp_read(), ast_rtp_stun_request(), and rtp_reload().
#define V6_WORD | ( | sin6, | |
index | |||
) | ((uint32_t *)&((sin6)->sin6_addr))[(index)] |
Isolate a 32-bit section of an IPv6 address.
An IPv6 address can be divided into 4 32-bit chunks. This gives easy access to one of these chunks.
sin6 | A pointer to a struct sockaddr_in6 |
index | Which 32-bit chunk to operate on. Must be in the range 0-3. |
Definition at line 77 of file netsock2.h.
Referenced by ast_sockaddr_apply_netmask(), and parse_cidr_mask().
anonymous enum |
Values for address families that we support. This is reproduced from socket.h because we do not want users to include that file. Only netsock2.c should ever include socket.h.
Definition at line 53 of file netsock2.h.
int ast_accept | ( | int | sockfd, |
struct ast_sockaddr * | addr | ||
) |
Wrapper around accept(2) that uses struct ast_sockaddr.
For parameter and return information, see the man page for accept(2).
Definition at line 584 of file netsock2.c.
int ast_bind | ( | int | sockfd, |
const struct ast_sockaddr * | addr | ||
) |
Wrapper around bind(2) that uses struct ast_sockaddr.
For parameter and return information, see the man page for bind(2).
Definition at line 590 of file netsock2.c.
Referenced by ast_rtp_prop_set(), ast_tcptls_client_create(), ast_tcptls_server_start(), and check_srcaddr().
int ast_connect | ( | int | sockfd, |
const struct ast_sockaddr * | addr | ||
) |
Wrapper around connect(2) that uses struct ast_sockaddr.
For parameter and return information, see the man page for connect(2).
Definition at line 595 of file netsock2.c.
Referenced by ast_audiosocket_connect(), ast_ouraddrfor(), and stun_monitor_request().
int ast_getsockname | ( | int | sockfd, |
struct ast_sockaddr * | addr | ||
) |
Wrapper around getsockname(2) that uses struct ast_sockaddr.
For parameter and return information, see the man page for getsockname(2).
Definition at line 600 of file netsock2.c.
Referenced by ast_ouraddrfor(), and ast_set_qos().
ssize_t ast_recvfrom | ( | int | sockfd, |
void * | buf, | ||
size_t | len, | ||
int | flags, | ||
struct ast_sockaddr * | src_addr | ||
) |
Wrapper around recvfrom(2) that uses struct ast_sockaddr.
For parameter and return information, see the man page for recvfrom(2).
Definition at line 606 of file netsock2.c.
Referenced by __rtp_recvfrom().
ssize_t ast_sendto | ( | int | sockfd, |
const void * | buf, | ||
size_t | len, | ||
int | flags, | ||
const struct ast_sockaddr * | dest_addr | ||
) |
Wrapper around sendto(2) that uses ast_sockaddr.
For parameter and return information, see the man page for sendto(2)
Definition at line 614 of file netsock2.c.
Referenced by __rtp_sendto(), hep_queue_cb(), and multicast_send_control_packet().
int ast_set_qos | ( | int | sockfd, |
int | tos, | ||
int | cos, | ||
const char * | desc | ||
) |
Set type of service.
Set ToS ("Type of Service for IPv4 and "Traffic Class for IPv6) and CoS (Linux's SO_PRIORITY)
sockfd | File descriptor for socket on which to set the parameters |
tos | The type of service for the socket |
cos | The cost of service for the socket |
desc | A text description of the socket in question. |
0 | Success |
-1 | Error, with errno set to an appropriate value |
Definition at line 621 of file netsock2.c.
References ast_getsockname(), ast_sockaddr_is_any(), and ast_sockaddr_is_ipv6().
Referenced by ast_netsock_set_qos(), and ast_rtp_qos_set().
int ast_sockaddr_apply_netmask | ( | const struct ast_sockaddr * | addr, |
const struct ast_sockaddr * | netmask, | ||
struct ast_sockaddr * | result | ||
) |
Apply a netmask to an address and store the result in a separate structure.
When dealing with IPv6 addresses, one cannot apply a netmask with a simple logical AND operation. Futhermore, the incoming address may be an IPv4 address and needs to be mapped properly before attempting to apply a rule.
addr | The IP address to apply the mask to. |
netmask | The netmask configured in the host access rule. |
result | The resultant address after applying the netmask to the given address |
0 | Successfully applied netmask |
-1 | Failed to apply netmask |
Definition at line 357 of file netsock2.c.
References ast_sockaddr_from_sin, ast_sockaddr_is_ipv4(), ast_sockaddr_is_ipv6(), and V6_WORD.
Referenced by ast_apply_ha(), and authenticate_reply().
int ast_sockaddr_cidr_bits | ( | const struct ast_sockaddr * | sa | ) |
Count the 1 bits in a netmask.
Definition at line 130 of file netsock2.c.
References ast_sockaddr_ipv4_mapped(), and ast_sockaddr_isnull().
Referenced by ast_ha_join_cidr().
int ast_sockaddr_cmp | ( | const struct ast_sockaddr * | a, |
const struct ast_sockaddr * | b | ||
) |
Compares two ast_sockaddr structures.
-1 | a is lexicographically smaller than b |
0 | a is equal to b |
1 | b is lexicographically smaller than a |
Definition at line 388 of file netsock2.c.
References ast_sockaddr_ipv4_mapped().
Referenced by __rtp_recvfrom(), ast_rtcp_interpret(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_and_cmp_requested_target_address(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_sockaddr_pj_sockaddr_cmp(), ast_tcptls_client_create(), ast_tcptls_server_start(), iax2_ack_registry(), rtp_add_candidates_to_ice(), and update_registry().
int ast_sockaddr_cmp_addr | ( | const struct ast_sockaddr * | a, |
const struct ast_sockaddr * | b | ||
) |
Compares the addresses of two ast_sockaddr structures.
-1 | a is lexicographically smaller than b |
0 | a is equal to b |
1 | b is lexicographically smaller than a |
Definition at line 413 of file netsock2.c.
References ast_sockaddr_ipv4_mapped().
Referenced by ast_apply_ha(), authenticate_reply(), realtime_peer(), realtime_user(), and rtp_add_candidates_to_ice().
|
inlinestatic |
Copies the data from one ast_sockaddr to another.
dst | The destination ast_sockaddr |
src | The source ast_sockaddr |
Definition at line 167 of file netsock2.h.
Referenced by __find_callno(), __rtp_recvfrom(), ast_copy_ha(), ast_find_ourip(), ast_rtcp_interpret(), ast_rtcp_read(), ast_rtcp_write(), ast_rtp_ice_add_remote_candidate(), ast_rtp_ice_turn_request(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_and_cmp_requested_target_address(), ast_rtp_instance_get_incoming_source_address(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_requested_target_address(), ast_rtp_instance_new(), ast_rtp_instance_set_local_address(), ast_rtp_instance_set_requested_target_address(), ast_rtp_new(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_sockaddr_resolve_first_af(), ast_tcptls_client_create(), ast_tcptls_server_start(), authenticate_reply(), build_mansession(), build_peer(), iax2_ack_registry(), rtp_reload(), session_do(), unicast_rtp_request(), and update_registry().
|
inlinestatic |
Copies the data from a sockaddr to an ast_sockaddr.
dst | The destination ast_sockaddr |
src | The source sockaddr |
len | Length of the value stored in sockaddr |
Definition at line 151 of file netsock2.h.
Referenced by curl_open_socket_cb().
int ast_sockaddr_hash | ( | const struct ast_sockaddr * | addr | ) |
Computes a hash value from the address. The port is ignored.
0 | Unknown address family |
other | A 32-bit hash derived from the address |
Definition at line 548 of file netsock2.c.
uint32_t ast_sockaddr_ipv4 | ( | const struct ast_sockaddr * | addr | ) |
Get an IPv4 address of an ast_sockaddr.
Definition at line 491 of file netsock2.c.
Referenced by ast_sockaddr_is_ipv4_multicast(), and multicast_send_control_packet().
int ast_sockaddr_ipv4_mapped | ( | const struct ast_sockaddr * | addr, |
struct ast_sockaddr * | ast_mapped | ||
) |
Convert an IPv4-mapped IPv6 address into an IPv4 address.
addr | The IPv4-mapped address to convert |
ast_mapped | The resulting IPv4 address |
0 | Unable to make the conversion |
1 | Successful conversion |
Definition at line 37 of file netsock2.c.
References ast_sockaddr_from_sin, ast_sockaddr_is_ipv4_mapped(), and ast_sockaddr_is_ipv6().
Referenced by ast_apply_ha(), ast_rtcp_read(), ast_rtp_read(), ast_sockaddr_cidr_bits(), ast_sockaddr_cmp(), ast_sockaddr_cmp_addr(), and ast_sockaddr_stringify_fmt().
int ast_sockaddr_is_any | ( | const struct ast_sockaddr * | addr | ) |
Determine if the address type is unspecified, or "any" address.
For IPv4, this would be the address 0.0.0.0, and for IPv6, this would be the address ::. The port number is ignored.
1 | This is an "any" address |
0 | This is not an "any" address |
Definition at line 534 of file netsock2.c.
References ast_sockaddr_is_ipv4(), and ast_sockaddr_is_ipv6().
Referenced by ast_find_ourip(), ast_set_qos(), ast_tcptls_client_create(), and rtp_add_candidates_to_ice().
int ast_sockaddr_is_ipv4 | ( | const struct ast_sockaddr * | addr | ) |
Determine if the address is an IPv4 address.
1 | This is an IPv4 address |
0 | This is an IPv6 or IPv4-mapped IPv6 address |
Definition at line 497 of file netsock2.c.
Referenced by ast_apply_ha(), ast_json_ipaddr(), ast_rtcp_read(), ast_rtp_ice_turn_request(), ast_rtp_prop_set(), ast_rtp_read(), ast_sockaddr_apply_netmask(), ast_sockaddr_is_any(), hep_queue_cb(), jingle_interpret_ice_udp_transport(), negotiate_incoming_sdp_stream(), and rtp_add_candidates_to_ice().
int ast_sockaddr_is_ipv4_mapped | ( | const struct ast_sockaddr * | addr | ) |
Determine if this is an IPv4-mapped IPv6 address.
1 | This is an IPv4-mapped IPv6 address. |
0 | This is not an IPv4-mapped IPv6 address. |
Definition at line 507 of file netsock2.c.
Referenced by ast_apply_ha(), ast_json_ipaddr(), ast_sockaddr_ipv4_mapped(), and build_peer().
int ast_sockaddr_is_ipv4_multicast | ( | const struct ast_sockaddr * | addr | ) |
Determine if an IPv4 address is a multicast address.
addr | the address to check |
This function checks if an address is in the 224.0.0.0/4 network block.
Definition at line 513 of file netsock2.c.
References ast_sockaddr_ipv4().
int ast_sockaddr_is_ipv6 | ( | const struct ast_sockaddr * | addr | ) |
Determine if this is an IPv6 address.
1 | This is an IPv6 or IPv4-mapped IPv6 address. |
0 | This is an IPv4 address. |
Definition at line 524 of file netsock2.c.
Referenced by ast_apply_ha(), ast_ouraddrfor(), ast_rtp_prop_set(), ast_set_qos(), ast_sockaddr_apply_netmask(), ast_sockaddr_ipv4_mapped(), ast_sockaddr_is_any(), ast_sockaddr_is_ipv6_link_local(), ast_tcptls_client_create(), ast_tcptls_server_start(), build_peer(), hepv3_data_alloc(), multicast_send_control_packet(), and negotiate_incoming_sdp_stream().
int ast_sockaddr_is_ipv6_link_local | ( | const struct ast_sockaddr * | addr | ) |
Determine if this is a link-local IPv6 address.
1 | This is a link-local IPv6 address. |
0 | This is link-local IPv6 address. |
Definition at line 518 of file netsock2.c.
References ast_sockaddr_is_ipv6().
Referenced by ast_sockaddr_stringify_fmt().
|
inlinestatic |
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length.
addr | Pointer to the ast_sockaddr we wish to check |
1 | addr is null |
0 | addr is non-null. |
Definition at line 127 of file netsock2.h.
Referenced by __rtp_recvfrom(), add_ice_to_stream(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_ice_start(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_sendcng(), ast_rtp_write(), ast_sockaddr_cidr_bits(), ast_sockaddr_stringify_fmt(), ast_tcptls_client_create(), ast_tcptls_server_start(), authenticate_reply(), bridge_p2p_rtp_write(), build_peer(), check_for_rtp_changes(), create_outgoing_sdp_stream(), iax2_ack_registry(), iax2_devicestate(), iax2_prov_app(), jingle_interpret_ice_udp_transport(), multicast_send_control_packet(), realtime_peer(), realtime_user(), rtp_add_candidates_to_ice(), rtp_check_timeout(), rtp_raw_write(), and update_registry().
int ast_sockaddr_parse | ( | struct ast_sockaddr * | addr, |
const char * | str, | ||
int | flags | ||
) |
Parse an IPv4 or IPv6 address string.
Parses a string containing an IPv4 or IPv6 address followed by an optional port (separated by a colon) into a struct ast_sockaddr. The allowed formats are the following:
a.b.c.d a.b.c.d:port a:b:c:...:d [a:b:c:...:d]
Host names are NOT allowed.
[out] | addr | The resulting ast_sockaddr. This MAY be NULL from functions that are performing validity checks only, e.g. ast_parse_arg(). |
str | The string to parse | |
flags | If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT be present. |
1 | Success |
0 | Failure |
Definition at line 230 of file netsock2.c.
References ast_sockaddr_split_hostport(), ast_strdupa, and S_OR.
Referenced by ast_parse_arg(), ast_rtp_ice_add_cand(), ast_rtp_ice_turn_request(), build_peer(), change_outgoing_sdp_stream_media_address(), create_rtp(), jingle_alloc(), jingle_enable_video(), jingle_interpret_google_transport(), jingle_interpret_ice_udp_transport(), load_module(), multicast_rtp_request(), peer_set_srcaddr(), process_ice_attributes(), realtime_peer(), rtp_reload(), set_config(), t38_initialize_session(), unicast_rtp_request(), and update_address_with_ice_candidate().
int ast_sockaddr_resolve | ( | struct ast_sockaddr ** | addrs, |
const char * | str, | ||
int | flags, | ||
int | family | ||
) |
Parses a string with an IPv4 or IPv6 address and place results into an array.
Parses a string containing a host name or an IPv4 or IPv6 address followed by an optional port (separated by a colon). The result is returned into a array of struct ast_sockaddr. Allowed formats for str are the following:
hostname:port host.example.com:port a.b.c.d a.b.c.d:port a:b:c:...:d [a:b:c:...:d]
[out] | addrs | The resulting array of ast_sockaddrs |
str | The string to parse | |
flags | If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT be present. | |
family | Only addresses of the given family will be returned. Use 0 or AST_AF_UNSPEC to get addresses of all families. |
0 | Failure |
non-zero | The number of elements in addrs array. |
Definition at line 280 of file netsock2.c.
References ast_malloc, ast_sockaddr_split_hostport(), ast_strdupa, cleanup(), and S_OR.
Referenced by apply_negotiated_sdp_stream(), ast_audiosocket_connect(), ast_sockaddr_resolve_first_af(), http_server_get_by_host(), negotiate_incoming_sdp_stream(), realtime_peer(), and realtime_user().
int ast_sockaddr_resolve_first_af | ( | struct ast_sockaddr * | addr, |
const char * | name, | ||
int | flag, | ||
int | family | ||
) |
Return the first entry from ast_sockaddr_resolve filtered by address family.
Parses a string containing a host name or an IPv4 or IPv6 address followed by an optional port (separated by a colon). This function only returns the first address into the ast_sockaddr. Allowed formats for name are the following:
hostname:port host.example.com:port a.b.c.d a.b.c.d:port a:b:c:...:d [a:b:c:...:d]
[out] | addr | The resulting ast_sockaddr |
name | The string to parse | |
flag | If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT be present. | |
family | Only addresses of the given family will be returned. Use 0 or AST_AF_UNSPEC to specify any address family. Behavior is ultimately determined by getaddrinfo in how it orders return results. First result is selected to be returned. |
0 | Success |
non-zero | Failure |
Return the first entry from ast_sockaddr_resolve filtered by address family.
Definition at line 337 of file netsock2.c.
References ast_debug, ast_sockaddr_copy(), and ast_sockaddr_resolve().
Referenced by ast_parse_arg(), audiosocket_request(), and hepv3_data_alloc().
|
inlinestatic |
Sets address addr to null.
Definition at line 138 of file netsock2.h.
Referenced by ast_tcptls_client_create(), ast_tcptls_server_start(), build_peer(), check_for_rtp_changes(), do_register_expire(), multicast_rtp_request(), rtp_add_candidates_to_ice(), and rtp_reload().
int ast_sockaddr_split_hostport | ( | char * | str, |
char ** | host, | ||
char ** | port, | ||
int | flags | ||
) |
Splits a string into its host and port components.
[in] | str | The string to parse. May be modified by writing a NUL at the end of the host part. |
[out] | host | Pointer to the host component within str. |
[out] | port | Pointer to the port component within str. |
flags | If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT be present. |
1 | Success |
0 | Failure |
Definition at line 164 of file netsock2.c.
References ast_debug.
Referenced by ast_ari_channels_external_media(), ast_sockaddr_parse(), ast_sockaddr_resolve(), peer_set_srcaddr(), rtp_reload(), and unicast_rtp_request().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition at line 256 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
Referenced by __find_callno(), __rtp_recvfrom(), ast_apply_ha(), ast_ari_websocket_session_write(), ast_audiosocket_connect(), ast_ha_join(), ast_parse_arg(), ast_rtcp_interpret(), ast_rtcp_read(), ast_rtcp_write(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_ice_add_cand(), ast_rtp_ice_start(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_sendcng(), ast_sockaddr_pj_sockaddr_cmp(), ast_tcptls_client_create(), ast_tcptls_client_start_timeout(), ast_tcptls_server_start(), ast_websocket_close(), bridge_p2p_rtp_write(), handle_manager_show_settings(), handle_tcptls_connection(), http_server_get_by_addr(), iax2_ack_registry(), iax2_devicestate(), iax2_prov_app(), ice_reset_session(), rtp_raw_write(), session_destroy_fn(), set_config(), stasis_app_message_handler(), stun_monitor_request(), and update_registry().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition at line 286 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
Referenced by ast_ha_join(), ast_ha_join_cidr(), ast_ha_output(), ast_json_ipaddr(), ast_manager_hangup_helper(), ast_ouraddrfor(), generic_http_callback(), get_input(), handle_cli_iax2_show_peer(), handle_showmanconn(), hep_queue_cb(), publish_cluster_discovery_to_stasis_full(), purge_sessions(), realtime_peer(), realtime_user(), register_verify(), session_do(), unicast_rtp_request(), and update_registry().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition at line 313 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
Referenced by add_ice_to_stream(), and change_outgoing_sdp_stream_media_address().
char* ast_sockaddr_stringify_fmt | ( | const struct ast_sockaddr * | addr, |
int | format | ||
) |
Convert a socket address to a string.
This will be of the form a.b.c.d:xyz for IPv4 and [a:b:c:...:d]:xyz for IPv6.
This function is thread-safe. The returned string is on static thread-specific storage.
addr | The input to be stringified |
format | one of the following: AST_SOCKADDR_STR_DEFAULT: a.b.c.d:xyz for IPv4 [a:b:c:...:d]:xyz for IPv6. AST_SOCKADDR_STR_ADDR: address only a.b.c.d for IPv4 a:b:c:...:d for IPv6. AST_SOCKADDR_STR_HOST: address only, suitable for a URL a.b.c.d for IPv4 [a:b:c:...:d] for IPv6. AST_SOCKADDR_STR_PORT: port only |
(null) | addr is null |
"" | An error occurred during processing |
Definition at line 65 of file netsock2.c.
References ast_sockaddr_ipv4_mapped(), ast_sockaddr_is_ipv6_link_local(), ast_sockaddr_isnull(), ast_str_buffer(), ast_str_set(), and ast_str_thread_get().
Referenced by ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_addr_remote(), ast_sockaddr_stringify_host(), ast_sockaddr_stringify_host_remote(), ast_sockaddr_stringify_port(), ast_sockaddr_stringify_remote(), and create_outgoing_sdp_stream().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6).
Definition at line 327 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
Referenced by jingle_add_google_candidates_to_transport(), jingle_add_ice_udp_candidates_to_transport(), and rtp_reload().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6).
Definition at line 345 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Definition at line 358 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
Referenced by add_ice_to_stream(), ast_json_ipaddr(), handle_cli_iax2_show_peer(), jingle_add_google_candidates_to_transport(), jingle_add_ice_udp_candidates_to_transport(), realtime_peer(), realtime_user(), and unicast_rtp_request().
|
inlinestatic |
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition at line 273 of file netsock2.h.
References ast_sockaddr_stringify_fmt().
const char* ast_transport2str | ( | enum ast_transport | transport | ) |
Returns a string representation of an ast_transport.
Definition at line 566 of file netsock2.c.