本文整理汇总了C++中pj_sockaddr_get_addr函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_sockaddr_get_addr函数的具体用法?C++ pj_sockaddr_get_addr怎么用?C++ pj_sockaddr_get_addr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_sockaddr_get_addr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PJ_DEF
/* Get the default IP interface */
PJ_DEF(pj_status_t) pj_getdefaultipinterface(int af, pj_sockaddr *addr)
{
pj_sock_t fd;
pj_str_t cp;
pj_sockaddr a;
int len;
pj_uint8_t zero[64];
pj_status_t status;
addr->addr.sa_family = (pj_uint16_t)af;
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &fd);
if (status != PJ_SUCCESS) {
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_socket."));
if (af == PJ_AF_INET) {
cp = pj_str("1.1.1.1");
} else {
cp = pj_str("1::1");
}
status = pj_sockaddr_init(af, &a, &cp, 53);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sockaddr_init."));
status = pj_sock_connect(fd, &a, pj_sockaddr_get_len(&a));
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_connect."));
len = sizeof(a);
status = pj_sock_getsockname(fd, &a, &len);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_getsockname."));
pj_sock_close(fd);
/* Check that the address returned is not zero */
pj_bzero(zero, sizeof(zero));
if (pj_memcmp(pj_sockaddr_get_addr(&a), zero,
pj_sockaddr_get_addr_len(&a))==0)
{
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() interface not found."));
return PJ_ENOTFOUND;
}
pj_sockaddr_copy_addr(addr, &a);
/* Success */
return PJ_SUCCESS;
}
示例2: pj_inet_ntop
static const char *addr_string(const pj_sockaddr_t *addr)
{
static char str[PJ_INET6_ADDRSTRLEN];
pj_inet_ntop(((const pj_sockaddr*)addr)->addr.sa_family,
pj_sockaddr_get_addr(addr),
str, sizeof(str));
return str;
}
示例3: PJ_DEF
/* Start socket. */
PJ_DEF(pj_status_t) pj_stun_sock_start( pj_stun_sock *stun_sock,
const pj_str_t *domain,
pj_uint16_t default_port,
pj_dns_resolver *resolver)
{
pj_status_t status;
PJ_ASSERT_RETURN(stun_sock && domain && default_port, PJ_EINVAL);
/* Check whether the domain contains IP address */
stun_sock->srv_addr.addr.sa_family = (pj_uint16_t)stun_sock->af;
status = pj_inet_pton(stun_sock->af, domain,
pj_sockaddr_get_addr(&stun_sock->srv_addr));
if (status != PJ_SUCCESS) {
stun_sock->srv_addr.addr.sa_family = (pj_uint16_t)0;
}
/* If resolver is set, try to resolve with DNS SRV first. It
* will fallback to DNS A/AAAA when no SRV record is found.
*/
if (status != PJ_SUCCESS && resolver) {
const pj_str_t res_name = pj_str("_stun._udp.");
unsigned opt;
pj_assert(stun_sock->q == NULL);
opt = PJ_DNS_SRV_FALLBACK_A;
if (stun_sock->af == pj_AF_INET6()) {
opt |= (PJ_DNS_SRV_RESOLVE_AAAA | PJ_DNS_SRV_FALLBACK_AAAA);
}
status = pj_dns_srv_resolve(domain, &res_name, default_port,
stun_sock->pool, resolver, opt,
stun_sock, &dns_srv_resolver_cb,
&stun_sock->q);
/* Processing will resume when the DNS SRV callback is called */
return status;
} else {
if (status != PJ_SUCCESS) {
pj_addrinfo ai;
unsigned cnt = 1;
status = pj_getaddrinfo(stun_sock->af, domain, &cnt, &ai);
if (status != PJ_SUCCESS)
return status;
pj_sockaddr_cp(&stun_sock->srv_addr, &ai.ai_addr);
}
pj_sockaddr_set_port(&stun_sock->srv_addr, (pj_uint16_t)default_port);
/* Start sending Binding request */
return get_mapped_addr(stun_sock);
}
}
示例4: lookup_permission_by_addr
/* Lookup permission in hash table by the peer address */
static pj_turn_permission*
lookup_permission_by_addr(pj_turn_allocation *alloc,
const pj_sockaddr_t *peer_addr,
unsigned addr_len)
{
pj_turn_permission *perm;
PJ_UNUSED_ARG(addr_len);
/* Lookup in peer hash table */
perm = (pj_turn_permission*)
pj_hash_get(alloc->peer_table,
pj_sockaddr_get_addr(peer_addr),
pj_sockaddr_get_addr_len(peer_addr),
NULL);
return perm ? check_permission_expiry(perm) : NULL;
}
示例5: PJ_POOL_ZALLOC_T
/* Create new permission */
static pj_turn_permission *create_permission(pj_turn_allocation *alloc,
const pj_sockaddr_t *peer_addr,
unsigned addr_len)
{
pj_turn_permission *perm;
perm = PJ_POOL_ZALLOC_T(alloc->pool, pj_turn_permission);
pj_memcpy(&perm->hkey.peer_addr, peer_addr, addr_len);
perm->allocation = alloc;
perm->channel = PJ_TURN_INVALID_CHANNEL;
pj_gettimeofday(&perm->expiry);
perm->expiry.sec += PJ_TURN_PERM_TIMEOUT;
/* Register to hash table (only the address part!) */
pj_hash_set(alloc->pool, alloc->peer_table,
pj_sockaddr_get_addr(&perm->hkey.peer_addr),
pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, perm);
return perm;
}
示例6: pj_gettimeofday
/* Check if a permission isn't expired. Return NULL if expired. */
static pj_turn_permission *check_permission_expiry(pj_turn_permission *perm)
{
pj_turn_allocation *alloc = perm->allocation;
pj_time_val now;
pj_gettimeofday(&now);
if (PJ_TIME_VAL_GT(perm->expiry, now)) {
/* Permission has not expired */
return perm;
}
/* Remove from permission hash table */
pj_hash_set(NULL, alloc->peer_table,
pj_sockaddr_get_addr(&perm->hkey.peer_addr),
pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, NULL);
/* Remove from channel hash table, if assigned a channel number */
if (perm->channel != PJ_TURN_INVALID_CHANNEL) {
pj_hash_set(NULL, alloc->ch_table, &perm->channel,
sizeof(perm->channel), 0, NULL);
}
return NULL;
}
示例7: PJ_DEF
//.........这里部分代码省略.........
} else {
srv_port = (pj_uint16_t)target->addr.port;
}
if (type & PJSIP_TRANSPORT_IPV6) {
af = pj_AF_INET6();
} else {
af = pj_AF_INET();
}
/* Resolve */
count = 1;
status = pj_getaddrinfo(af, &target->addr.host, &count, &ai);
if (status != PJ_SUCCESS)
goto on_error;
svr_addr.entry[0].addr.addr.sa_family = (pj_uint16_t)af;
pj_memcpy(&svr_addr.entry[0].addr, &ai.ai_addr, sizeof(pj_sockaddr));
if (af == pj_AF_INET6()) {
svr_addr.entry[0].addr.ipv6.sin6_port = pj_htons(srv_port);
} else {
svr_addr.entry[0].addr.ipv4.sin_port = pj_htons(srv_port);
}
/* Call the callback. */
PJ_LOG(5,(THIS_FILE,
"Target '%.*s:%d' type=%s resolved to "
"'%s:%d' type=%s (%s)",
(int)target->addr.host.slen,
target->addr.host.ptr,
target->addr.port,
pjsip_transport_get_type_name(target->type),
pj_inet_ntop2(af, pj_sockaddr_get_addr(&svr_addr.entry[0].addr),
ip_addr, sizeof(ip_addr)),
srv_port,
pjsip_transport_get_type_name(type),
pjsip_transport_get_type_desc(type)));
svr_addr.count = 1;
svr_addr.entry[0].priority = 0;
svr_addr.entry[0].weight = 0;
svr_addr.entry[0].type = type;
svr_addr.entry[0].addr_len = pj_sockaddr_get_len(&svr_addr.entry[0].addr);
(*cb)(status, token, &svr_addr);
/* Done. */
return;
}
/* Target is not an IP address so we need to resolve it. */
#if PJSIP_HAS_RESOLVER
/* Build the query state */
query = PJ_POOL_ZALLOC_T(pool, struct query);
query->objname = THIS_FILE;
query->token = token;
query->cb = cb;
query->req.target = *target;
pj_strdup(pool, &query->req.target.addr.host, &target->addr.host);
/* If port is not specified, start with SRV resolution
* (should be with NAPTR, but we'll do that later)
*/
PJ_TODO(SUPPORT_DNS_NAPTR);
/* Build dummy NAPTR entry */
示例8: get_published_name
/* Generate transport's published address */
static pj_status_t get_published_name(pj_sock_t sock,
char hostbuf[],
int hostbufsz,
pjsip_host_port *bound_name)
{
pj_sockaddr tmp_addr;
int addr_len;
pj_status_t status;
addr_len = sizeof(tmp_addr);
status = pj_sock_getsockname(sock, &tmp_addr, &addr_len);
if (status != PJ_SUCCESS)
return status;
bound_name->host.ptr = hostbuf;
if (tmp_addr.addr.sa_family == pj_AF_INET()) {
bound_name->port = pj_ntohs(tmp_addr.ipv4.sin_port);
/* If bound address specifies "0.0.0.0", get the IP address
* of local hostname.
*/
if (tmp_addr.ipv4.sin_addr.s_addr == PJ_INADDR_ANY) {
pj_sockaddr hostip;
status = pj_gethostip(pj_AF_INET(), &hostip);
if (status != PJ_SUCCESS)
return status;
pj_strcpy2(&bound_name->host, pj_inet_ntoa(hostip.ipv4.sin_addr));
} else {
/* Otherwise use bound address. */
pj_strcpy2(&bound_name->host,
pj_inet_ntoa(tmp_addr.ipv4.sin_addr));
status = PJ_SUCCESS;
}
} else {
/* If bound address specifies "INADDR_ANY" (IPv6), get the
* IP address of local hostname
*/
pj_uint32_t loop6[4] = { 0, 0, 0, 0};
bound_name->port = pj_ntohs(tmp_addr.ipv6.sin6_port);
if (pj_memcmp(&tmp_addr.ipv6.sin6_addr, loop6, sizeof(loop6))==0) {
status = pj_gethostip(tmp_addr.addr.sa_family, &tmp_addr);
if (status != PJ_SUCCESS)
return status;
}
status = pj_inet_ntop(tmp_addr.addr.sa_family,
pj_sockaddr_get_addr(&tmp_addr),
hostbuf, hostbufsz);
if (status == PJ_SUCCESS) {
bound_name->host.slen = pj_ansi_strlen(hostbuf);
}
}
return status;
}
示例9: udp_on_read_complete
/*
* udp_on_read_complete()
*
* This is callback notification from ioqueue that a pending recvfrom()
* operation has completed.
*/
static void udp_on_read_complete( pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
/* See https://trac.pjsip.org/repos/ticket/1197 */
enum { MAX_IMMEDIATE_PACKET = 50 };
pjsip_rx_data_op_key *rdata_op_key = (pjsip_rx_data_op_key*) op_key;
pjsip_rx_data *rdata = rdata_op_key->rdata;
struct udp_transport *tp = (struct udp_transport*)rdata->tp_info.transport;
int i;
pj_status_t status;
/* Don't do anything if transport is closing. */
if (tp->is_closing) {
tp->is_closing++;
return;
}
/* Don't do anything if transport is being paused. */
if (tp->is_paused)
return;
/*
* The idea of the loop is to process immediate data received by
* pj_ioqueue_recvfrom(), as long as i < MAX_IMMEDIATE_PACKET. When
* i is >= MAX_IMMEDIATE_PACKET, we force the recvfrom() operation to
* complete asynchronously, to allow other sockets to get their data.
*/
for (i=0;; ++i) {
enum { MIN_SIZE = 32 };
pj_uint32_t flags;
/* Report the packet to transport manager. Only do so if packet size
* is relatively big enough for a SIP packet.
*/
if (bytes_read > MIN_SIZE) {
pj_ssize_t size_eaten;
const pj_sockaddr *src_addr = &rdata->pkt_info.src_addr;
/* Init pkt_info part. */
rdata->pkt_info.len = bytes_read;
rdata->pkt_info.zero = 0;
pj_gettimeofday(&rdata->pkt_info.timestamp);
if (src_addr->addr.sa_family == pj_AF_INET()) {
pj_ansi_strcpy(rdata->pkt_info.src_name,
pj_inet_ntoa(src_addr->ipv4.sin_addr));
rdata->pkt_info.src_port = pj_ntohs(src_addr->ipv4.sin_port);
} else {
pj_inet_ntop(pj_AF_INET6(),
pj_sockaddr_get_addr(&rdata->pkt_info.src_addr),
rdata->pkt_info.src_name,
sizeof(rdata->pkt_info.src_name));
rdata->pkt_info.src_port = pj_ntohs(src_addr->ipv6.sin6_port);
}
size_eaten =
pjsip_tpmgr_receive_packet(rdata->tp_info.transport->tpmgr,
rdata);
if (size_eaten < 0) {
pj_assert(!"It shouldn't happen!");
size_eaten = rdata->pkt_info.len;
}
/* Since this is UDP, the whole buffer is the message. */
rdata->pkt_info.len = 0;
} else if (bytes_read <= MIN_SIZE) {
/* TODO: */
} else if (-bytes_read != PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK) &&
-bytes_read != PJ_STATUS_FROM_OS(OSERR_EINPROGRESS) &&
-bytes_read != PJ_STATUS_FROM_OS(OSERR_ECONNRESET))
{
/* Report error to endpoint. */
PJSIP_ENDPT_LOG_ERROR((rdata->tp_info.transport->endpt,
rdata->tp_info.transport->obj_name,
(pj_status_t)-bytes_read,
"Warning: pj_ioqueue_recvfrom()"
" callback error"));
}
if (i >= MAX_IMMEDIATE_PACKET) {
/* Force ioqueue_recvfrom() to return PJ_EPENDING */
flags = PJ_IOQUEUE_ALWAYS_ASYNC;
} else {
flags = 0;
}
/* Reset pool.
* Need to copy rdata fields to temp variable because they will
* be invalid after pj_pool_reset().
//.........这里部分代码省略.........
示例10: PJ_DEF
//.........这里部分代码省略.........
local_af = pj_AF_INET();
} else if (pj_stricmp(&local_conn->addr_type, &ID_IP6)==0) {
local_af = pj_AF_INET6();
}
}
if (local_af==pj_AF_UNSPEC()) {
/* Unsupported address family */
return PJ_SUCCESS;
}
/* Set remote address: */
status = pj_sockaddr_init(local_af, &local_addr, &local_conn->addr,
local_m->desc.port);
if (status != PJ_SUCCESS) {
/* Invalid IP address. */
return PJMEDIA_EINVALIDIP;
}
/* Local and remote address family must match */
if (local_af != rem_af)
return PJ_EAFNOTSUP;
/* Media direction: */
if (local_m->desc.port == 0 ||
pj_sockaddr_has_addr(&local_addr)==PJ_FALSE ||
pj_sockaddr_has_addr(&si->rem_addr)==PJ_FALSE ||
pjmedia_sdp_media_find_attr(local_m, &STR_INACTIVE, NULL)!=NULL)
{
/* Inactive stream. */
si->dir = PJMEDIA_DIR_NONE;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_SENDONLY, NULL)!=NULL) {
/* Send only stream. */
si->dir = PJMEDIA_DIR_ENCODING;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_RECVONLY, NULL)!=NULL) {
/* Recv only stream. */
si->dir = PJMEDIA_DIR_DECODING;
} else {
/* Send and receive stream. */
si->dir = PJMEDIA_DIR_ENCODING_DECODING;
}
/* No need to do anything else if stream is rejected */
if (local_m->desc.port == 0) {
return PJ_SUCCESS;
}
/* If "rtcp" attribute is present in the SDP, set the RTCP address
* from that attribute. Otherwise, calculate from RTP address.
*/
attr = pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
"rtcp", NULL);
if (attr) {
pjmedia_sdp_rtcp_attr rtcp;
status = pjmedia_sdp_attr_get_rtcp(attr, &rtcp);
if (status == PJ_SUCCESS) {
if (rtcp.addr.slen) {
status = pj_sockaddr_init(rem_af, &si->rem_rtcp, &rtcp.addr,
(pj_uint16_t)rtcp.port);
} else {
pj_sockaddr_init(rem_af, &si->rem_rtcp, NULL,
(pj_uint16_t)rtcp.port);
pj_memcpy(pj_sockaddr_get_addr(&si->rem_rtcp),
pj_sockaddr_get_addr(&si->rem_addr),
pj_sockaddr_get_addr_len(&si->rem_addr));
}
}
}
if (!pj_sockaddr_has_addr(&si->rem_rtcp)) {
int rtcp_port;
pj_memcpy(&si->rem_rtcp, &si->rem_addr, sizeof(pj_sockaddr));
rtcp_port = pj_sockaddr_get_port(&si->rem_addr) + 1;
pj_sockaddr_set_port(&si->rem_rtcp, (pj_uint16_t)rtcp_port);
}
/* Get codec info and param */
status = get_video_codec_info_param(si, pool, NULL, local_m, rem_m);
/* Leave SSRC to random. */
si->ssrc = pj_rand();
/* Set default jitter buffer parameter. */
si->jb_init = si->jb_max = si->jb_min_pre = si->jb_max_pre = -1;
return status;
}
示例11: PJ_DEF
/* Get IP interface for sending to the specified destination */
PJ_DEF(pj_status_t) pj_getipinterface(int af,
const pj_str_t *dst,
pj_sockaddr *itf_addr,
pj_bool_t allow_resolve,
pj_sockaddr *p_dst_addr)
{
pj_sockaddr dst_addr;
pj_sock_t fd;
int len;
pj_uint8_t zero[64];
pj_status_t status;
pj_sockaddr_init(af, &dst_addr, NULL, 53);
status = pj_inet_pton(af, dst, pj_sockaddr_get_addr(&dst_addr));
if (status != PJ_SUCCESS) {
/* "dst" is not an IP address. */
if (allow_resolve) {
status = pj_sockaddr_init(af, &dst_addr, dst, 53);
} else {
pj_str_t cp;
if (af == PJ_AF_INET) {
cp = pj_str("1.1.1.1");
} else {
cp = pj_str("1::1");
}
status = pj_sockaddr_init(af, &dst_addr, &cp, 53);
}
if (status != PJ_SUCCESS)
return status;
}
/* Create UDP socket and connect() to the destination IP */
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &fd);
if (status != PJ_SUCCESS) {
return status;
}
status = pj_sock_connect(fd, &dst_addr, pj_sockaddr_get_len(&dst_addr));
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
len = sizeof(*itf_addr);
status = pj_sock_getsockname(fd, itf_addr, &len);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
pj_sock_close(fd);
/* Check that the address returned is not zero */
pj_bzero(zero, sizeof(zero));
if (pj_memcmp(pj_sockaddr_get_addr(itf_addr), zero,
pj_sockaddr_get_addr_len(itf_addr))==0)
{
return PJ_ENOTFOUND;
}
if (p_dst_addr)
*p_dst_addr = dst_addr;
return PJ_SUCCESS;
}
示例12: PJ_DEF
/**
* Set the server or domain name of the server.
*/
PJ_DEF(pj_status_t) pj_tcp_session_set_server( pj_tcp_session *sess,
const pj_str_t *domain,
int default_port,
pj_dns_resolver *resolver)
{
pj_sockaddr tmp_addr;
pj_bool_t is_ip_addr;
pj_status_t status;
PJ_ASSERT_RETURN(sess && domain, PJ_EINVAL);
PJ_ASSERT_RETURN(sess->state == PJ_TCP_STATE_NULL, PJ_EINVALIDOP);
pj_lock_acquire(sess->lock);
/* See if "domain" contains just IP address */
tmp_addr.addr.sa_family = sess->af;
status = pj_inet_pton(sess->af, domain,
pj_sockaddr_get_addr(&tmp_addr));
is_ip_addr = (status == PJ_SUCCESS);
if (!is_ip_addr && resolver) {
/* Resolve with DNS SRV resolution, and fallback to DNS A resolution
* if default_port is specified.
*/
unsigned opt = 0;
pj_str_t res_name;
res_name = pj_str("_tcps._tcp.");
/* Fallback to DNS A only if default port is specified */
if (default_port>0 && default_port<65536) {
opt = PJ_DNS_SRV_FALLBACK_A;
sess->default_port = (pj_uint16_t)default_port;
}
PJ_LOG(5,(sess->obj_name, "Resolving %.*s%.*s with DNS SRV",
(int)res_name.slen, res_name.ptr,
(int)domain->slen, domain->ptr));
pj_tcp_session_set_state(sess, PJ_TCP_STATE_RESOLVING);
/* User may have destroyed us in the callback */
if (sess->state != PJ_TCP_STATE_RESOLVING) {
status = PJ_ECANCELLED;
goto on_return;
}
status = pj_dns_srv_resolve(domain, &res_name, default_port,
sess->pool, resolver, opt, sess,
&dns_srv_resolver_cb, &sess->dns_async);
if (status != PJ_SUCCESS) {
pj_tcp_session_set_state(sess, PJ_TCP_STATE_NULL);
goto on_return;
}
} else {
/* Resolver is not specified, resolve with standard gethostbyname().
* The default_port MUST be specified in this case.
*/
pj_addrinfo *ai;
unsigned i, cnt;
/* Default port must be specified */
PJ_ASSERT_RETURN(default_port>0 && default_port<65536, PJ_EINVAL);
sess->default_port = (pj_uint16_t)default_port;
cnt = PJ_TCP_MAX_DNS_SRV_CNT;
ai = (pj_addrinfo*)
pj_pool_calloc(sess->pool, cnt, sizeof(pj_addrinfo));
PJ_LOG(5,(sess->obj_name, "Resolving %.*s with DNS A",
(int)domain->slen, domain->ptr));
pj_tcp_session_set_state(sess, PJ_TCP_STATE_RESOLVING);
/* User may have destroyed us in the callback */
if (sess->state != PJ_TCP_STATE_RESOLVING) {
status = PJ_ECANCELLED;
goto on_return;
}
status = pj_getaddrinfo(sess->af, domain, &cnt, ai);
if (status != PJ_SUCCESS)
goto on_return;
sess->srv_addr_cnt = (pj_uint16_t)cnt;
sess->srv_addr_list = (pj_sockaddr*)
pj_pool_calloc(sess->pool, cnt,
sizeof(pj_sockaddr));
for (i=0; i<cnt; ++i) {
pj_sockaddr *addr = &sess->srv_addr_list[i];
pj_memcpy(addr, &ai[i].ai_addr, sizeof(pj_sockaddr));
addr->addr.sa_family = sess->af;
addr->ipv4.sin_port = pj_htons(sess->default_port);
}
sess->srv_addr = &sess->srv_addr_list[0];
pj_tcp_session_set_state(sess, PJ_TCP_STATE_RESOLVED);
}
//.........这里部分代码省略.........
示例13: alloc_on_data_recvfrom
/* On received data from peer */
static pj_bool_t alloc_on_data_recvfrom(pj_activesock_t *asock,
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status)
{
turn_allocation *alloc;
pj_stun_xor_peer_addr_attr *pa;
pj_stun_data_attr *da;
char peer_info[PJ_INET6_ADDRSTRLEN+10];
char client_info[PJ_INET6_ADDRSTRLEN+10];
pj_uint8_t buffer[1500];
pj_ssize_t sent;
unsigned i;
if (status != PJ_SUCCESS)
return PJ_TRUE;
alloc = (turn_allocation*) pj_activesock_get_user_data(asock);
pj_sockaddr_print(&alloc->client_addr, client_info, sizeof(client_info), 3);
pj_sockaddr_print(src_addr, peer_info, sizeof(peer_info), 3);
/* Check that this peer has a permission */
for (i=0; i<alloc->perm_cnt; ++i) {
if (pj_sockaddr_get_len(&alloc->perm[i]) == (unsigned)addr_len &&
pj_memcmp(pj_sockaddr_get_addr(&alloc->perm[i]),
pj_sockaddr_get_addr(src_addr),
addr_len) == 0)
{
break;
}
}
if (i==alloc->perm_cnt) {
PJ_LOG(5,("", "Client %s received %d bytes unauthorized data from peer %s",
client_info, size, peer_info));
if (alloc->perm_cnt == 0)
PJ_LOG(5,("", "Client %s has no permission", client_info));
return PJ_TRUE;
}
/* Format a Data indication */
pa = (pj_stun_xor_peer_addr_attr*)
pj_stun_msg_find_attr(alloc->data_ind, PJ_STUN_ATTR_XOR_PEER_ADDR, 0);
da = (pj_stun_data_attr*)
pj_stun_msg_find_attr(alloc->data_ind, PJ_STUN_ATTR_DATA, 0);
pj_assert(pa && da);
pj_sockaddr_cp(&pa->sockaddr, src_addr);
da->data = (pj_uint8_t*)data;
da->length = size;
/* Encode Data indication */
status = pj_stun_msg_encode(alloc->data_ind, buffer, sizeof(buffer), 0,
NULL, &size);
if (status != PJ_SUCCESS)
return PJ_TRUE;
/* Send */
sent = size;
PJ_LOG(5,("", "Forwarding %d bytes data from peer %s to client %s",
sent, peer_info, client_info));
pj_activesock_sendto(alloc->test_srv->turn_sock, &alloc->send_key, buffer,
&sent, 0, &alloc->client_addr,
pj_sockaddr_get_len(&alloc->client_addr));
return PJ_TRUE;
}
示例14: PJ_DEF
//.........这里部分代码省略.........
/* Recv only stream. */
si->dir = PJMEDIA_DIR_DECODING;
} else {
/* Send and receive stream. */
si->dir = PJMEDIA_DIR_ENCODING_DECODING;
}
/* No need to do anything else if stream is rejected */
if (local_m->desc.port == 0) {
return PJ_SUCCESS;
}
/* If "rtcp" attribute is present in the SDP, set the RTCP address
* from that attribute. Otherwise, calculate from RTP address.
*/
attr = pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
"rtcp", NULL);
if (attr) {
pjmedia_sdp_rtcp_attr rtcp;
status = pjmedia_sdp_attr_get_rtcp(attr, &rtcp);
if (status == PJ_SUCCESS) {
if (rtcp.addr.slen) {
status = pj_sockaddr_init(rem_af, &si->rem_rtcp, &rtcp.addr,
(pj_uint16_t)rtcp.port);
} else {
pj_sockaddr_init(rem_af, &si->rem_rtcp, NULL,
(pj_uint16_t)rtcp.port);
pj_memcpy(pj_sockaddr_get_addr(&si->rem_rtcp),
pj_sockaddr_get_addr(&si->rem_addr),
pj_sockaddr_get_addr_len(&si->rem_addr));
}
}
}
if (!pj_sockaddr_has_addr(&si->rem_rtcp)) {
int rtcp_port;
pj_memcpy(&si->rem_rtcp, &si->rem_addr, sizeof(pj_sockaddr));
rtcp_port = pj_sockaddr_get_port(&si->rem_addr) + 1;
pj_sockaddr_set_port(&si->rem_rtcp, (pj_uint16_t)rtcp_port);
}
/* Get the payload number for receive channel. */
/*
Previously we used to rely on fmt[0] being the selected codec,
but some UA sends telephone-event as fmt[0] and this would
cause assert failure below.
Thanks Chris Hamilton <chamilton .at. cs.dal.ca> for this patch.
// And codec must be numeric!
if (!pj_isdigit(*local_m->desc.fmt[0].ptr) ||
!pj_isdigit(*rem_m->desc.fmt[0].ptr))
{
return PJMEDIA_EINVALIDPT;
}
pt = pj_strtoul(&local_m->desc.fmt[0]);
pj_assert(PJMEDIA_RTP_PT_TELEPHONE_EVENTS==0 ||
示例15: PJ_DEF
//.........这里部分代码省略.........
return PJ_EAFNOTSUP;
/* Media direction: */
if (local_m->desc.port == 0 ||
pj_sockaddr_has_addr(&local_addr)==PJ_FALSE ||
pj_sockaddr_has_addr(&si->rem_addr)==PJ_FALSE ||
pjmedia_sdp_media_find_attr(local_m, &STR_INACTIVE, NULL)!=NULL)
{
/* Inactive stream. */
si->dir = PJMEDIA_DIR_NONE;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_SENDONLY, NULL)!=NULL) {
/* Send only stream. */
si->dir = PJMEDIA_DIR_ENCODING;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_RECVONLY, NULL)!=NULL) {
/* Recv only stream. */
si->dir = PJMEDIA_DIR_DECODING;
} else {
/* Send and receive stream. */
si->dir = PJMEDIA_DIR_ENCODING_DECODING;
}
/* No need to do anything else if stream is rejected */
if (local_m->desc.port == 0) {
return PJ_SUCCESS;
}
/* If "rtcp" attribute is present in the SDP, set the RTCP address
* from that attribute. Otherwise, calculate from RTP address.
*/
attr = pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
"rtcp", NULL);
if (attr) {
pjmedia_sdp_rtcp_attr rtcp;
status = pjmedia_sdp_attr_get_rtcp(attr, &rtcp);
if (status == PJ_SUCCESS) {
if (rtcp.addr.slen) {
status = pj_sockaddr_init(rem_af, &si->rem_rtcp, &rtcp.addr,
(pj_uint16_t)rtcp.port);
} else {
pj_sockaddr_init(rem_af, &si->rem_rtcp, NULL,
(pj_uint16_t)rtcp.port);
pj_memcpy(pj_sockaddr_get_addr(&si->rem_rtcp),
pj_sockaddr_get_addr(&si->rem_addr),
pj_sockaddr_get_addr_len(&si->rem_addr));
}
}
}
if (!pj_sockaddr_has_addr(&si->rem_rtcp)) {
int rtcp_port;
pj_memcpy(&si->rem_rtcp, &si->rem_addr, sizeof(pj_sockaddr));
rtcp_port = pj_sockaddr_get_port(&si->rem_addr) + 1;
pj_sockaddr_set_port(&si->rem_rtcp, (pj_uint16_t)rtcp_port);
}
/* Get the payload number for receive channel. */
/*
Previously we used to rely on fmt[0] being the selected codec,
but some UA sends telephone-event as fmt[0] and this would
cause assert failure below.
Thanks Chris Hamilton <chamilton .at. cs.dal.ca> for this patch.
// And codec must be numeric!
if (!pj_isdigit(*local_m->desc.fmt[0].ptr) ||
!pj_isdigit(*rem_m->desc.fmt[0].ptr))
{
return PJMEDIA_EINVALIDPT;
}
pt = pj_strtoul(&local_m->desc.fmt[0]);
pj_assert(PJMEDIA_RTP_PT_TELEPHONE_EVENTS==0 ||
pt != PJMEDIA_RTP_PT_TELEPHONE_EVENTS);
*/
/* Get codec info and param */
status = get_audio_codec_info_param(si, pool, mgr, local_m, rem_m);
/* Leave SSRC to random. */
si->ssrc = pj_rand();
/* Set default jitter buffer parameter. */
si->jb_init = si->jb_max = si->jb_min_pre = si->jb_max_pre = -1;
return status;
}