view libutil/sockinit.c @ 124:7e04d28fae8b

sip-in: default use-100rel to no BulkVS servers act badly when we send a reliable 180 Ringing response to an incoming call, even though they advertise 100rel support in the Supported header in the INVITE packet, and we probably won't be implementing 100rel for outbound because doing per-the-spec PRACK as a UAC is just too burdensome. Therefore, we need to consider 100rel extension as not-really-supported in themwi-system-sw.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 15:54:50 -0800
parents dbc0a8677b69
children
line wrap: on
line source

/*
 * This library module implements a function that helps initialize
 * sockaddr for bind or connect operations on UNIX domain sockets.
 *
 * Back when I programmed under 4.3BSD UNIX, this operation was simple
 * and straightforward - but under "modern" Unixes, it appears to be
 * a complex affair, given the messy code (originally copied from
 * Osmocom) that appears in FreeCalypso host tools for the rvinterf
 * local socket interface.  Hence I am factoring that mess out into
 * its own library function this time around.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <strings.h>

void
fill_sockaddr_un(pathname, sunp, lenp)
	char *pathname;
	struct sockaddr_un *sunp;
	unsigned *lenp;
{
	/* local socket binding voodoo copied from osmocon */
	sunp->sun_family = AF_UNIX;
	strncpy(sunp->sun_path, pathname, sizeof(sunp->sun_path));
	sunp->sun_path[sizeof(sunp->sun_path) - 1] = '\0';
	/* we use the same magic that X11 uses in Xtranssock.c for
	 * calculating the proper length of the sockaddr */
#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
	sunp->sun_len = strlen(sunp->sun_path);
#endif
#if defined(BSD44SOCKETS) || defined(SUN_LEN)
	*lenp = SUN_LEN(sunp);
#else
	*lenp = strlen(sunp->sun_path) +
		offsetof(struct sockaddr_un, sun_path) + 1;
#endif
}