view src/set_remote.c @ 42:334d883b96ba

twrtp_jibuf_create: make config argument const While this config structure is not a constant in the mathematical sense of the term (it is expected that vty config changes may happen while twjit instance is alive), twjit functions never write to it, only read, hence it is 'const' in the not-quite-mathematical C-standard sense.
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 20 Dec 2024 22:47:20 +0000
parents 8f1700a42ca5
children
line wrap: on
line source

/*
 * Here we implement functions for setting the remote end on themwi_endp,
 * both IPv4 and IPv6.
 */

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#include <themwi/rtp/endp.h>

void twrtp_endp_set_remote_ipv4(struct twrtp_endp *endp,
				const struct in_addr *ip, uint16_t port)
{
	endp->rtp_remote.u.sin.sin_family = AF_INET;
	memcpy(&endp->rtp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr));
	endp->rtp_remote.u.sin.sin_port = htons(port);

	endp->rtcp_remote.u.sin.sin_family = AF_INET;
	memcpy(&endp->rtcp_remote.u.sin.sin_addr, ip, sizeof(struct in_addr));
	endp->rtcp_remote.u.sin.sin_port = htons(port + 1);

	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));
}