Network socket handling. More...
#include <sys/socket.h>#include <netinet/in.h>

Go to the source code of this file.
Data Structures | |
| struct | ast_sockaddr |
| Socket address structure. More... | |
Defines | |
| #define | ast_sockaddr_port(addr) _ast_sockaddr_port(addr, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| Get the port number of a socket address. | |
| #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. | |
| #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) |
Enumerations | |
| enum | { AST_AF_UNSPEC = 0, AST_AF_INET = 2, AST_AF_INET6 = 10 } |
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. | |
| int | ast_bind (int sockfd, const struct ast_sockaddr *addr) |
| Wrapper around bind(2) that uses struct ast_sockaddr. | |
| int | ast_connect (int sockfd, const struct ast_sockaddr *addr) |
| Wrapper around connect(2) that uses struct ast_sockaddr. | |
| int | ast_getsockname (int sockfd, struct ast_sockaddr *addr) |
| Wrapper around getsockname(2) that uses struct ast_sockaddr. | |
| 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. | |
| 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. | |
| int | ast_set_qos (int sockfd, int tos, int cos, const char *desc) |
| Set type of service. | |
| int | ast_sockaddr_cmp (const struct ast_sockaddr *a, const struct ast_sockaddr *b) |
| Compares two ast_sockaddr structures. | |
| int | ast_sockaddr_cmp_addr (const struct ast_sockaddr *a, const struct ast_sockaddr *b) |
| Compares the addresses of two ast_sockaddr structures. | |
| static void | ast_sockaddr_copy (struct ast_sockaddr *dst, const struct ast_sockaddr *src) |
| Copies the data from one ast_sockaddr to another. | |
| int | ast_sockaddr_hash (const struct ast_sockaddr *addr) |
| Computes a hash value from the address. The port is ignored. | |
| uint32_t | ast_sockaddr_ipv4 (const struct ast_sockaddr *addr) |
| Get an IPv4 address of an ast_sockaddr. | |
| 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. | |
| int | ast_sockaddr_is_any (const struct ast_sockaddr *addr) |
| Determine if the address type is unspecified, or "any" address. | |
| int | ast_sockaddr_is_ipv4 (const struct ast_sockaddr *addr) |
| Determine if the address is an IPv4 address. | |
| int | ast_sockaddr_is_ipv4_mapped (const struct ast_sockaddr *addr) |
| Determine if this is an IPv4-mapped IPv6 address. | |
| int | ast_sockaddr_is_ipv6 (const struct ast_sockaddr *addr) |
| Determine if this is an IPv6 address. | |
| int | ast_sockaddr_is_ipv6_link_local (const struct ast_sockaddr *addr) |
| Determine if this is a link-local IPv6 address. | |
| 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. | |
| int | ast_sockaddr_parse (struct ast_sockaddr *addr, const char *str, int flags) |
| Parse an IPv4 or IPv6 address string. | |
| 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. | |
| static void | ast_sockaddr_setnull (struct ast_sockaddr *addr) |
| Sets address addr to null. | |
| int | ast_sockaddr_split_hostport (char *str, char **host, char **port, int flags) |
| Splits a string into its host and port components. | |
| static char * | ast_sockaddr_stringify (const struct ast_sockaddr *addr) |
| Wrapper around ast_sockaddr_stringify_fmt() with default format. | |
| static char * | ast_sockaddr_stringify_addr (const struct ast_sockaddr *addr) |
| Wrapper around ast_sockaddr_stringify_fmt() to return an address only. | |
| static char * | ast_sockaddr_stringify_addr_remote (const struct ast_sockaddr *addr) |
| Wrapper around ast_sockaddr_stringify_fmt() to return an address only. | |
| char * | ast_sockaddr_stringify_fmt (const struct ast_sockaddr *addr, int format) |
| Convert a socket address to a string. | |
| 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). | |
| 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). | |
| static char * | ast_sockaddr_stringify_port (const struct ast_sockaddr *addr) |
| Wrapper around ast_sockaddr_stringify_fmt() to return a port only. | |
| static char * | ast_sockaddr_stringify_remote (const struct ast_sockaddr *addr) |
| Wrapper around ast_sockaddr_stringify_fmt() with default format. | |
| #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. | |
| #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. | |
| 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) |
Network socket handling.
Definition in 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.
| sin | The sockaddr_in to convert |
Definition at line 633 of file netsock2.h.
Referenced by apply_netmask(), parse_cidr_mask(), app_exec(), gtalk_get_local_ip(), gtalk_alloc(), gtalk_update_externip(), gtalk_update_stun(), load_module(), __oh323_rtp_create(), setup_rtp_connection(), check_access(), register_verify(), update_registry(), jingle_create_candidates(), jingle_alloc(), jingle_update_stun(), find_subchannel_and_lock(), process_sdp(), start_rtp(), build_gateway(), skinny_register(), handle_open_receive_channel_ack_message(), __ast_http_load(), authenticate(), auth_http_callback(), manager_http_callback(), mxml_http_callback(), rawman_http_callback(), auth_manager_http_callback(), auth_mxml_http_callback(), auth_rawman_http_callback(), __init_manager(), ast_sockaddr_ipv4_mapped(), ast_rtp_read(), ast_rtp_stun_request(), and stun_start_monitor().
| #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 397 of file netsock2.h.
Referenced by ast_ouraddrfor(), realtime_update_peer(), __iax2_show_peers(), manager_iax2_show_peer_list(), build_peer(), peers_data_provider_get(), sip_debug_test_addr(), ast_sip_ouraddrfor(), create_addr(), copy_via_headers(), set_destination(), get_our_media_address(), add_sdp(), initreqprep(), __sip_subscribe_mwi_do(), transmit_notify_with_mwi(), transmit_register(), __set_address_from_contact(), parse_register_contact(), check_via(), _sip_show_peers(), _sip_show_peer(), function_sippeer(), sipsock_read(), sip_request_call(), reload_config(), peer_ipcmp_cb(), dnsmgr_refresh(), ast_rtp_read(), ast_rtp_prop_set(), ast_rtp_remote_address_set(), multicast_send_control_packet(), and udptl_debug_test_addr().
| #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 |
| void |
Definition at line 413 of file netsock2.h.
Referenced by ast_get_ip_or_srv(), ast_ouraddrfor(), realtime_peer(), iax2_append_register(), build_peer(), proxy_update(), ast_sip_ouraddrfor(), create_addr(), process_via(), process_sdp(), set_destination(), get_our_media_address(), add_sdp(), __sip_subscribe_mwi_do(), sip_reg_timeout(), transmit_register(), __set_address_from_contact(), parse_register_contact(), check_via_response(), check_via(), sip_request_call(), reload_config(), dnsmgr_refresh(), __ast_http_load(), ast_rtp_new(), ast_rtp_read(), ast_rtp_prop_set(), ast_rtp_remote_address_set(), and ast_udptl_new_with_bindaddr().
| #define AST_SOCKADDR_STR_ADDR (1 << 0) |
Definition at line 152 of file netsock2.h.
Referenced by ast_sockaddr_stringify_fmt(), and ast_sockaddr_stringify_addr().
| #define AST_SOCKADDR_STR_ADDR_REMOTE (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_REMOTE) |
Definition at line 158 of file netsock2.h.
Referenced by ast_sockaddr_stringify_addr_remote().
| #define AST_SOCKADDR_STR_BRACKETS (1 << 2) |
Definition at line 154 of file netsock2.h.
| #define AST_SOCKADDR_STR_DEFAULT (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT) |
Definition at line 157 of file netsock2.h.
Referenced by ast_sockaddr_stringify_fmt(), and ast_sockaddr_stringify().
| #define AST_SOCKADDR_STR_DEFAULT_REMOTE (AST_SOCKADDR_STR_DEFAULT | AST_SOCKADDR_STR_REMOTE) |
Definition at line 160 of file netsock2.h.
Referenced by ast_sockaddr_stringify_remote().
| #define AST_SOCKADDR_STR_FORMAT_MASK (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT | AST_SOCKADDR_STR_BRACKETS) |
Definition at line 161 of file netsock2.h.
Referenced by ast_sockaddr_stringify_fmt().
| #define AST_SOCKADDR_STR_HOST (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_BRACKETS) |
Definition at line 156 of file netsock2.h.
Referenced by _sip_show_peers(), ast_sockaddr_stringify_fmt(), and ast_sockaddr_stringify_host().
| #define AST_SOCKADDR_STR_HOST_REMOTE (AST_SOCKADDR_STR_HOST | AST_SOCKADDR_STR_REMOTE) |
Definition at line 159 of file netsock2.h.
Referenced by ast_sockaddr_stringify_host_remote().
| #define AST_SOCKADDR_STR_PORT (1 << 1) |
Definition at line 153 of file netsock2.h.
Referenced by ast_sockaddr_stringify_fmt(), and ast_sockaddr_stringify_port().
| #define AST_SOCKADDR_STR_REMOTE (1 << 3) |
Definition at line 155 of file netsock2.h.
Referenced by ast_sockaddr_stringify_fmt().
| #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 620 of file netsock2.h.
Referenced by gtalk_create_candidates(), gtalk_update_stun(), build_user(), build_peer(), external_rtp_create(), oh323_set_rtp_peer(), iax2_getpeername(), addr_range_hash_cb(), addr_range_match_address_cb(), peercnt_modify(), handle_cli_iax2_show_peer(), create_addr(), iax2_getpeertrunk(), __iax2_show_peers(), handle_cli_iax2_set_debug(), authenticate_reply(), iax2_ack_registry(), update_registry(), registry_rerequest(), iax2_do_register(), iax2_poke_peer(), peer_set_srcaddr(), jingle_create_candidates(), find_subchannel_and_lock(), add_sdp(), transmit_modify_with_sdp(), build_gateway(), skinny_set_rtp_peer(), handle_open_receive_channel_ack_message(), config_parse_variables(), start_rtp(), __ast_http_load(), handle_show_http(), mansession_encode_sin_local(), session_do(), manager_http_callback(), mxml_http_callback(), rawman_http_callback(), auth_manager_http_callback(), auth_mxml_http_callback(), auth_rawman_http_callback(), ast_rtp_read(), and ast_rtp_stun_request().
| 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 39 of file netsock2.h.
{
AST_AF_UNSPEC = 0,
AST_AF_INET = 2,
AST_AF_INET6 = 10,
};
| void _ast_sockaddr_from_sin | ( | struct ast_sockaddr * | addr, |
| const struct sockaddr_in * | sin, | ||
| const char * | file, | ||
| int | line, | ||
| const char * | func | ||
| ) |
Definition at line 551 of file netsock2.c.
References ast_sockaddr::ss, option_debug, ast_log(), __LOG_DEBUG, and ast_sockaddr::len.
{
memcpy(&addr->ss, sin, sizeof(*sin));
if (addr->ss.ss_family != AF_INET && option_debug >= 1) {
ast_log(__LOG_DEBUG, file, line, func, "Address family is not AF_INET\n");
}
addr->len = sizeof(*sin);
}
| uint16_t _ast_sockaddr_port | ( | const struct ast_sockaddr * | addr, |
| const char * | file, | ||
| int | line, | ||
| const char * | func | ||
| ) |
Definition at line 355 of file netsock2.c.
References ast_sockaddr::ss, ast_sockaddr::len, option_debug, ast_log(), and __LOG_DEBUG.
{
if (addr->ss.ss_family == AF_INET &&
addr->len == sizeof(struct sockaddr_in)) {
return ntohs(((struct sockaddr_in *)&addr->ss)->sin_port);
} else if (addr->ss.ss_family == AF_INET6 &&
addr->len == sizeof(struct sockaddr_in6)) {
return ntohs(((struct sockaddr_in6 *)&addr->ss)->sin6_port);
}
if (option_debug >= 1) {
ast_log(__LOG_DEBUG, file, line, func, "Not an IPv4 nor IPv6 address, cannot get port.\n");
}
return 0;
}
| void _ast_sockaddr_set_port | ( | struct ast_sockaddr * | addr, |
| uint16_t | port, | ||
| const char * | file, | ||
| int | line, | ||
| const char * | func | ||
| ) |
Definition at line 370 of file netsock2.c.
References ast_sockaddr::ss, ast_sockaddr::len, option_debug, ast_log(), and __LOG_DEBUG.
{
if (addr->ss.ss_family == AF_INET &&
addr->len == sizeof(struct sockaddr_in)) {
((struct sockaddr_in *)&addr->ss)->sin_port = htons(port);
} else if (addr->ss.ss_family == AF_INET6 &&
addr->len == sizeof(struct sockaddr_in6)) {
((struct sockaddr_in6 *)&addr->ss)->sin6_port = htons(port);
} else if (option_debug >= 1) {
ast_log(__LOG_DEBUG, file, line, func,
"Not an IPv4 nor IPv6 address, cannot set port.\n");
}
}
| int _ast_sockaddr_to_sin | ( | const struct ast_sockaddr * | addr, |
| struct sockaddr_in * | sin, | ||
| const char * | file, | ||
| int | line, | ||
| const char * | func | ||
| ) |
Definition at line 530 of file netsock2.c.
References ast_sockaddr_isnull(), ast_sockaddr::len, ast_log(), __LOG_ERROR, ast_sockaddr::ss, option_debug, and __LOG_DEBUG.
{
if (ast_sockaddr_isnull(addr)) {
memset(sin, 0, sizeof(*sin));
return 1;
}
if (addr->len != sizeof(*sin)) {
ast_log(__LOG_ERROR, file, line, func, "Bad address cast to IPv4\n");
return 0;
}
if (addr->ss.ss_family != AF_INET && option_debug >= 1) {
ast_log(__LOG_DEBUG, file, line, func, "Address family is not AF_INET\n");
}
*sin = *(struct sockaddr_in *)&addr->ss;
return 1;
}
| 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 446 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by ast_tcptls_server_root().
| 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 452 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by reload_config(), ast_rtp_new(), ast_rtp_prop_set(), ast_tcptls_client_create(), ast_tcptls_server_start(), and ast_udptl_new_with_bindaddr().
| 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 457 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by ast_ouraddrfor(), gtalk_update_externip(), stun_start_monitor(), and ast_tcptls_client_start().
| 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 462 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
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 468 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by sipsock_read(), __rtp_recvfrom(), and ast_udptl_read().
| 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 476 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by __sip_xmit(), __rtp_sendto(), multicast_send_control_packet(), multicast_rtp_write(), and ast_udptl_write().
| 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 483 of file netsock2.c.
References ast_getsockname(), ast_sockaddr_is_ipv6(), ast_sockaddr_is_any(), ast_log(), LOG_WARNING, errno, and ast_verb.
Referenced by reload_config(), and ast_rtp_qos_set().
{
int res = 0;
int set_tos;
int set_tclass;
struct ast_sockaddr addr;
/* If the sock address is IPv6, the TCLASS field must be set. */
set_tclass = !ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr) ? 1 : 0;
/* If the the sock address is IPv4 or (IPv6 set to any address [::]) set TOS bits */
set_tos = (!set_tclass || (set_tclass && ast_sockaddr_is_any(&addr))) ? 1 : 0;
if (set_tos) {
if ((res = setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) {
ast_log(LOG_WARNING, "Unable to set %s DSCP TOS value to %d (may be you have no "
"root privileges): %s\n", desc, tos, strerror(errno));
} else if (tos) {
ast_verb(2, "Using %s TOS bits %d\n", desc, tos);
}
}
#if defined(IPV6_TCLASS) && defined(IPPROTO_IPV6)
if (set_tclass) {
if (!ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr)) {
if ((res = setsockopt(sockfd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)))) {
ast_log(LOG_WARNING, "Unable to set %s DSCP TCLASS field to %d (may be you have no "
"root privileges): %s\n", desc, tos, strerror(errno));
} else if (tos) {
ast_verb(2, "Using %s TOS bits %d in TCLASS field.\n", desc, tos);
}
}
}
#endif
#ifdef linux
if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos))) {
ast_log(LOG_WARNING, "Unable to set %s CoS to %d: %s\n", desc, cos,
strerror(errno));
} else if (cos) {
ast_verb(2, "Using %s CoS mark %d\n", desc, cos);
}
#endif
return res;
}
| 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 290 of file netsock2.c.
References ast_sockaddr::len, ast_sockaddr_ipv4_mapped(), and ast_sockaddr::ss.
Referenced by update_registry(), sip_debug_test_addr(), realtime_peer(), add_sdp(), parse_register_contact(), threadinfo_locate_cb(), reload_config(), dnsmgr_refresh(), rtp_debug_test_addr(), rtcp_debug_test_addr(), ast_rtcp_read(), ast_rtp_read(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_and_cmp_remote_address(), remote_bridge_loop(), ast_tcptls_client_create(), ast_tcptls_server_start(), udptl_debug_test_addr(), ast_udptl_read(), and ast_udptl_bridge().
{
const struct ast_sockaddr *a_tmp, *b_tmp;
struct ast_sockaddr ipv4_mapped;
a_tmp = a;
b_tmp = b;
if (a_tmp->len != b_tmp->len) {
if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) {
a_tmp = &ipv4_mapped;
} else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) {
b_tmp = &ipv4_mapped;
}
}
if (a_tmp->len < b_tmp->len) {
return -1;
} else if (a_tmp->len > b_tmp->len) {
return 1;
}
return memcmp(&a_tmp->ss, &b_tmp->ss, a_tmp->len);
}
| 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 315 of file netsock2.c.
References ast_sockaddr::len, ast_sockaddr_ipv4_mapped(), and ast_sockaddr::ss.
Referenced by ast_apply_ha(), addr_range_cmp_cb(), sip_debug_test_addr(), get_our_media_address(), peer_ipcmp_cb(), and udptl_debug_test_addr().
{
const struct ast_sockaddr *a_tmp, *b_tmp;
struct ast_sockaddr ipv4_mapped;
const struct in_addr *ip4a, *ip4b;
const struct in6_addr *ip6a, *ip6b;
int ret = -1;
a_tmp = a;
b_tmp = b;
if (a_tmp->len != b_tmp->len) {
if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) {
a_tmp = &ipv4_mapped;
} else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) {
b_tmp = &ipv4_mapped;
}
}
if (a->len < b->len) {
ret = -1;
} else if (a->len > b->len) {
ret = 1;
}
switch (a_tmp->ss.ss_family) {
case AF_INET:
ip4a = &((const struct sockaddr_in*)&a_tmp->ss)->sin_addr;
ip4b = &((const struct sockaddr_in*)&b_tmp->ss)->sin_addr;
ret = memcmp(ip4a, ip4b, sizeof(*ip4a));
break;
case AF_INET6:
ip6a = &((const struct sockaddr_in6*)&a_tmp->ss)->sin6_addr;
ip6b = &((const struct sockaddr_in6*)&b_tmp->ss)->sin6_addr;
ret = memcmp(ip6a, ip6b, sizeof(*ip6a));
break;
}
return ret;
}
| static void ast_sockaddr_copy | ( | struct ast_sockaddr * | dst, |
| const struct ast_sockaddr * | src | ||
| ) | [inline, static] |
Copies the data from one ast_sockaddr to another.
| dst | The destination ast_sockaddr |
| src | The source ast_sockaddr |
| void |
Definition at line 121 of file netsock2.h.
References ast_sockaddr::len.
Referenced by ast_copy_ha(), resolve_first(), ast_find_ourip(), gtalk_get_local_ip(), ast_sip_ouraddrfor(), find_peer(), dialog_initialize_rtp(), create_addr(), sip_alloc(), transmit_response_using_temp(), get_our_media_address(), add_sdp(), sip_reg_timeout(), transmit_register(), reg_source_db(), parse_register_contact(), sip_do_debug_peer(), handle_request_do(), sip_prepare_socket(), reload_config(), ast_sockaddr_resolve_first_af(), dnsmgr_refresh(), ast_rtcp_read(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_alt_remote_address_set(), ast_rtp_instance_new(), ast_rtp_instance_set_local_address(), ast_rtp_instance_set_remote_address(), ast_rtp_instance_set_alt_remote_address(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_and_cmp_remote_address(), ast_rtp_instance_get_remote_address(), remote_bridge_loop(), ast_tcptls_server_root(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_read(), ast_udptl_new_with_bindaddr(), ast_udptl_set_peer(), ast_udptl_get_peer(), ast_udptl_get_us(), ast_udptl_bridge(), and handle_cli_udptl_set_debug().
| 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 428 of file netsock2.c.
References ast_sockaddr::ss, ast_log(), and LOG_ERROR.
Referenced by peer_iphash_cb(), and threadt_hash_cb().
{
/*
* For IPv4, return the IP address as-is. For IPv6, return the last 32
* bits.
*/
switch (addr->ss.ss_family) {
case AF_INET:
return ((const struct sockaddr_in *)&addr->ss)->sin_addr.s_addr;
case AF_INET6:
return ((uint32_t *)&((const struct sockaddr_in6 *)&addr->ss)->sin6_addr)[3];
default:
ast_log(LOG_ERROR, "Unknown address family '%d'.\n",
addr->ss.ss_family);
return 0;
}
}
| uint32_t ast_sockaddr_ipv4 | ( | const struct ast_sockaddr * | addr | ) |
Get an IPv4 address of an ast_sockaddr.
Definition at line 384 of file netsock2.c.
References ast_sockaddr::ss.
Referenced by load_module(), iax2_do_register(), iax2_poke_peer(), iax2_devicestate(), jingle_create_candidates(), addr_is_multicast(), and multicast_send_control_packet().
{
const struct sockaddr_in *sin = (struct sockaddr_in *)&addr->ss;
return ntohl(sin->sin_addr.s_addr);
}
| 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 |
| mapped_addr | The resulting IPv4 address |
| 0 | Unable to make the conversion |
| 1 | Successful conversion |
Definition at line 35 of file netsock2.c.
References ast_sockaddr_is_ipv6(), ast_sockaddr_is_ipv4_mapped(), ast_sockaddr::ss, and ast_sockaddr_from_sin.
Referenced by ast_append_ha(), ast_apply_ha(), ast_sockaddr_stringify_fmt(), ast_sockaddr_cmp(), and ast_sockaddr_cmp_addr().
{
const struct sockaddr_in6 *sin6;
struct sockaddr_in sin4;
if (!ast_sockaddr_is_ipv6(addr)) {
return 0;
}
if (!ast_sockaddr_is_ipv4_mapped(addr)) {
return 0;
}
sin6 = (const struct sockaddr_in6*)&addr->ss;
memset(&sin4, 0, sizeof(sin4));
sin4.sin_family = AF_INET;
sin4.sin_port = sin6->sin6_port;
sin4.sin_addr.s_addr = ((uint32_t *)&sin6->sin6_addr)[3];
ast_sockaddr_from_sin(ast_mapped, &sin4);
return 1;
}
| 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 414 of file netsock2.c.
References ast_sockaddr::ss, ast_sockaddr_is_ipv4(), and ast_sockaddr_is_ipv6().
Referenced by ast_find_ourip(), gtalk_get_local_ip(), ast_sip_ouraddrfor(), get_our_media_address(), sip_show_settings(), get_address_family_filter(), reload_config(), and ast_set_qos().
{
union {
struct sockaddr_storage ss;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} tmp_addr = {
.ss = addr->ss,
};
return (ast_sockaddr_is_ipv4(addr) && (tmp_addr.sin.sin_addr.s_addr == INADDR_ANY)) ||
(ast_sockaddr_is_ipv6(addr) && IN6_IS_ADDR_UNSPECIFIED(&tmp_addr.sin6.sin6_addr));
}
| 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 390 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by apply_netmask(), ast_append_ha(), ast_apply_ha(), ast_sockaddr_is_any(), ast_rtp_new(), and ast_rtp_prop_set().
| 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 396 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by ast_apply_ha(), add_sdp(), ast_sockaddr_ipv4_mapped(), and ast_rtp_instance_bridge().
| 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 408 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr::len.
Referenced by apply_netmask(), ast_apply_ha(), ast_ouraddrfor(), ast_sip_ouraddrfor(), add_sdp(), sip_show_settings(), get_address_family_filter(), reload_config(), ast_sockaddr_ipv4_mapped(), ast_sockaddr_is_ipv6_link_local(), ast_sockaddr_is_any(), ast_set_qos(), ast_rtp_new(), ast_rtp_prop_set(), multicast_send_control_packet(), ast_tcptls_client_create(), ast_tcptls_server_start(), and ast_udptl_new_with_bindaddr().
| 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 402 of file netsock2.c.
References ast_sockaddr::ss, and ast_sockaddr_is_ipv6().
Referenced by ast_sockaddr_stringify_fmt().
{
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&addr->ss;
return ast_sockaddr_is_ipv6(addr) && IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr);
}
| static int ast_sockaddr_isnull | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
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 93 of file netsock2.h.
References ast_sockaddr::len.
Referenced by unlink_peer_from_tables(), sip_debug_test_addr(), ast_sip_ouraddrfor(), realtime_peer(), create_addr_from_peer(), create_addr(), process_sdp(), get_our_media_address(), add_sdp(), transmit_register(), expire_register(), parse_register_contact(), register_verify(), _sip_show_peers(), sip_prune_realtime(), sip_show_settings(), sip_show_channel(), sip_do_debug_peer(), sip_send_mwi_to_peer(), check_rtp_timeout(), sip_poke_peer(), sip_devicestate(), build_peer(), reload_config(), sip_set_rtp_peer(), peer_iphash_cb(), ast_sockaddr_stringify_fmt(), _ast_sockaddr_to_sin(), rtp_debug_test_addr(), rtcp_debug_test_addr(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_raw_write(), ast_rtp_write(), bridge_p2p_rtp_write(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_sendcng(), multicast_send_control_packet(), remote_bridge_loop(), ast_tcptls_client_create(), ast_tcptls_server_start(), udptl_debug_test_addr(), ast_udptl_read(), and ast_udptl_write().
{
return !addr || addr->len == 0;
}
| 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] [a:b:c:...:d]:port
Host names are NOT allowed.
| [out] | addr | The resulting ast_sockaddr |
| 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 194 of file netsock2.c.
References ast_strdupa, ast_sockaddr_split_hostport(), ast_log(), LOG_ERROR, S_OR, LOG_WARNING, ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by ast_append_ha(), realtime_peer(), reg_source_db(), multicast_rtp_request(), proxy_update(), sip_sanitized_host(), build_peer(), reload_config(), ast_parse_arg(), ast_dnsmgr_lookup(), rtp_do_debug_ip(), and rtcp_do_debug_ip().
{
struct addrinfo hints;
struct addrinfo *res;
char *s;
char *host;
char *port;
int e;
s = ast_strdupa(str);
if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}
memset(&hints, 0, sizeof(hints));
/* Hint to get only one entry from getaddrinfo */
hints.ai_socktype = SOCK_DGRAM;
#ifdef AI_NUMERICSERV
hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
#else
hints.ai_flags = AI_NUMERICHOST;
#endif
if ((e = getaddrinfo(host, port, &hints, &res))) {
if (e != EAI_NONAME) { /* if this was just a host name rather than a ip address, don't print error */
ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n",
host, S_OR(port, "(null)"), gai_strerror(e));
}
return 0;
}
/*
* I don't see how this could be possible since we're not resolving host
* names. But let's be careful...
*/
if (res->ai_next != NULL) {
ast_log(LOG_WARNING, "getaddrinfo() returned multiple "
"addresses. Ignoring all but the first.\n");
}
addr->len = res->ai_addrlen;
memcpy(&addr->ss, res->ai_addr, addr->len);
freeaddrinfo(res);
return 1;
}
| 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] [a:b:c:...:d]:port
| [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_SOCKADDR_UNSPEC to get addresses of all families. |
| 0 | Failure |
| non-zero | The number of elements in addrs array. |
Definition at line 242 of file netsock2.c.
References ast_strdupa, ast_sockaddr_split_hostport(), ast_log(), LOG_ERROR, S_OR, ast_malloc, and cleanup().
Referenced by resolve_first(), gtalk_get_local_ip(), realtime_peer(), ast_sockaddr_resolve_first_af(), and handle_cli_udptl_set_debug().
{
struct addrinfo hints, *res, *ai;
char *s, *host, *port;
int e, i, res_cnt;
if (!str) {
return 0;
}
s = ast_strdupa(str);
if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}
memset(&hints, 0, sizeof(hints));
hints.ai_family = family;
hints.ai_socktype = SOCK_DGRAM;
if ((e = getaddrinfo(host, port, &hints, &res))) {
ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n",
host, S_OR(port, "(null)"), gai_strerror(e));
return 0;
}
res_cnt = 0;
for (ai = res; ai; ai = ai->ai_next) {
res_cnt++;
}
if ((*addrs = ast_malloc(res_cnt * sizeof(struct ast_sockaddr))) == NULL) {
res_cnt = 0;
goto cleanup;
}
i = 0;
for (ai = res; ai; ai = ai->ai_next) {
(*addrs)[i].len = ai->ai_addrlen;
memcpy(&(*addrs)[i].ss, ai->ai_addr, ai->ai_addrlen);
++i;
}
cleanup:
freeaddrinfo(res);
return res_cnt;
}
| static void ast_sockaddr_setnull | ( | struct ast_sockaddr * | addr | ) | [inline, static] |
Sets address addr to null.
| void |
Definition at line 106 of file netsock2.h.
References ast_sockaddr::len.
Referenced by get_local_address(), build_peer(), multicast_rtp_request(), set_peer_defaults(), reload_config(), __ast_http_load(), ast_rtp_stop(), ast_tcptls_client_create(), ast_tcptls_server_start(), and ast_udptl_stop().
{
addr->len = 0;
}
| int ast_sockaddr_split_hostport | ( | char * | str, |
| char ** | host, | ||
| char ** | port, | ||
| int | flags | ||
| ) |
Splits a string into its host and port components.
| str[in] | The string to parse. May be modified by writing a NUL at the end of the host part. |
| host[out] | Pointer to the host component within str. |
| port[out] | 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 128 of file netsock2.c.
References str, ast_debug, PARSE_PORT_MASK, PARSE_PORT_IGNORE, PARSE_PORT_REQUIRE, ast_log(), LOG_WARNING, and PARSE_PORT_FORBID.
Referenced by ast_sockaddr_parse(), and ast_sockaddr_resolve().
{
char *s = str;
char *orig_str = str;/* Original string in case the port presence is incorrect. */
char *host_end = NULL;/* Delay terminating the host in case the port presence is incorrect. */
ast_debug(5, "Splitting '%s' into...\n", str);
*host = NULL;
*port = NULL;
if (*s == '[') {
*host = ++s;
for (; *s && *s != ']'; ++s) {
}
if (*s == ']') {
host_end = s;
++s;
}
if (*s == ':') {
*port = s + 1;
}
} else {
*host = s;
for (; *s; ++s) {
if (*s == ':') {
if (*port) {
*port = NULL;
break;
} else {
*port = s;
}
}
}
if (*port) {
host_end = *port;
++*port;
}
}
switch (flags & PARSE_PORT_MASK) {
case PARSE_PORT_IGNORE:
*port = NULL;
break;
case PARSE_PORT_REQUIRE:
if (*port == NULL) {
ast_log(LOG_WARNING, "Port missing in %s\n", orig_str);
return 0;
}
break;
case PARSE_PORT_FORBID:
if (*port != NULL) {
ast_log(LOG_WARNING, "Port disallowed in %s\n", orig_str);
return 0;
}
break;
}
/* Can terminate the host string now if needed. */
if (host_end) {
*host_end = '\0';
}
ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port ? *port : "");
return 1;
}
| static char* ast_sockaddr_stringify | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition at line 202 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_DEFAULT.
Referenced by ast_append_ha(), gtalk_update_externip(), handle_cli_iax2_show_registry(), manager_iax2_show_registry(), reg_source_db(), __sip_xmit(), ast_sip_ouraddrfor(), retrans_pkt(), send_response(), send_request(), process_sdp(), set_destination(), add_sdp(), parse_register_contact(), register_verify(), check_via(), check_peer_ok(), sip_show_tcp(), _sip_show_peer(), sip_show_settings(), sip_show_channel(), handle_response_notify(), handle_response_refer(), handle_response_info(), handle_response_message(), handle_response(), handle_request_invite(), handle_request_bye(), handle_request_subscribe(), handle_request_register(), handle_incoming(), handle_request_do(), reload_config(), apply_directmedia_ha(), sip_set_udptl_peer(), sip_set_rtp_peer(), ast_parse_arg(), dnsmgr_refresh(), handle_manager_show_settings(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_raw_write(), create_dtmf_frame(), process_dtmf_rfc2833(), process_cn_rfc3389(), ast_rtcp_read(), bridge_p2p_rtp_write(), ast_rtp_read(), ast_rtp_sendcng(), rtp_do_debug_ip(), rtcp_do_debug_ip(), multicast_rtp_write(), stun_start_monitor(), remote_bridge_loop(), ast_tcptls_client_start(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_read(), ast_udptl_write(), ast_udptl_bridge(), and handle_cli_udptl_set_debug().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_DEFAULT);
}
| static char* ast_sockaddr_stringify_addr | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition at line 232 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_ADDR.
Referenced by ast_ouraddrfor(), gtalk_create_candidates(), realtime_update_peer(), __iax2_show_peers(), manager_iax2_show_peer_list(), function_iaxpeer(), realtime_peer(), add_sdp(), parse_register_contact(), register_verify(), _sip_show_peers(), _sip_show_peer(), show_chanstats_cb(), sip_show_settings(), show_channels_cb(), sip_show_channel(), sip_do_debug_ip(), sip_do_debug_peer(), function_sippeer(), function_sipchaninfo_read(), build_peer(), reload_config(), and httpstatus_callback().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_ADDR);
}
| static char* ast_sockaddr_stringify_addr_remote | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition at line 249 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_ADDR_REMOTE.
Referenced by copy_via_headers(), and add_sdp().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_ADDR_REMOTE);
}
| 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 |
| string | The stringified form of the address |
Definition at line 63 of file netsock2.c.
References str, ast_sockaddr_isnull(), ast_str_thread_get(), ast_sockaddr_stringify_buf, ast_sockaddr_ipv4_mapped(), ast_sockaddr::ss, ast_sockaddr::len, AST_SOCKADDR_STR_ADDR, AST_SOCKADDR_STR_PORT, ast_log(), LOG_ERROR, AST_SOCKADDR_STR_REMOTE, ast_sockaddr_is_ipv6_link_local(), AST_SOCKADDR_STR_FORMAT_MASK, AST_SOCKADDR_STR_DEFAULT, ast_str_set(), AST_SOCKADDR_STR_HOST, and ast_str_buffer().
Referenced by _sip_show_peers(), ast_sockaddr_stringify(), ast_sockaddr_stringify_remote(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_addr_remote(), ast_sockaddr_stringify_host(), ast_sockaddr_stringify_host_remote(), and ast_sockaddr_stringify_port().
{
struct ast_sockaddr sa_ipv4;
const struct ast_sockaddr *sa_tmp;
char host[NI_MAXHOST];
char port[NI_MAXSERV];
struct ast_str *str;
int e;
static const size_t size = sizeof(host) - 1 + sizeof(port) - 1 + 4;
if (ast_sockaddr_isnull(sa)) {
return "(null)";
}
if (!(str = ast_str_thread_get(&ast_sockaddr_stringify_buf, size))) {
return "";
}
if (ast_sockaddr_ipv4_mapped(sa, &sa_ipv4)) {
sa_tmp = &sa_ipv4;
} else {
sa_tmp = sa;
}
if ((e = getnameinfo((struct sockaddr *)&sa_tmp->ss, sa_tmp->len,
format & AST_SOCKADDR_STR_ADDR ? host : NULL,
format & AST_SOCKADDR_STR_ADDR ? sizeof(host) : 0,
format & AST_SOCKADDR_STR_PORT ? port : 0,
format & AST_SOCKADDR_STR_PORT ? sizeof(port): 0,
NI_NUMERICHOST | NI_NUMERICSERV))) {
ast_log(LOG_ERROR, "getnameinfo(): %s\n", gai_strerror(e));
return "";
}
if ((format & AST_SOCKADDR_STR_REMOTE) == AST_SOCKADDR_STR_REMOTE) {
char *p;
if (ast_sockaddr_is_ipv6_link_local(sa) && (p = strchr(host, '%'))) {
*p = '\0';
}
}
switch ((format & AST_SOCKADDR_STR_FORMAT_MASK)) {
case AST_SOCKADDR_STR_DEFAULT:
ast_str_set(&str, 0, sa_tmp->ss.ss_family == AF_INET6 ?
"[%s]:%s" : "%s:%s", host, port);
break;
case AST_SOCKADDR_STR_ADDR:
ast_str_set(&str, 0, "%s", host);
break;
case AST_SOCKADDR_STR_HOST:
ast_str_set(&str, 0,
sa_tmp->ss.ss_family == AF_INET6 ? "[%s]" : "%s", host);
break;
case AST_SOCKADDR_STR_PORT:
ast_str_set(&str, 0, "%s", port);
break;
default:
ast_log(LOG_ERROR, "Invalid format\n");
return "";
}
return ast_str_buffer(str);
}
| static char* ast_sockaddr_stringify_host | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6).
Definition at line 263 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_HOST.
Referenced by peers_data_provider_get(), and reg_source_db().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_HOST);
}
| static char* ast_sockaddr_stringify_host_remote | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brackets for IPv6).
Definition at line 281 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_HOST_REMOTE.
Referenced by create_addr_from_peer(), build_callid_registry(), add_rpid(), initreqprep(), add_diversion_header(), transmit_notify_with_mwi(), sip_sanitized_host(), build_reply_digest(), and sip_poke_peer().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_HOST_REMOTE);
}
| static char* ast_sockaddr_stringify_port | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Definition at line 294 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_PORT.
Referenced by realtime_update_peer(), realtime_peer(), add_sdp(), register_verify(), and httpstatus_callback().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_PORT);
}
| static char* ast_sockaddr_stringify_remote | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition at line 219 of file netsock2.h.
References ast_sockaddr_stringify_fmt(), and AST_SOCKADDR_STR_DEFAULT_REMOTE.
Referenced by build_via(), generate_uri(), build_callid_pvt(), and build_contact().
{
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_DEFAULT_REMOTE);
}