# HG changeset patch # User Mychaela Falconia # Date 1732388908 0 # Node ID 8f1700a42ca519e25c4dfdfc65a687d5b8e75171 # Parent 84affc6de3659ffe5f69b274dd395506d9f31ad0 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. diff -r 84affc6de365 -r 8f1700a42ca5 include/endp.h --- a/include/endp.h Tue Jul 09 02:22:18 2024 +0000 +++ b/include/endp.h Sat Nov 23 19:08:28 2024 +0000 @@ -88,6 +88,12 @@ void twrtp_endp_set_remote_ipv4(struct twrtp_endp *endp, const struct in_addr *ip, uint16_t port); +void twrtp_endp_set_remote_ipv6(struct twrtp_endp *endp, + const struct in6_addr *ip6, uint16_t port); +void twrtp_endp_set_remote_sin(struct twrtp_endp *endp, + const struct sockaddr_in *sin); +void twrtp_endp_set_remote_sin6(struct twrtp_endp *endp, + const struct sockaddr_in6 *sin6); int twrtp_endp_tx_quantum(struct twrtp_endp *endp, const uint8_t *payload, unsigned payload_len, uint8_t payload_type, diff -r 84affc6de365 -r 8f1700a42ca5 src/set_remote.c --- a/src/set_remote.c Tue Jul 09 02:22:18 2024 +0000 +++ b/src/set_remote.c Sat Nov 23 19:08:28 2024 +0000 @@ -1,6 +1,6 @@ /* * Here we implement functions for setting the remote end on themwi_endp, - * initially only IPv4, then possibly IPv6 in the future. + * both IPv4 and IPv6. */ #include @@ -25,3 +25,32 @@ endp->remote_set = true; } + +void twrtp_endp_set_remote_ipv6(struct twrtp_endp *endp, + const struct in6_addr *ip6, uint16_t port) +{ + endp->rtp_remote.u.sin6.sin6_family = AF_INET6; + memcpy(&endp->rtp_remote.u.sin6.sin6_addr, ip6, + sizeof(struct in6_addr)); + endp->rtp_remote.u.sin6.sin6_port = htons(port); + + endp->rtcp_remote.u.sin6.sin6_family = AF_INET6; + memcpy(&endp->rtcp_remote.u.sin6.sin6_addr, ip6, + sizeof(struct in6_addr)); + endp->rtcp_remote.u.sin6.sin6_port = htons(port + 1); + + endp->remote_set = true; +} + +void twrtp_endp_set_remote_sin(struct twrtp_endp *endp, + const struct sockaddr_in *sin) +{ + twrtp_endp_set_remote_ipv4(endp, &sin->sin_addr, ntohs(sin->sin_port)); +} + +void twrtp_endp_set_remote_sin6(struct twrtp_endp *endp, + const struct sockaddr_in6 *sin6) +{ + twrtp_endp_set_remote_ipv6(endp, &sin6->sin6_addr, + ntohs(sin6->sin6_port)); +}