本文整理汇总了C++中pj_ntohs函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_ntohs函数的具体用法?C++ pj_ntohs怎么用?C++ pj_ntohs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_ntohs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PJ_DEF
PJ_DEF(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
pj_stun_msg *msg)
{
pj_uint16_t msg_type, msg_len;
char *p_attr;
PJ_LOG(5,(THIS_FILE, "pj_stun_parse_msg %p, len=%d", buf, len));
msg->hdr = (pj_stun_msg_hdr*)buf;
msg_type = pj_ntohs(msg->hdr->type);
switch (msg_type) {
case PJ_STUN_BINDING_REQUEST:
case PJ_STUN_BINDING_RESPONSE:
case PJ_STUN_BINDING_ERROR_RESPONSE:
case PJ_STUN_SHARED_SECRET_REQUEST:
case PJ_STUN_SHARED_SECRET_RESPONSE:
case PJ_STUN_SHARED_SECRET_ERROR_RESPONSE:
break;
default:
PJ_LOG(5,(THIS_FILE, "Error: unknown msg type %d", msg_type));
return -1;
}
msg_len = pj_ntohs(msg->hdr->length);
if (msg_len != len - sizeof(pj_stun_msg_hdr)) {
PJ_LOG(5,(THIS_FILE, "Error: invalid msg_len %d (expecting %d)",
msg_len, len - sizeof(pj_stun_msg_hdr)));
return -1;
}
msg->attr_count = 0;
p_attr = (char*)buf + sizeof(pj_stun_msg_hdr);
while (msg_len > 0) {
pj_stun_attr_hdr **attr = &msg->attr[msg->attr_count];
pj_uint32_t len;
*attr = (pj_stun_attr_hdr*)p_attr;
len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pj_stun_attr_hdr);
if (msg_len < len) {
PJ_LOG(5,(THIS_FILE, "Error: length mismatch in attr %d",
msg->attr_count));
return -1;
}
if (pj_ntohs((*attr)->type) > PJ_STUN_ATTR_REFLECTED_FORM) {
PJ_LOG(5,(THIS_FILE, "Error: invalid attr type %d in attr %d",
pj_ntohs((*attr)->type), msg->attr_count));
return -1;
}
msg_len = (pj_uint16_t)(msg_len - len);
p_attr += len;
++msg->attr_count;
}
return 0;
}
示例2: PJ_DEF
PJ_DEF(void) pjmedia_rtp_session_update2( pjmedia_rtp_session *ses,
const pjmedia_rtp_hdr *hdr,
pjmedia_rtp_status *p_seq_st,
pj_bool_t check_pt)
{
pjmedia_rtp_status seq_st;
/* for now check_pt MUST be either PJ_TRUE or PJ_FALSE.
* In the future we might change check_pt from boolean to
* unsigned integer to accommodate more flags.
*/
pj_assert(check_pt==PJ_TRUE || check_pt==PJ_FALSE);
/* Init status */
seq_st.status.value = 0;
seq_st.diff = 0;
/* Check SSRC. */
if (!ses->has_peer_ssrc && ses->peer_ssrc == 0)
ses->peer_ssrc = pj_ntohl(hdr->ssrc);
if (pj_ntohl(hdr->ssrc) != ses->peer_ssrc) {
seq_st.status.flag.badssrc = 1;
if (!ses->has_peer_ssrc)
ses->peer_ssrc = pj_ntohl(hdr->ssrc);
}
/* Check payload type. */
if (check_pt && hdr->pt != ses->out_pt) {
if (p_seq_st) {
p_seq_st->status.value = seq_st.status.value;
p_seq_st->status.flag.bad = 1;
p_seq_st->status.flag.badpt = 1;
}
return;
}
/* Initialize sequence number on first packet received. */
if (ses->received == 0)
pjmedia_rtp_seq_init( &ses->seq_ctrl, pj_ntohs(hdr->seq) );
/* Check sequence number to see if remote session has been restarted. */
pjmedia_rtp_seq_update( &ses->seq_ctrl, pj_ntohs(hdr->seq), &seq_st);
if (seq_st.status.flag.restart) {
++ses->received;
} else if (!seq_st.status.flag.bad) {
++ses->received;
}
if (p_seq_st) {
p_seq_st->status.value = seq_st.status.value;
p_seq_st->diff = seq_st.diff;
}
}
示例3: has_packet
/* Quick check to determine if there is enough packet to process in the
* incoming buffer. Return the packet length, or zero if there's no packet.
*/
static unsigned has_packet(pj_turn_sock *turn_sock, const void *buf, pj_size_t bufsize)
{
pj_bool_t is_stun;
if (turn_sock->conn_type == PJ_TURN_TP_UDP)
return (unsigned)bufsize;
/* Quickly check if this is STUN message, by checking the first two bits and
* size field which must be multiple of 4 bytes
*/
is_stun = ((((pj_uint8_t*)buf)[0] & 0xC0) == 0) &&
((GETVAL16H((const pj_uint8_t*)buf, 2) & 0x03)==0);
if (is_stun) {
pj_size_t msg_len = GETVAL16H((const pj_uint8_t*)buf, 2);
return (unsigned)((msg_len+20 <= bufsize) ? msg_len+20 : 0);
} else {
/* This must be ChannelData. */
pj_turn_channel_data cd;
if (bufsize < 4)
return 0;
/* Decode ChannelData packet */
pj_memcpy(&cd, buf, sizeof(pj_turn_channel_data));
cd.length = pj_ntohs(cd.length);
if (bufsize >= cd.length+sizeof(cd))
return (cd.length+sizeof(cd)+3) & (~3);
else
return 0;
}
}
示例4: PJ_DEF
PJ_DEF(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_rtcp(pj_pool_t *pool,
const pj_sockaddr *a)
{
enum {
ATTR_LEN = PJ_INET6_ADDRSTRLEN+16
};
pjmedia_sdp_attr *attr;
attr = PJ_POOL_ALLOC_T(pool, pjmedia_sdp_attr);
attr->name = pj_str("rtcp");
attr->value.ptr = (char*) pj_pool_alloc(pool, ATTR_LEN);
if (a->addr.sa_family == pj_AF_INET()) {
attr->value.slen =
pj_ansi_snprintf(attr->value.ptr, ATTR_LEN,
"%u IN IP4 %s",
pj_ntohs(a->ipv4.sin_port),
pj_inet_ntoa(a->ipv4.sin_addr));
} else if (a->addr.sa_family == pj_AF_INET6()) {
char tmp_addr[PJ_INET6_ADDRSTRLEN];
attr->value.slen =
pj_ansi_snprintf(attr->value.ptr, ATTR_LEN,
"%u IN IP6 %s",
pj_sockaddr_get_port(a),
pj_sockaddr_print(a, tmp_addr,
sizeof(tmp_addr), 0));
} else {
pj_assert(!"Unsupported address family");
return NULL;
}
return attr;
}
示例5: guid_to_str
static void guid_to_str( GUID *guid, pj_str_t *str )
{
unsigned i;
const unsigned char *src = (const unsigned char*)guid;
char *dst = str->ptr;
guid->Data1 = pj_ntohl(guid->Data1);
guid->Data2 = pj_ntohs(guid->Data2);
guid->Data3 = pj_ntohs(guid->Data3);
for (i=0; i<16; ++i) {
hex2digit( *src, dst );
dst += 2;
++src;
}
str->slen = 32;
}
示例6: PJ_DEF
/*
* Get port number
*/
PJ_DEF(pj_uint16_t) pj_sockaddr_get_port(const pj_sockaddr_t *addr)
{
const pj_sockaddr *a = (const pj_sockaddr*) addr;
PJ_ASSERT_RETURN(a->addr.sa_family == PJ_AF_INET ||
a->addr.sa_family == PJ_AF_INET6, (pj_uint16_t)0xFFFF);
return pj_ntohs((pj_uint16_t)(a->addr.sa_family == PJ_AF_INET6 ?
a->ipv6.sin6_port : a->ipv4.sin_port));
}
示例7: read_ITU_format
/*
* Read file in ITU format (".itu" extension).
*
* Set swap_endian to TRUE if the ITU file is stored in little
* endian format (normally true).
*/
static int read_ITU_format(FILE *fp_bitstream,
short *out_words,
short *p_frame_error_flag,
int number_of_16bit_words_per_frame,
pj_bool_t swap_endian)
{
enum { MAX_BITS_PER_FRAME = 160*8 };
short i,j;
short nsamp;
short packed_word;
short bit_count;
short bit;
short in_array[MAX_BITS_PER_FRAME+2];
short one = 0x0081;
short zero = 0x007f;
short frame_start = 0x6b21;
nsamp = (short)fread(in_array, 2, 2 + 16*number_of_16bit_words_per_frame,
fp_bitstream);
j = 0;
bit = in_array[j++];
if (bit != frame_start) {
*p_frame_error_flag = 1;
} else {
*p_frame_error_flag = 0;
/* increment j to skip over the number of bits in frame */
j++;
for (i=0; i<number_of_16bit_words_per_frame; i++) {
packed_word = 0;
bit_count = 15;
while (bit_count >= 0) {
bit = in_array[j++];
if (bit == zero)
bit = 0;
else if (bit == one)
bit = 1;
else
*p_frame_error_flag = 1;
packed_word <<= 1;
packed_word = (short )(packed_word + bit);
bit_count--;
}
if (swap_endian)
out_words[i] = pj_ntohs(packed_word);
else
out_words[i] = packed_word;
}
}
return (nsamp-1)/16;
}
示例8: on_rx_rtcp
/* Notification from ioqueue about incoming RTCP packet */
static void on_rx_rtcp(pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
struct transport_udp *udp;
pj_status_t status;
PJ_UNUSED_ARG(op_key);
udp = pj_ioqueue_get_user_data(key);
do {
void (*cb)(void*,const void*,pj_ssize_t);
void *user_data;
cb = udp->rtcp_cb;
user_data = udp->user_data;
if (udp->attached && cb)
(*cb)(user_data, udp->rtcp_pkt, bytes_read);
/* Check if RTCP source address is the same as the configured
* remote address, and switch the address when they are
* different.
*/
if (bytes_read>0 &&
(udp->options & PJMEDIA_UDP_NO_SRC_ADDR_CHECKING)==0 &&
((udp->rem_rtcp_addr.sin_addr.s_addr !=
udp->rtcp_src_addr.sin_addr.s_addr) ||
(udp->rem_rtcp_addr.sin_port !=
udp->rtcp_src_addr.sin_port)))
{
pj_memcpy(&udp->rem_rtcp_addr, &udp->rtcp_src_addr,
sizeof(pj_sockaddr_in));
PJ_LOG(4,(udp->base.name,
"Remote RTCP address switched to %s:%d",
pj_inet_ntoa(udp->rtcp_src_addr.sin_addr),
pj_ntohs(udp->rtcp_src_addr.sin_port)));
}
bytes_read = sizeof(udp->rtcp_pkt);
udp->rtcp_addr_len = sizeof(udp->rtcp_src_addr);
status = pj_ioqueue_recvfrom(udp->rtcp_key, &udp->rtcp_read_op,
udp->rtcp_pkt, &bytes_read, 0,
&udp->rtcp_src_addr,
&udp->rtcp_addr_len);
if (status != PJ_EPENDING && status != PJ_SUCCESS)
bytes_read = -status;
} while (status != PJ_EPENDING);
}
示例9: transport_attach
/* Called by application to initialize the transport */
static pj_status_t transport_attach( pjmedia_transport *tp,
void *user_data,
const pj_sockaddr_t *rem_addr,
const pj_sockaddr_t *rem_rtcp,
unsigned addr_len,
void (*rtp_cb)(void*,
const void*,
pj_ssize_t),
void (*rtcp_cb)(void*,
const void*,
pj_ssize_t))
{
struct transport_udp *udp = (struct transport_udp*) tp;
const pj_sockaddr_in *rtcp_addr;
/* Validate arguments */
PJ_ASSERT_RETURN(tp && rem_addr && addr_len, PJ_EINVAL);
/* Must not be "attached" to existing application */
PJ_ASSERT_RETURN(!udp->attached, PJ_EINVALIDOP);
/* "Attach" the application: */
/* Copy remote RTP address */
pj_memcpy(&udp->rem_rtp_addr, rem_addr, sizeof(pj_sockaddr_in));
/* Copy remote RTP address, if one is specified. */
rtcp_addr = rem_rtcp;
if (rtcp_addr && rtcp_addr->sin_addr.s_addr != 0) {
pj_memcpy(&udp->rem_rtcp_addr, rem_rtcp, sizeof(pj_sockaddr_in));
} else {
int rtcp_port;
/* Otherwise guess the RTCP address from the RTP address */
pj_memcpy(&udp->rem_rtcp_addr, rem_addr, sizeof(pj_sockaddr_in));
rtcp_port = pj_ntohs(udp->rem_rtp_addr.sin_port) + 1;
udp->rem_rtcp_addr.sin_port = pj_htons((pj_uint16_t)rtcp_port);
}
/* Save the callbacks */
udp->rtp_cb = rtp_cb;
udp->rtcp_cb = rtcp_cb;
udp->user_data = user_data;
/* Last, mark transport as attached */
udp->attached = PJ_TRUE;
return PJ_SUCCESS;
}
示例10: tls_start_read
/*
* This utility function creates receive data buffers and start
* asynchronous recv() operations from the socket. It is called after
* accept() or connect() operation complete.
*/
static pj_status_t tls_start_read(struct tls_transport *tls)
{
pj_pool_t *pool;
pj_ssize_t size;
pj_sockaddr_in *rem_addr;
void *readbuf[1];
pj_status_t status;
/* Init rdata */
pool = pjsip_endpt_create_pool(tls->base.endpt,
"rtd%p",
PJSIP_POOL_RDATA_LEN,
PJSIP_POOL_RDATA_INC);
if (!pool) {
tls_perror(tls->base.obj_name, "Unable to create pool", PJ_ENOMEM);
return PJ_ENOMEM;
}
tls->rdata.tp_info.pool = pool;
tls->rdata.tp_info.transport = &tls->base;
tls->rdata.tp_info.tp_data = tls;
tls->rdata.tp_info.op_key.rdata = &tls->rdata;
pj_ioqueue_op_key_init(&tls->rdata.tp_info.op_key.op_key,
sizeof(pj_ioqueue_op_key_t));
tls->rdata.pkt_info.src_addr = tls->base.key.rem_addr;
tls->rdata.pkt_info.src_addr_len = sizeof(pj_sockaddr_in);
rem_addr = (pj_sockaddr_in*) &tls->base.key.rem_addr;
pj_ansi_strcpy(tls->rdata.pkt_info.src_name,
pj_inet_ntoa(rem_addr->sin_addr));
tls->rdata.pkt_info.src_port = pj_ntohs(rem_addr->sin_port);
size = sizeof(tls->rdata.pkt_info.packet);
readbuf[0] = tls->rdata.pkt_info.packet;
status = pj_ssl_sock_start_read2(tls->ssock, tls->base.pool, size,
readbuf, 0);
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
PJ_LOG(4, (tls->base.obj_name,
"pj_ssl_sock_start_read() error, status=%d",
status));
return status;
}
return PJ_SUCCESS;
}
示例11: udp_echo_srv_create
static pj_status_t udp_echo_srv_create(pj_pool_t *pool,
pj_ioqueue_t *ioqueue,
pj_bool_t enable_echo,
struct udp_echo_srv **p_srv)
{
struct udp_echo_srv *srv;
pj_sock_t sock_fd = PJ_INVALID_SOCKET;
pj_sockaddr addr;
int addr_len;
pj_activesock_cb activesock_cb;
pj_status_t status;
srv = PJ_POOL_ZALLOC_T(pool, struct udp_echo_srv);
srv->echo_enabled = enable_echo;
pj_sockaddr_in_init(&addr.ipv4, NULL, 0);
addr_len = sizeof(addr);
pj_bzero(&activesock_cb, sizeof(activesock_cb));
activesock_cb.on_data_recvfrom = &udp_echo_srv_on_data_recvfrom;
status = pj_activesock_create_udp(pool, &addr, NULL, ioqueue, &activesock_cb,
srv, &srv->asock, &addr);
if (status != PJ_SUCCESS) {
pj_sock_close(sock_fd);
udp_echo_err("pj_activesock_create()", status);
return status;
}
srv->port = pj_ntohs(addr.ipv4.sin_port);
pj_ioqueue_op_key_init(&srv->send_key, sizeof(srv->send_key));
status = pj_activesock_start_recvfrom(srv->asock, pool, 32, 0);
if (status != PJ_SUCCESS) {
pj_activesock_close(srv->asock);
udp_echo_err("pj_activesock_start_recvfrom()", status);
return status;
}
*p_srv = srv;
return PJ_SUCCESS;
}
示例12: PJ_DEF
PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp( pjmedia_rtp_session *ses,
const void *pkt, int pkt_len,
const pjmedia_rtp_hdr **hdr,
const void **payload,
unsigned *payloadlen)
{
int offset;
PJ_UNUSED_ARG(ses);
/* Assume RTP header at the start of packet. We'll verify this later. */
*hdr = (pjmedia_rtp_hdr*)pkt;
/* Check RTP header sanity. */
if ((*hdr)->v != RTP_VERSION) {
return PJMEDIA_RTP_EINVER;
}
/* Payload is located right after header plus CSRC */
offset = sizeof(pjmedia_rtp_hdr) + ((*hdr)->cc * sizeof(pj_uint32_t));
/* Adjust offset if RTP extension is used. */
if ((*hdr)->x) {
pjmedia_rtp_ext_hdr *ext = (pjmedia_rtp_ext_hdr*)
(((pj_uint8_t*)pkt) + offset);
offset += ((pj_ntohs(ext->length)+1) * sizeof(pj_uint32_t));
}
/* Check that offset is less than packet size */
if (offset > pkt_len)
return PJMEDIA_RTP_EINLEN;
/* Find and set payload. */
*payload = ((pj_uint8_t*)pkt) + offset;
*payloadlen = pkt_len - offset;
return PJ_SUCCESS;
}
示例13: turn_on_data_recvfrom
static pj_bool_t turn_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)
{
test_server *test_srv;
pj_pool_t *pool;
turn_allocation *alloc;
pj_stun_msg *req, *resp = NULL;
pj_str_t auth_key = { NULL, 0 };
char client_info[PJ_INET6_ADDRSTRLEN+10];
unsigned i;
pj_ssize_t len;
if (status != PJ_SUCCESS)
return PJ_TRUE;
pj_sockaddr_print(src_addr, client_info, sizeof(client_info), 3);
test_srv = (test_server*) pj_activesock_get_user_data(asock);
pool = pj_pool_create(test_srv->stun_cfg->pf, NULL, 512, 512, NULL);
/* Find the client */
for (i=0; i<test_srv->turn_alloc_cnt; i++) {
if (pj_sockaddr_cmp(&test_srv->turn_alloc[i].client_addr, src_addr)==0)
break;
}
if (pj_stun_msg_check((pj_uint8_t*)data, size, PJ_STUN_NO_FINGERPRINT_CHECK)!=PJ_SUCCESS) {
/* Not STUN message, this probably is a ChannelData */
pj_turn_channel_data cd;
const pj_turn_channel_data *pcd = (const pj_turn_channel_data*)data;
pj_ssize_t sent;
if (i==test_srv->turn_alloc_cnt) {
/* Invalid data */
PJ_LOG(1,(THIS_FILE,
"TURN Server received strayed data"));
goto on_return;
}
alloc = &test_srv->turn_alloc[i];
cd.ch_number = pj_ntohs(pcd->ch_number);
cd.length = pj_ntohs(pcd->length);
/* For UDP check the packet length */
if (size < cd.length+sizeof(cd)) {
PJ_LOG(1,(THIS_FILE,
"TURN Server: ChannelData discarded: UDP size error"));
goto on_return;
}
/* Lookup peer */
for (i=0; i<alloc->perm_cnt; ++i) {
if (alloc->chnum[i] == cd.ch_number)
break;
}
if (i==alloc->perm_cnt) {
PJ_LOG(1,(THIS_FILE,
"TURN Server: ChannelData discarded: invalid channel number"));
goto on_return;
}
/* Relay the data to peer */
sent = cd.length;
pj_activesock_sendto(alloc->sock, &alloc->send_key,
pcd+1, &sent, 0,
&alloc->perm[i],
pj_sockaddr_get_len(&alloc->perm[i]));
/* Done */
goto on_return;
}
status = pj_stun_msg_decode(pool, (pj_uint8_t*)data, size,
PJ_STUN_IS_DATAGRAM | PJ_STUN_CHECK_PACKET |
PJ_STUN_NO_FINGERPRINT_CHECK,
&req, NULL, NULL);
if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE];
pj_strerror(status, errmsg, sizeof(errmsg));
PJ_LOG(1,("", "STUN message decode error from client %s: %s", client_info, errmsg));
goto on_return;
}
if (i==test_srv->turn_alloc_cnt) {
/* New client */
//pj_str_t ip_addr;
pj_stun_username_attr *uname;
pj_activesock_cb alloc_sock_cb;
turn_allocation *alloc;
/* Must be Allocate request */
if (req->hdr.type != PJ_STUN_ALLOCATE_REQUEST) {
PJ_LOG(1,(THIS_FILE, "Invalid %s %s from client %s",
//.........这里部分代码省略.........
示例14: on_rx_rtp
/* Notification from ioqueue about incoming RTP packet */
static void on_rx_rtp( pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
struct transport_udp *udp;
pj_status_t status;
PJ_UNUSED_ARG(op_key);
udp = pj_ioqueue_get_user_data(key);
do {
void (*cb)(void*,const void*,pj_ssize_t);
void *user_data;
cb = udp->rtp_cb;
user_data = udp->user_data;
/* Simulate packet lost on RX direction */
if (udp->rx_drop_pct) {
if ((pj_rand() % 100) <= (int)udp->rx_drop_pct) {
PJ_LOG(5,(udp->base.name,
"RX RTP packet dropped because of pkt lost "
"simulation"));
goto read_next_packet;
}
}
if (udp->attached && cb)
(*cb)(user_data, udp->rtp_pkt, bytes_read);
/* See if source address of RTP packet is different than the
* configured address, and switch RTP remote address to
* source packet address after several consecutive packets
* have been received.
*/
if (bytes_read>0 &&
(udp->options & PJMEDIA_UDP_NO_SRC_ADDR_CHECKING)==0)
{
if ((udp->rem_rtp_addr.sin_addr.s_addr !=
udp->rtp_src_addr.sin_addr.s_addr) ||
(udp->rem_rtp_addr.sin_port !=
udp->rtp_src_addr.sin_port))
{
udp->rtp_src_cnt++;
if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) {
/* Set remote RTP address to source address */
udp->rem_rtp_addr = udp->rtp_src_addr;
/* Reset counter */
udp->rtp_src_cnt = 0;
PJ_LOG(4,(udp->base.name,
"Remote RTP address switched to %s:%d",
pj_inet_ntoa(udp->rtp_src_addr.sin_addr),
pj_ntohs(udp->rtp_src_addr.sin_port)));
/* Also update remote RTCP address if actual RTCP source
* address is not heard yet.
*/
if (udp->rtcp_src_addr.sin_addr.s_addr == 0) {
pj_uint16_t port;
pj_memcpy(&udp->rem_rtcp_addr, &udp->rem_rtp_addr,
sizeof(pj_sockaddr_in));
port = (pj_uint16_t)
(pj_ntohs(udp->rem_rtp_addr.sin_port)+1);
udp->rem_rtcp_addr.sin_port = pj_htons(port);
pj_memcpy(&udp->rtcp_src_addr, &udp->rem_rtcp_addr,
sizeof(pj_sockaddr_in));
PJ_LOG(4,(udp->base.name,
"Remote RTCP address switched to %s:%d",
pj_inet_ntoa(udp->rtcp_src_addr.sin_addr),
pj_ntohs(udp->rtcp_src_addr.sin_port)));
}
}
}
}
read_next_packet:
bytes_read = sizeof(udp->rtp_pkt);
udp->rtp_addrlen = sizeof(pj_sockaddr_in);
status = pj_ioqueue_recvfrom(udp->rtp_key, &udp->rtp_read_op,
udp->rtp_pkt, &bytes_read, 0,
&udp->rtp_src_addr,
&udp->rtp_addrlen);
if (status != PJ_EPENDING && status != PJ_SUCCESS)
bytes_read = -status;
} while (status != PJ_EPENDING);
}
示例15: tls_create
/*
* Common function to create TLS transport, called when pending accept() and
* pending connect() complete.
*/
static pj_status_t tls_create( struct tls_listener *listener,
pj_pool_t *pool,
pj_ssl_sock_t *ssock,
pj_bool_t is_server,
const pj_sockaddr_in *local,
const pj_sockaddr_in *remote,
const pj_str_t *remote_name,
struct tls_transport **p_tls)
{
struct tls_transport *tls;
const pj_str_t ka_pkt = PJSIP_TLS_KEEP_ALIVE_DATA;
pj_status_t status;
PJ_ASSERT_RETURN(listener && ssock && local && remote && p_tls, PJ_EINVAL);
if (pool == NULL) {
pool = pjsip_endpt_create_pool(listener->endpt, "tls",
POOL_TP_INIT, POOL_TP_INC);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
}
/*
* Create and initialize basic transport structure.
*/
tls = PJ_POOL_ZALLOC_T(pool, struct tls_transport);
tls->is_server = is_server;
tls->verify_server = listener->tls_setting.verify_server;
pj_list_init(&tls->delayed_list);
tls->base.pool = pool;
pj_ansi_snprintf(tls->base.obj_name, PJ_MAX_OBJ_NAME,
(is_server ? "tlss%p" :"tlsc%p"), tls);
status = pj_atomic_create(pool, 0, &tls->base.ref_cnt);
if (status != PJ_SUCCESS) {
goto on_error;
}
status = pj_lock_create_recursive_mutex(pool, "tls", &tls->base.lock);
if (status != PJ_SUCCESS) {
goto on_error;
}
if (remote_name)
pj_strdup(pool, &tls->remote_name, remote_name);
tls->base.key.type = PJSIP_TRANSPORT_TLS;
pj_memcpy(&tls->base.key.rem_addr, remote, sizeof(pj_sockaddr_in));
tls->base.type_name = "tls";
tls->base.flag = pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_TLS);
tls->base.info = (char*) pj_pool_alloc(pool, 64);
pj_ansi_snprintf(tls->base.info, 64, "TLS to %s:%d",
pj_inet_ntoa(remote->sin_addr),
(int)pj_ntohs(remote->sin_port));
tls->base.addr_len = sizeof(pj_sockaddr_in);
tls->base.dir = is_server? PJSIP_TP_DIR_INCOMING : PJSIP_TP_DIR_OUTGOING;
/* Set initial local address */
if (!pj_sockaddr_has_addr(local)) {
pj_sockaddr_cp(&tls->base.local_addr,
&listener->factory.local_addr);
} else {
pj_sockaddr_cp(&tls->base.local_addr, local);
}
sockaddr_to_host_port(pool, &tls->base.local_name,
(pj_sockaddr_in*)&tls->base.local_addr);
if (tls->remote_name.slen) {
tls->base.remote_name.host = tls->remote_name;
tls->base.remote_name.port = pj_sockaddr_in_get_port(remote);
} else {
sockaddr_to_host_port(pool, &tls->base.remote_name, remote);
}
tls->base.endpt = listener->endpt;
tls->base.tpmgr = listener->tpmgr;
tls->base.send_msg = &tls_send_msg;
tls->base.do_shutdown = &tls_shutdown;
tls->base.destroy = &tls_destroy_transport;
tls->ssock = ssock;
/* Register transport to transport manager */
status = pjsip_transport_register(listener->tpmgr, &tls->base);
if (status != PJ_SUCCESS) {
goto on_error;
}
tls->is_registered = PJ_TRUE;
/* Initialize keep-alive timer */
tls->ka_timer.user_data = (void*)tls;
//.........这里部分代码省略.........