annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement functions for setting the remote end on themwi_endp,
37
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
3 * both IPv4 and IPv6.
22
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <arpa/inet.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdbool.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <themwi/rtp/endp.h>
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 void twrtp_endp_set_remote_ipv4(struct twrtp_endp *endp,
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 const struct in_addr *ip, uint16_t port)
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 endp->rtp_remote.u.sin.sin_family = AF_INET;
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 memcpy(&endp->rtp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr));
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 endp->rtp_remote.u.sin.sin_port = htons(port);
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 endp->rtcp_remote.u.sin.sin_family = AF_INET;
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 memcpy(&endp->rtcp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr));
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 endp->rtcp_remote.u.sin.sin_port = htons(port + 1);
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 endp->remote_set = true;
587437b62ed5 implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
37
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
28
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
29 void twrtp_endp_set_remote_ipv6(struct twrtp_endp *endp,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
30 const struct in6_addr *ip6, uint16_t port)
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
31 {
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
32 endp->rtp_remote.u.sin6.sin6_family = AF_INET6;
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
33 memcpy(&endp->rtp_remote.u.sin6.sin6_addr, ip6,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
34 sizeof(struct in6_addr));
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
35 endp->rtp_remote.u.sin6.sin6_port = htons(port);
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
36
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
37 endp->rtcp_remote.u.sin6.sin6_family = AF_INET6;
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
38 memcpy(&endp->rtcp_remote.u.sin6.sin6_addr, ip6,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
39 sizeof(struct in6_addr));
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
40 endp->rtcp_remote.u.sin6.sin6_port = htons(port + 1);
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
41
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
42 endp->remote_set = true;
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
43 }
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
44
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
45 void twrtp_endp_set_remote_sin(struct twrtp_endp *endp,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
46 const struct sockaddr_in *sin)
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
47 {
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
48 twrtp_endp_set_remote_ipv4(endp, &sin->sin_addr, ntohs(sin->sin_port));
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
49 }
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
50
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
51 void twrtp_endp_set_remote_sin6(struct twrtp_endp *endp,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
52 const struct sockaddr_in6 *sin6)
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
53 {
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
54 twrtp_endp_set_remote_ipv6(endp, &sin6->sin6_addr,
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
55 ntohs(sin6->sin6_port));
8f1700a42ca5 set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
56 }