#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... | |
#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. | |
#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. | |
void | _ast_sockaddr_from_sin (struct ast_sockaddr *addr, const struct sockaddr_in *sin, const char *file, int line, const char *func) |
int | _ast_sockaddr_to_sin (const struct ast_sockaddr *addr, struct sockaddr_in *sin, const char *file, int line, const char *func) |
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. |
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 641 of file netsock2.h.
Referenced by __ast_http_load(), __oh323_rtp_create(), apply_netmask(), ast_rtp_read(), ast_rtp_stun_request(), ast_sockaddr_ipv4_mapped(), auth_manager_http_callback(), auth_mxml_http_callback(), auth_rawman_http_callback(), authenticate(), check_access(), find_subchannel_and_lock(), gtalk_alloc(), gtalk_get_local_ip(), gtalk_update_externip(), gtalk_update_stun(), handle_open_receive_channel_ack_message(), jingle_alloc(), jingle_create_candidates(), jingle_update_stun(), load_module(), manager_http_callback(), mxml_http_callback(), parse_cidr_mask(), process_sdp(), rawman_http_callback(), register_verify(), setup_rtp_connection(), skinny_register(), start_rtp(), and update_registry().
#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 405 of file netsock2.h.
Referenced by __iax2_show_peers(), __set_address_from_contact(), __sip_subscribe_mwi_do(), _sip_show_peer(), _sip_show_peers(), add_sdp(), ast_find_ourip(), ast_ouraddrfor(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_sip_ouraddrfor(), build_peer(), check_via(), copy_via_headers(), create_addr(), dnsmgr_refresh(), function_sippeer(), get_our_media_address(), initreqprep(), manager_iax2_show_peer_list(), multicast_send_control_packet(), on_dns_update_peer(), on_dns_update_registry(), parse_register_contact(), peer_ipcmp_cb(), peers_data_provider_get(), realtime_update_peer(), set_destination(), sip_debug_test_addr(), sip_request_call(), sipsock_read(), transmit_notify_with_mwi(), transmit_register(), 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 421 of file netsock2.h.
Referenced by __set_address_from_contact(), __sip_subscribe_mwi_do(), add_sdp(), ast_find_ourip(), ast_get_ip_or_srv(), ast_ouraddrfor(), ast_rtp_new(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_sip_ouraddrfor(), ast_udptl_new_with_bindaddr(), build_peer(), check_via(), check_via_response(), create_addr(), dnsmgr_refresh(), get_our_media_address(), iax2_append_register(), on_dns_update_peer(), on_dns_update_registry(), parse_register_contact(), process_sdp(), process_via(), proxy_update(), set_destination(), sip_request_call(), stun_monitor_request(), and transmit_register().
#define AST_SOCKADDR_STR_ADDR (1 << 0) |
Definition at line 152 of file netsock2.h.
Referenced by ast_sockaddr_stringify_addr(), and ast_sockaddr_stringify_fmt().
#define AST_SOCKADDR_STR_ADDR_REMOTE (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_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(), and ast_sockaddr_stringify_fmt().
#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) |
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) |
#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) |
#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.
addr | The ast_sockaddr to convert | |
[out] | sin | The resulting sockaddr_in struct |
nonzero | Success | |
zero | Failure |
Definition at line 628 of file netsock2.h.
Referenced by __iax2_show_peers(), add_sdp(), addr_range_hash_cb(), addr_range_match_address_cb(), ast_rtp_read(), ast_rtp_stun_request(), auth_manager_http_callback(), auth_mxml_http_callback(), auth_rawman_http_callback(), authenticate_reply(), build_peer(), build_user(), config_parse_variables(), create_addr(), external_rtp_create(), find_subchannel_and_lock(), gtalk_create_candidates(), gtalk_update_stun(), handle_cli_iax2_set_debug(), handle_cli_iax2_show_peer(), handle_open_receive_channel_ack_message(), handle_show_http(), iax2_ack_registry(), iax2_do_register(), iax2_getpeername(), iax2_getpeertrunk(), iax2_poke_peer(), jingle_create_candidates(), manager_http_callback(), mansession_encode_sin_local(), mxml_http_callback(), oh323_set_rtp_peer(), peer_set_srcaddr(), peercnt_modify(), rawman_http_callback(), registry_rerequest(), session_do(), skinny_set_rtp_peer(), start_rtp(), transmit_modify_with_sdp(), and update_registry().
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.
00039 { 00040 AST_AF_UNSPEC = 0, 00041 AST_AF_INET = 2, 00042 AST_AF_INET6 = 10, 00043 };
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 __LOG_DEBUG, ast_log(), ast_sockaddr::len, option_debug, and ast_sockaddr::ss.
00553 { 00554 memcpy(&addr->ss, sin, sizeof(*sin)); 00555 00556 if (addr->ss.ss_family != AF_INET && option_debug >= 1) { 00557 ast_log(__LOG_DEBUG, file, line, func, "Address family is not AF_INET\n"); 00558 } 00559 00560 addr->len = sizeof(*sin); 00561 }
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 __LOG_DEBUG, ast_log(), ast_sockaddr::len, option_debug, and ast_sockaddr::ss.
00356 { 00357 if (addr->ss.ss_family == AF_INET && 00358 addr->len == sizeof(struct sockaddr_in)) { 00359 return ntohs(((struct sockaddr_in *)&addr->ss)->sin_port); 00360 } else if (addr->ss.ss_family == AF_INET6 && 00361 addr->len == sizeof(struct sockaddr_in6)) { 00362 return ntohs(((struct sockaddr_in6 *)&addr->ss)->sin6_port); 00363 } 00364 if (option_debug >= 1) { 00365 ast_log(__LOG_DEBUG, file, line, func, "Not an IPv4 nor IPv6 address, cannot get port.\n"); 00366 } 00367 return 0; 00368 }
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 __LOG_DEBUG, ast_log(), ast_sockaddr::len, option_debug, and ast_sockaddr::ss.
00371 { 00372 if (addr->ss.ss_family == AF_INET && 00373 addr->len == sizeof(struct sockaddr_in)) { 00374 ((struct sockaddr_in *)&addr->ss)->sin_port = htons(port); 00375 } else if (addr->ss.ss_family == AF_INET6 && 00376 addr->len == sizeof(struct sockaddr_in6)) { 00377 ((struct sockaddr_in6 *)&addr->ss)->sin6_port = htons(port); 00378 } else if (option_debug >= 1) { 00379 ast_log(__LOG_DEBUG, file, line, func, 00380 "Not an IPv4 nor IPv6 address, cannot set port.\n"); 00381 } 00382 }
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 __LOG_DEBUG, __LOG_ERROR, ast_log(), ast_sockaddr_isnull(), ast_sockaddr::len, option_debug, and ast_sockaddr::ss.
00532 { 00533 if (ast_sockaddr_isnull(addr)) { 00534 memset(sin, 0, sizeof(*sin)); 00535 return 1; 00536 } 00537 00538 if (addr->len != sizeof(*sin)) { 00539 ast_log(__LOG_ERROR, file, line, func, "Bad address cast to IPv4\n"); 00540 return 0; 00541 } 00542 00543 if (addr->ss.ss_family != AF_INET && option_debug >= 1) { 00544 ast_log(__LOG_DEBUG, file, line, func, "Address family is not AF_INET\n"); 00545 } 00546 00547 *sin = *(struct sockaddr_in *)&addr->ss; 00548 return 1; 00549 }
int ast_accept | ( | int | sockfd, | |
struct ast_sockaddr * | addr | |||
) |
Wrapper around accept(2) that uses struct ast_sockaddr.
Definition at line 446 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by ast_tcptls_server_root().
00447 { 00448 addr->len = sizeof(addr->ss); 00449 return accept(sockfd, (struct sockaddr *)&addr->ss, &addr->len); 00450 }
int ast_bind | ( | int | sockfd, | |
const struct ast_sockaddr * | addr | |||
) |
Wrapper around bind(2) that uses struct ast_sockaddr.
Definition at line 452 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by 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.
Definition at line 457 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by ast_ouraddrfor(), ast_tcptls_client_start(), gtalk_update_externip(), and stun_monitor_request().
int ast_getsockname | ( | int | sockfd, | |
struct ast_sockaddr * | addr | |||
) |
Wrapper around getsockname(2) that uses struct ast_sockaddr.
Definition at line 462 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by ast_ouraddrfor(), and ast_set_qos().
00463 { 00464 addr->len = sizeof(addr->ss); 00465 return getsockname(sockfd, (struct sockaddr *)&addr->ss, &addr->len); 00466 }
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.
Definition at line 468 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by __rtp_recvfrom(), ast_udptl_read(), and sipsock_read().
00470 { 00471 src_addr->len = sizeof(src_addr->ss); 00472 return recvfrom(sockfd, buf, len, flags, 00473 (struct sockaddr *)&src_addr->ss, &src_addr->len); 00474 }
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.
Definition at line 476 of file netsock2.c.
References ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by __rtp_sendto(), __sip_xmit(), ast_udptl_write(), multicast_rtp_write(), and multicast_send_control_packet().
00478 { 00479 return sendto(sockfd, buf, len, flags, 00480 (const struct sockaddr *)&dest_addr->ss, dest_addr->len); 00481 }
int ast_set_qos | ( | int | sockfd, | |
int | tos, | |||
int | cos, | |||
const char * | desc | |||
) |
Set type of service.
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_log(), ast_sockaddr_is_any(), ast_sockaddr_is_ipv6(), ast_verb, errno, and LOG_WARNING.
Referenced by ast_rtp_qos_set().
00484 { 00485 int res = 0; 00486 int set_tos; 00487 int set_tclass; 00488 struct ast_sockaddr addr; 00489 00490 /* If the sock address is IPv6, the TCLASS field must be set. */ 00491 set_tclass = !ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr) ? 1 : 0; 00492 00493 /* If the the sock address is IPv4 or (IPv6 set to any address [::]) set TOS bits */ 00494 set_tos = (!set_tclass || (set_tclass && ast_sockaddr_is_any(&addr))) ? 1 : 0; 00495 00496 if (set_tos) { 00497 if ((res = setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) { 00498 ast_log(LOG_WARNING, "Unable to set %s DSCP TOS value to %d (may be you have no " 00499 "root privileges): %s\n", desc, tos, strerror(errno)); 00500 } else if (tos) { 00501 ast_verb(2, "Using %s TOS bits %d\n", desc, tos); 00502 } 00503 } 00504 00505 #if defined(IPV6_TCLASS) && defined(IPPROTO_IPV6) 00506 if (set_tclass) { 00507 if (!ast_getsockname(sockfd, &addr) && ast_sockaddr_is_ipv6(&addr)) { 00508 if ((res = setsockopt(sockfd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)))) { 00509 ast_log(LOG_WARNING, "Unable to set %s DSCP TCLASS field to %d (may be you have no " 00510 "root privileges): %s\n", desc, tos, strerror(errno)); 00511 } else if (tos) { 00512 ast_verb(2, "Using %s TOS bits %d in TCLASS field.\n", desc, tos); 00513 } 00514 } 00515 } 00516 #endif 00517 00518 #ifdef linux 00519 if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos))) { 00520 ast_log(LOG_WARNING, "Unable to set %s CoS to %d: %s\n", desc, cos, 00521 strerror(errno)); 00522 } else if (cos) { 00523 ast_verb(2, "Using %s CoS mark %d\n", desc, cos); 00524 } 00525 #endif 00526 00527 return res; 00528 }
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_ipv4_mapped(), ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by add_sdp(), ast_rtcp_read(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_and_cmp_remote_address(), ast_rtp_read(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_bridge(), ast_udptl_read(), dnsmgr_refresh(), parse_register_contact(), realtime_peer_by_name(), remote_bridge_loop(), rtcp_debug_test_addr(), rtp_debug_test_addr(), sip_debug_test_addr(), sip_uri_domain_cmp(), threadinfo_locate_cb(), transmit_register(), udptl_debug_test_addr(), and update_registry().
00291 { 00292 const struct ast_sockaddr *a_tmp, *b_tmp; 00293 struct ast_sockaddr ipv4_mapped; 00294 00295 a_tmp = a; 00296 b_tmp = b; 00297 00298 if (a_tmp->len != b_tmp->len) { 00299 if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) { 00300 a_tmp = &ipv4_mapped; 00301 } else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) { 00302 b_tmp = &ipv4_mapped; 00303 } 00304 } 00305 00306 if (a_tmp->len < b_tmp->len) { 00307 return -1; 00308 } else if (a_tmp->len > b_tmp->len) { 00309 return 1; 00310 } 00311 00312 return memcmp(&a_tmp->ss, &b_tmp->ss, a_tmp->len); 00313 }
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_ipv4_mapped(), ast_sockaddr::len, and ast_sockaddr::ss.
Referenced by addr_range_cmp_cb(), ast_apply_ha(), get_our_media_address(), peer_ipcmp_cb(), rtcp_debug_test_addr(), rtp_debug_test_addr(), sip_debug_test_addr(), and udptl_debug_test_addr().
00316 { 00317 const struct ast_sockaddr *a_tmp, *b_tmp; 00318 struct ast_sockaddr ipv4_mapped; 00319 const struct in_addr *ip4a, *ip4b; 00320 const struct in6_addr *ip6a, *ip6b; 00321 int ret = -1; 00322 00323 a_tmp = a; 00324 b_tmp = b; 00325 00326 if (a_tmp->len != b_tmp->len) { 00327 if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) { 00328 a_tmp = &ipv4_mapped; 00329 } else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) { 00330 b_tmp = &ipv4_mapped; 00331 } 00332 } 00333 00334 if (a->len < b->len) { 00335 ret = -1; 00336 } else if (a->len > b->len) { 00337 ret = 1; 00338 } 00339 00340 switch (a_tmp->ss.ss_family) { 00341 case AF_INET: 00342 ip4a = &((const struct sockaddr_in*)&a_tmp->ss)->sin_addr; 00343 ip4b = &((const struct sockaddr_in*)&b_tmp->ss)->sin_addr; 00344 ret = memcmp(ip4a, ip4b, sizeof(*ip4a)); 00345 break; 00346 case AF_INET6: 00347 ip6a = &((const struct sockaddr_in6*)&a_tmp->ss)->sin6_addr; 00348 ip6b = &((const struct sockaddr_in6*)&b_tmp->ss)->sin6_addr; 00349 ret = memcmp(ip6a, ip6b, sizeof(*ip6a)); 00350 break; 00351 } 00352 return ret; 00353 }
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 add_sdp(), ast_copy_ha(), ast_find_ourip(), ast_rtcp_read(), ast_rtp_alt_remote_address_set(), ast_rtp_instance_get_and_cmp_local_address(), ast_rtp_instance_get_and_cmp_remote_address(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_remote_address(), ast_rtp_instance_new(), ast_rtp_instance_set_alt_remote_address(), ast_rtp_instance_set_local_address(), ast_rtp_instance_set_remote_address(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_sip_ouraddrfor(), ast_sockaddr_resolve_first_af(), ast_tcptls_client_create(), ast_tcptls_server_root(), ast_tcptls_server_start(), ast_udptl_bridge(), ast_udptl_get_peer(), ast_udptl_get_us(), ast_udptl_new_with_bindaddr(), ast_udptl_read(), ast_udptl_set_peer(), create_addr(), dialog_initialize_rtp(), dnsmgr_refresh(), find_peer(), get_our_media_address(), gtalk_get_local_ip(), handle_cli_udptl_set_debug(), handle_request_do(), on_dns_update_mwi(), on_dns_update_peer(), on_dns_update_registry(), parse_register_contact(), reg_source_db(), remote_bridge_loop(), resolve_first(), sip_alloc(), sip_do_debug_peer(), sip_prepare_socket(), and transmit_response_using_temp().
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_log(), LOG_ERROR, and ast_sockaddr::ss.
Referenced by peer_iphash_cb(), and threadt_hash_cb().
00429 { 00430 /* 00431 * For IPv4, return the IP address as-is. For IPv6, return the last 32 00432 * bits. 00433 */ 00434 switch (addr->ss.ss_family) { 00435 case AF_INET: 00436 return ((const struct sockaddr_in *)&addr->ss)->sin_addr.s_addr; 00437 case AF_INET6: 00438 return ((uint32_t *)&((const struct sockaddr_in6 *)&addr->ss)->sin6_addr)[3]; 00439 default: 00440 ast_log(LOG_ERROR, "Unknown address family '%d'.\n", 00441 addr->ss.ss_family); 00442 return 0; 00443 } 00444 }
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 addr_is_multicast(), iax2_devicestate(), iax2_do_register(), iax2_poke_peer(), jingle_create_candidates(), load_module(), and multicast_send_control_packet().
00385 { 00386 const struct sockaddr_in *sin = (struct sockaddr_in *)&addr->ss; 00387 return ntohl(sin->sin_addr.s_addr); 00388 }
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_from_sin, ast_sockaddr_is_ipv4_mapped(), ast_sockaddr_is_ipv6(), and ast_sockaddr::ss.
Referenced by ast_append_ha(), ast_apply_ha(), ast_rtp_read(), ast_sockaddr_cmp(), ast_sockaddr_cmp_addr(), and ast_sockaddr_stringify_fmt().
00036 { 00037 const struct sockaddr_in6 *sin6; 00038 struct sockaddr_in sin4; 00039 00040 if (!ast_sockaddr_is_ipv6(addr)) { 00041 return 0; 00042 } 00043 00044 if (!ast_sockaddr_is_ipv4_mapped(addr)) { 00045 return 0; 00046 } 00047 00048 sin6 = (const struct sockaddr_in6*)&addr->ss; 00049 00050 memset(&sin4, 0, sizeof(sin4)); 00051 sin4.sin_family = AF_INET; 00052 sin4.sin_port = sin6->sin6_port; 00053 sin4.sin_addr.s_addr = ((uint32_t *)&sin6->sin6_addr)[3]; 00054 00055 ast_sockaddr_from_sin(ast_mapped, &sin4); 00056 00057 return 1; 00058 }
int ast_sockaddr_is_any | ( | const struct ast_sockaddr * | addr | ) |
Determine if the address type is unspecified, or "any" address.
1 | This is an "any" address | |
0 | This is not an "any" address |
Definition at line 414 of file netsock2.c.
References ast_sockaddr_is_ipv4(), ast_sockaddr_is_ipv6(), and ast_sockaddr::ss.
Referenced by ast_find_ourip(), ast_set_qos(), ast_sip_ouraddrfor(), get_address_family_filter(), get_our_media_address(), gtalk_get_local_ip(), sip_show_settings(), and sockaddr_is_null_or_any().
00415 { 00416 union { 00417 struct sockaddr_storage ss; 00418 struct sockaddr_in sin; 00419 struct sockaddr_in6 sin6; 00420 } tmp_addr = { 00421 .ss = addr->ss, 00422 }; 00423 00424 return (ast_sockaddr_is_ipv4(addr) && (tmp_addr.sin.sin_addr.s_addr == INADDR_ANY)) || 00425 (ast_sockaddr_is_ipv6(addr) && IN6_IS_ADDR_UNSPECIFIED(&tmp_addr.sin6.sin6_addr)); 00426 }
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::len, and ast_sockaddr::ss.
Referenced by apply_netmask(), ast_append_ha(), ast_apply_ha(), ast_rtp_new(), ast_rtp_prop_set(), ast_rtp_read(), and ast_sockaddr_is_any().
00391 { 00392 return addr->ss.ss_family == AF_INET && 00393 addr->len == sizeof(struct sockaddr_in); 00394 }
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::len, and ast_sockaddr::ss.
Referenced by add_sdp(), ast_apply_ha(), ast_rtp_instance_bridge(), and ast_sockaddr_ipv4_mapped().
00397 { 00398 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&addr->ss; 00399 return addr->len && IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr); 00400 }
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::len, and ast_sockaddr::ss.
Referenced by add_sdp(), apply_netmask(), ast_apply_ha(), ast_ouraddrfor(), ast_rtp_new(), ast_rtp_prop_set(), ast_set_qos(), ast_sip_ouraddrfor(), ast_sockaddr_ipv4_mapped(), ast_sockaddr_is_any(), ast_sockaddr_is_ipv6_link_local(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_new_with_bindaddr(), get_address_family_filter(), multicast_send_control_packet(), and sip_show_settings().
00409 { 00410 return addr->ss.ss_family == AF_INET6 && 00411 addr->len == sizeof(struct sockaddr_in6); 00412 }
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_is_ipv6(), and ast_sockaddr::ss.
Referenced by ast_sockaddr_stringify_fmt().
00403 { 00404 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&addr->ss; 00405 return ast_sockaddr_is_ipv6(addr) && IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr); 00406 }
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 _ast_sockaddr_to_sin(), _sip_show_peers(), add_sdp(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_sendcng(), ast_rtp_write(), ast_sip_ouraddrfor(), ast_sockaddr_stringify_fmt(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_read(), ast_udptl_write(), bridge_p2p_rtp_write(), build_peer(), check_rtp_timeout(), create_addr(), create_addr_from_peer(), expire_register(), get_our_media_address(), multicast_send_control_packet(), on_dns_update_mwi(), on_dns_update_peer(), on_dns_update_registry(), parse_register_contact(), peer_iphash_cb(), process_sdp(), register_verify(), remote_bridge_loop(), rtcp_debug_test_addr(), rtp_debug_test_addr(), sip_acf_channel_read(), sip_debug_test_addr(), sip_devicestate(), sip_do_debug_peer(), sip_poke_peer(), sip_prune_realtime(), sip_send_mwi_to_peer(), sip_set_rtp_peer(), sip_show_channel(), sip_show_settings(), sockaddr_is_null_or_any(), transmit_register(), udptl_debug_test_addr(), and unlink_peer_from_tables().
00094 { 00095 return !addr || addr->len == 0; 00096 }
int ast_sockaddr_parse | ( | struct ast_sockaddr * | addr, | |
const char * | str, | |||
int | flags | |||
) |
Parse an IPv4 or IPv6 address string.
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_log(), ast_sockaddr_split_hostport(), ast_strdupa, ast_sockaddr::len, LOG_ERROR, LOG_WARNING, S_OR, and ast_sockaddr::ss.
Referenced by ast_append_ha(), ast_parse_arg(), build_peer(), internal_dnsmgr_lookup(), multicast_rtp_request(), proxy_update(), reg_source_db(), reload_config(), rtcp_do_debug_ip(), rtp_do_debug_ip(), sip_sanitized_host(), and sip_uri_domain_cmp().
00195 { 00196 struct addrinfo hints; 00197 struct addrinfo *res; 00198 char *s; 00199 char *host; 00200 char *port; 00201 int e; 00202 00203 s = ast_strdupa(str); 00204 if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) { 00205 return 0; 00206 } 00207 00208 memset(&hints, 0, sizeof(hints)); 00209 /* Hint to get only one entry from getaddrinfo */ 00210 hints.ai_socktype = SOCK_DGRAM; 00211 00212 #ifdef AI_NUMERICSERV 00213 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; 00214 #else 00215 hints.ai_flags = AI_NUMERICHOST; 00216 #endif 00217 if ((e = getaddrinfo(host, port, &hints, &res))) { 00218 if (e != EAI_NONAME) { /* if this was just a host name rather than a ip address, don't print error */ 00219 ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n", 00220 host, S_OR(port, "(null)"), gai_strerror(e)); 00221 } 00222 return 0; 00223 } 00224 00225 /* 00226 * I don't see how this could be possible since we're not resolving host 00227 * names. But let's be careful... 00228 */ 00229 if (res->ai_next != NULL) { 00230 ast_log(LOG_WARNING, "getaddrinfo() returned multiple " 00231 "addresses. Ignoring all but the first.\n"); 00232 } 00233 00234 addr->len = res->ai_addrlen; 00235 memcpy(&addr->ss, res->ai_addr, addr->len); 00236 00237 freeaddrinfo(res); 00238 00239 return 1; 00240 }
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.
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_log(), ast_malloc, ast_sockaddr_split_hostport(), ast_strdupa, cleanup(), len(), LOG_ERROR, and S_OR.
Referenced by ast_sockaddr_resolve_first_af(), gtalk_get_local_ip(), handle_cli_udptl_set_debug(), realtime_peer_by_name(), and resolve_first().
00244 { 00245 struct addrinfo hints, *res, *ai; 00246 char *s, *host, *port; 00247 int e, i, res_cnt; 00248 00249 if (!str) { 00250 return 0; 00251 } 00252 00253 s = ast_strdupa(str); 00254 if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) { 00255 return 0; 00256 } 00257 00258 memset(&hints, 0, sizeof(hints)); 00259 hints.ai_family = family; 00260 hints.ai_socktype = SOCK_DGRAM; 00261 00262 if ((e = getaddrinfo(host, port, &hints, &res))) { 00263 ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n", 00264 host, S_OR(port, "(null)"), gai_strerror(e)); 00265 return 0; 00266 } 00267 00268 res_cnt = 0; 00269 for (ai = res; ai; ai = ai->ai_next) { 00270 res_cnt++; 00271 } 00272 00273 if ((*addrs = ast_malloc(res_cnt * sizeof(struct ast_sockaddr))) == NULL) { 00274 res_cnt = 0; 00275 goto cleanup; 00276 } 00277 00278 i = 0; 00279 for (ai = res; ai; ai = ai->ai_next) { 00280 (*addrs)[i].len = ai->ai_addrlen; 00281 memcpy(&(*addrs)[i].ss, ai->ai_addr, ai->ai_addrlen); 00282 ++i; 00283 } 00284 00285 cleanup: 00286 freeaddrinfo(res); 00287 return res_cnt; 00288 }
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 ast_rtp_stop(), ast_tcptls_client_create(), ast_tcptls_server_start(), ast_udptl_stop(), build_peer(), multicast_rtp_request(), and set_peer_defaults().
00107 { 00108 addr->len = 0; 00109 }
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 ast_debug, ast_log(), LOG_WARNING, PARSE_PORT_FORBID, PARSE_PORT_IGNORE, PARSE_PORT_MASK, and PARSE_PORT_REQUIRE.
Referenced by ast_sockaddr_parse(), ast_sockaddr_resolve(), extract_host_from_hostport(), rtcp_do_debug_ip(), rtp_do_debug_ip(), setup_stunaddr(), and sip_parse_host().
00129 { 00130 char *s = str; 00131 char *orig_str = str;/* Original string in case the port presence is incorrect. */ 00132 char *host_end = NULL;/* Delay terminating the host in case the port presence is incorrect. */ 00133 00134 ast_debug(5, "Splitting '%s' into...\n", str); 00135 *host = NULL; 00136 *port = NULL; 00137 if (*s == '[') { 00138 *host = ++s; 00139 for (; *s && *s != ']'; ++s) { 00140 } 00141 if (*s == ']') { 00142 host_end = s; 00143 ++s; 00144 } 00145 if (*s == ':') { 00146 *port = s + 1; 00147 } 00148 } else { 00149 *host = s; 00150 for (; *s; ++s) { 00151 if (*s == ':') { 00152 if (*port) { 00153 *port = NULL; 00154 break; 00155 } else { 00156 *port = s; 00157 } 00158 } 00159 } 00160 if (*port) { 00161 host_end = *port; 00162 ++*port; 00163 } 00164 } 00165 00166 switch (flags & PARSE_PORT_MASK) { 00167 case PARSE_PORT_IGNORE: 00168 *port = NULL; 00169 break; 00170 case PARSE_PORT_REQUIRE: 00171 if (*port == NULL) { 00172 ast_log(LOG_WARNING, "Port missing in %s\n", orig_str); 00173 return 0; 00174 } 00175 break; 00176 case PARSE_PORT_FORBID: 00177 if (*port != NULL) { 00178 ast_log(LOG_WARNING, "Port disallowed in %s\n", orig_str); 00179 return 0; 00180 } 00181 break; 00182 } 00183 00184 /* Can terminate the host string now if needed. */ 00185 if (host_end) { 00186 *host_end = '\0'; 00187 } 00188 ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port ? *port : ""); 00189 return 1; 00190 }
static char* ast_sockaddr_stringify | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition at line 210 of file netsock2.h.
References AST_SOCKADDR_STR_DEFAULT, and ast_sockaddr_stringify_fmt().
Referenced by __sip_xmit(), _sip_show_peer(), add_sdp(), apply_directmedia_ha(), ast_append_ha(), ast_parse_arg(), ast_rtcp_read(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_sendcng(), ast_sip_ouraddrfor(), ast_tcptls_client_create(), ast_tcptls_client_start(), ast_tcptls_server_start(), ast_udptl_bridge(), ast_udptl_read(), ast_udptl_write(), bridge_p2p_rtp_write(), check_peer_ok(), check_via(), create_dtmf_frame(), dnsmgr_refresh(), gtalk_update_externip(), handle_cli_iax2_show_registry(), handle_cli_udptl_set_debug(), handle_incoming(), handle_manager_show_settings(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_info(), handle_response_message(), handle_response_notify(), handle_response_refer(), manager_iax2_show_registry(), multicast_rtp_write(), on_dns_update_mwi(), on_dns_update_peer(), on_dns_update_registry(), parse_register_contact(), process_cn_rfc3389(), process_dtmf_rfc2833(), process_sdp(), reg_source_db(), register_verify(), remote_bridge_loop(), retrans_pkt(), rtcp_do_debug_ip(), rtp_do_debug_ip(), send_request(), send_response(), set_destination(), sip_acf_channel_read(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_show_channel(), sip_show_settings(), sip_show_tcp(), and stun_monitor_request().
00211 { 00212 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_DEFAULT); 00213 }
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 240 of file netsock2.h.
References AST_SOCKADDR_STR_ADDR, and ast_sockaddr_stringify_fmt().
Referenced by __iax2_show_peers(), _sip_show_peer(), _sip_show_peers(), add_sdp(), ast_ouraddrfor(), build_peer(), function_iaxpeer(), function_sipchaninfo_read(), function_sippeer(), gtalk_create_candidates(), httpstatus_callback(), manager_iax2_show_peer_list(), parse_register_contact(), realtime_peer(), realtime_update_peer(), register_verify(), show_channels_cb(), show_chanstats_cb(), sip_acf_channel_read(), sip_do_debug_ip(), sip_do_debug_peer(), sip_show_channel(), and sip_show_settings().
00241 { 00242 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_ADDR); 00243 }
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 257 of file netsock2.h.
References AST_SOCKADDR_STR_ADDR_REMOTE, and ast_sockaddr_stringify_fmt().
Referenced by add_sdp(), and copy_via_headers().
00258 { 00259 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_ADDR_REMOTE); 00260 }
char* ast_sockaddr_stringify_fmt | ( | const struct ast_sockaddr * | addr, | |
int | format | |||
) |
Convert a socket address to a string.
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 ast_log(), ast_sockaddr_ipv4_mapped(), ast_sockaddr_is_ipv6_link_local(), ast_sockaddr_isnull(), AST_SOCKADDR_STR_ADDR, AST_SOCKADDR_STR_DEFAULT, AST_SOCKADDR_STR_FORMAT_MASK, AST_SOCKADDR_STR_HOST, AST_SOCKADDR_STR_PORT, AST_SOCKADDR_STR_REMOTE, ast_sockaddr_stringify_buf, ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_sockaddr::len, LOG_ERROR, ast_sockaddr::ss, and str.
Referenced by _sip_show_peers(), 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(), and ast_sockaddr_stringify_remote().
00064 { 00065 struct ast_sockaddr sa_ipv4; 00066 const struct ast_sockaddr *sa_tmp; 00067 char host[NI_MAXHOST]; 00068 char port[NI_MAXSERV]; 00069 struct ast_str *str; 00070 int e; 00071 static const size_t size = sizeof(host) - 1 + sizeof(port) - 1 + 4; 00072 00073 00074 if (ast_sockaddr_isnull(sa)) { 00075 return "(null)"; 00076 } 00077 00078 if (!(str = ast_str_thread_get(&ast_sockaddr_stringify_buf, size))) { 00079 return ""; 00080 } 00081 00082 if (ast_sockaddr_ipv4_mapped(sa, &sa_ipv4)) { 00083 sa_tmp = &sa_ipv4; 00084 } else { 00085 sa_tmp = sa; 00086 } 00087 00088 if ((e = getnameinfo((struct sockaddr *)&sa_tmp->ss, sa_tmp->len, 00089 format & AST_SOCKADDR_STR_ADDR ? host : NULL, 00090 format & AST_SOCKADDR_STR_ADDR ? sizeof(host) : 0, 00091 format & AST_SOCKADDR_STR_PORT ? port : 0, 00092 format & AST_SOCKADDR_STR_PORT ? sizeof(port): 0, 00093 NI_NUMERICHOST | NI_NUMERICSERV))) { 00094 ast_log(LOG_ERROR, "getnameinfo(): %s\n", gai_strerror(e)); 00095 return ""; 00096 } 00097 00098 if ((format & AST_SOCKADDR_STR_REMOTE) == AST_SOCKADDR_STR_REMOTE) { 00099 char *p; 00100 if (ast_sockaddr_is_ipv6_link_local(sa) && (p = strchr(host, '%'))) { 00101 *p = '\0'; 00102 } 00103 } 00104 00105 switch ((format & AST_SOCKADDR_STR_FORMAT_MASK)) { 00106 case AST_SOCKADDR_STR_DEFAULT: 00107 ast_str_set(&str, 0, sa_tmp->ss.ss_family == AF_INET6 ? 00108 "[%s]:%s" : "%s:%s", host, port); 00109 break; 00110 case AST_SOCKADDR_STR_ADDR: 00111 ast_str_set(&str, 0, "%s", host); 00112 break; 00113 case AST_SOCKADDR_STR_HOST: 00114 ast_str_set(&str, 0, 00115 sa_tmp->ss.ss_family == AF_INET6 ? "[%s]" : "%s", host); 00116 break; 00117 case AST_SOCKADDR_STR_PORT: 00118 ast_str_set(&str, 0, "%s", port); 00119 break; 00120 default: 00121 ast_log(LOG_ERROR, "Invalid format\n"); 00122 return ""; 00123 } 00124 00125 return ast_str_buffer(str); 00126 }
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 271 of file netsock2.h.
References AST_SOCKADDR_STR_HOST, and ast_sockaddr_stringify_fmt().
Referenced by peers_data_provider_get(), and reg_source_db().
00272 { 00273 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_HOST); 00274 }
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 289 of file netsock2.h.
References AST_SOCKADDR_STR_HOST_REMOTE, and ast_sockaddr_stringify_fmt().
Referenced by add_diversion_header(), add_rpid(), build_callid_registry(), build_reply_digest(), create_addr_from_peer(), initreqprep(), sip_poke_peer(), sip_sanitized_host(), and transmit_notify_with_mwi().
00290 { 00291 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_HOST_REMOTE); 00292 }
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 302 of file netsock2.h.
References AST_SOCKADDR_STR_PORT, and ast_sockaddr_stringify_fmt().
Referenced by add_sdp(), httpstatus_callback(), realtime_peer_by_addr(), realtime_update_peer(), and register_verify().
00303 { 00304 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_PORT); 00305 }
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 227 of file netsock2.h.
References AST_SOCKADDR_STR_DEFAULT_REMOTE, and ast_sockaddr_stringify_fmt().
Referenced by build_callid_pvt(), build_contact(), build_via(), and generate_uri().
00228 { 00229 return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_DEFAULT_REMOTE); 00230 }