FreeCalypso > hg > themwi-rtp-lib
comparison src/set_remote.c @ 37:8f1700a42ca5 default tip
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
A convenient way to pass in remote end address as struct sockaddr_in
is needed for tw-border-mgw; IPv6 support will be needed in order to
bring twrtp_endp into Osmocom mainline.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 23 Nov 2024 19:08:28 +0000 |
parents | 587437b62ed5 |
children |
comparison
equal
deleted
inserted
replaced
36:84affc6de365 | 37:8f1700a42ca5 |
---|---|
1 /* | 1 /* |
2 * Here we implement functions for setting the remote end on themwi_endp, | 2 * Here we implement functions for setting the remote end on themwi_endp, |
3 * initially only IPv4, then possibly IPv6 in the future. | 3 * both IPv4 and IPv6. |
4 */ | 4 */ |
5 | 5 |
6 #include <sys/socket.h> | 6 #include <sys/socket.h> |
7 #include <netinet/in.h> | 7 #include <netinet/in.h> |
8 #include <arpa/inet.h> | 8 #include <arpa/inet.h> |
23 memcpy(&endp->rtcp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr)); | 23 memcpy(&endp->rtcp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr)); |
24 endp->rtcp_remote.u.sin.sin_port = htons(port + 1); | 24 endp->rtcp_remote.u.sin.sin_port = htons(port + 1); |
25 | 25 |
26 endp->remote_set = true; | 26 endp->remote_set = true; |
27 } | 27 } |
28 | |
29 void twrtp_endp_set_remote_ipv6(struct twrtp_endp *endp, | |
30 const struct in6_addr *ip6, uint16_t port) | |
31 { | |
32 endp->rtp_remote.u.sin6.sin6_family = AF_INET6; | |
33 memcpy(&endp->rtp_remote.u.sin6.sin6_addr, ip6, | |
34 sizeof(struct in6_addr)); | |
35 endp->rtp_remote.u.sin6.sin6_port = htons(port); | |
36 | |
37 endp->rtcp_remote.u.sin6.sin6_family = AF_INET6; | |
38 memcpy(&endp->rtcp_remote.u.sin6.sin6_addr, ip6, | |
39 sizeof(struct in6_addr)); | |
40 endp->rtcp_remote.u.sin6.sin6_port = htons(port + 1); | |
41 | |
42 endp->remote_set = true; | |
43 } | |
44 | |
45 void twrtp_endp_set_remote_sin(struct twrtp_endp *endp, | |
46 const struct sockaddr_in *sin) | |
47 { | |
48 twrtp_endp_set_remote_ipv4(endp, &sin->sin_addr, ntohs(sin->sin_port)); | |
49 } | |
50 | |
51 void twrtp_endp_set_remote_sin6(struct twrtp_endp *endp, | |
52 const struct sockaddr_in6 *sin6) | |
53 { | |
54 twrtp_endp_set_remote_ipv6(endp, &sin6->sin6_addr, | |
55 ntohs(sin6->sin6_port)); | |
56 } |