FreeCalypso > hg > sipout-test-utils
comparison libutil/sockinit.c @ 0:35c0d9f03c0a
beginning with sipout-test-voice,
a copy of sip-manual-out from themwi-system-sw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Mar 2024 23:20:19 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:35c0d9f03c0a |
---|---|
1 /* | |
2 * This library module implements a function that helps initialize | |
3 * sockaddr for bind or connect operations on UNIX domain sockets. | |
4 * | |
5 * Back when I programmed under 4.3BSD UNIX, this operation was simple | |
6 * and straightforward - but under "modern" Unixes, it appears to be | |
7 * a complex affair, given the messy code (originally copied from | |
8 * Osmocom) that appears in FreeCalypso host tools for the rvinterf | |
9 * local socket interface. Hence I am factoring that mess out into | |
10 * its own library function this time around. | |
11 */ | |
12 | |
13 #include <sys/types.h> | |
14 #include <sys/socket.h> | |
15 #include <sys/un.h> | |
16 #include <string.h> | |
17 #include <strings.h> | |
18 | |
19 void | |
20 fill_sockaddr_un(pathname, sunp, lenp) | |
21 char *pathname; | |
22 struct sockaddr_un *sunp; | |
23 unsigned *lenp; | |
24 { | |
25 /* local socket binding voodoo copied from osmocon */ | |
26 sunp->sun_family = AF_UNIX; | |
27 strncpy(sunp->sun_path, pathname, sizeof(sunp->sun_path)); | |
28 sunp->sun_path[sizeof(sunp->sun_path) - 1] = '\0'; | |
29 /* we use the same magic that X11 uses in Xtranssock.c for | |
30 * calculating the proper length of the sockaddr */ | |
31 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__) | |
32 sunp->sun_len = strlen(sunp->sun_path); | |
33 #endif | |
34 #if defined(BSD44SOCKETS) || defined(SUN_LEN) | |
35 *lenp = SUN_LEN(sunp); | |
36 #else | |
37 *lenp = strlen(sunp->sun_path) + | |
38 offsetof(struct sockaddr_un, sun_path) + 1; | |
39 #endif | |
40 } |