Commit 5b1c601c authored by Ghislain MARY's avatar Ghislain MARY

Add port information in the recv_addr of a received mblk_t and add function to...

Add port information in the recv_addr of a received mblk_t and add function to convert it to a sockaddr.
parent 5d473849
......@@ -44,6 +44,7 @@ typedef struct ortp_recv_addr {
struct in_addr ipi_addr;
struct in6_addr ipi6_addr;
} addr;
unsigned short port;
} ortp_recv_addr_t;
typedef struct msgb
......@@ -178,6 +179,8 @@ ORTP_PUBLIC float ortp_extremum_get_current(ortp_extremum *obj);
**/
ORTP_PUBLIC float ortp_extremum_get_previous(ortp_extremum *obj);
ORTP_PUBLIC void ortp_recvaddr_to_sockaddr(ortp_recv_addr_t *recvaddr, struct sockaddr *addr, socklen_t *socklen);
#ifdef __cplusplus
}
#endif
......
......@@ -2219,7 +2219,7 @@ int meta_rtp_transport_recvfrom(RtpTransport *t, mblk_t *msg, int flags, struct
msg->net_addrlen = *fromlen;
}
}else{
ret=rtp_session_rtp_recv_abstract(m->is_rtp?t->session->rtp.gs.socket:t->session->rtcp.gs.socket,msg,flags,from,fromlen);
ret=rtp_session_recvfrom(t->session,m->is_rtp,msg,flags,from,fromlen);
}
/*received packet must be treated in reversed order: first in last out
......
......@@ -1049,7 +1049,12 @@ int rtp_session_sendto(RtpSession *session, bool_t is_rtp, mblk_t *m, int flags,
}
int rtp_session_recvfrom(RtpSession *session, bool_t is_rtp, mblk_t *m, int flags, struct sockaddr *from, socklen_t *fromlen) {
return rtp_session_rtp_recv_abstract(is_rtp ? session->rtp.gs.socket : session->rtcp.gs.socket, m, flags, from, fromlen);
int ret = rtp_session_rtp_recv_abstract(is_rtp ? session->rtp.gs.socket : session->rtcp.gs.socket, m, flags, from, fromlen);
if (ret >= 0) {
/* Store the local port in the recv_addr of the mblk_t, the address is already filled in rtp_session_rtp_recv_abstract */
m->recv_addr.port = htons(is_rtp ? session->rtp.gs.loc_port : session->rtcp.gs.loc_port);
}
return ret;
}
void update_sent_bytes(OrtpStream *os, int nbytes) {
......@@ -1568,13 +1573,11 @@ void rtp_session_process_incoming(RtpSession * session, mblk_t *mp, bool_t is_rt
int rtp_session_rtp_recv (RtpSession * session, uint32_t user_ts) {
int error;
ortp_socket_t sockfd=session->rtp.gs.socket;
struct sockaddr_storage remaddr;
socklen_t addrlen = sizeof (remaddr);
mblk_t *mp;
if ((sockfd==(ortp_socket_t)-1) && !rtp_session_using_transport(session, rtp)) return -1; /*session has no sockets for the moment*/
if ((session->rtp.gs.socket==(ortp_socket_t)-1) && !rtp_session_using_transport(session, rtp)) return -1; /*session has no sockets for the moment*/
while (1)
{
......@@ -1585,11 +1588,11 @@ int rtp_session_rtp_recv (RtpSession * session, uint32_t user_ts) {
mp->reserved1 = user_ts;
if (sock_connected){
error=rtp_session_rtp_recv_abstract(sockfd, mp, 0, NULL, NULL);
error=rtp_session_recvfrom(session, TRUE, mp, 0, NULL, NULL);
}else if (rtp_session_using_transport(session, rtp)) {
error = (session->rtp.gs.tr->t_recvfrom)(session->rtp.gs.tr, mp, 0, (struct sockaddr *) &remaddr, &addrlen);
} else {
error = rtp_session_rtp_recv_abstract(sockfd, mp, 0, (struct sockaddr *) &remaddr, &addrlen);
error = rtp_session_recvfrom(session, TRUE, mp, 0, (struct sockaddr *) &remaddr, &addrlen);
}
if (error > 0){
mp->b_wptr+=error;
......@@ -1640,7 +1643,7 @@ int rtp_session_rtcp_recv (RtpSession * session) {
mp->reserved1 = session->rtp.rcv_last_app_ts;
if (sock_connected){
error=rtp_session_rtp_recv_abstract(session->rtcp.gs.socket, mp, 0, NULL, NULL);
error=rtp_session_recvfrom(session, FALSE, mp, 0, NULL, NULL);
}else{
addrlen=sizeof (remaddr);
......@@ -1649,7 +1652,7 @@ int rtp_session_rtcp_recv (RtpSession * session) {
(struct sockaddr *) &remaddr,
&addrlen);
}else{
error=rtp_session_rtp_recv_abstract (session->rtcp.gs.socket,mp, 0,
error=rtp_session_recvfrom(session, FALSE, mp, 0,
(struct sockaddr *) &remaddr,
&addrlen);
}
......
......@@ -343,3 +343,19 @@ mblk_t *msgb_allocator_alloc(msgb_allocator_t *a, size_t size){
void msgb_allocator_uninit(msgb_allocator_t *a){
flushq(&a->q,-1);
}
void ortp_recvaddr_to_sockaddr(ortp_recv_addr_t *recvaddr, struct sockaddr *addr, socklen_t *socklen) {
if (recvaddr->family == AF_INET) {
struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
addr_in->sin_family = AF_INET;
addr_in->sin_addr = recvaddr->addr.ipi_addr;
addr_in->sin_port = recvaddr->port;
*socklen = sizeof(struct sockaddr_in);
} else if (recvaddr->family == AF_INET6) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
addr_in6->sin6_family = AF_INET6;
addr_in6->sin6_addr = recvaddr->addr.ipi6_addr;
addr_in6->sin6_port = recvaddr->port;
*socklen = sizeof(struct sockaddr_in6);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment