annotate libutil/sockinit.c @ 140:01fe81914bd6

sip-in: move MNCC_RTP_CONNECT sending to answer time
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Oct 2022 11:48:26 -0800
parents dbc0a8677b69
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This library module implements a function that helps initialize
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * sockaddr for bind or connect operations on UNIX domain sockets.
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Back when I programmed under 4.3BSD UNIX, this operation was simple
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * and straightforward - but under "modern" Unixes, it appears to be
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * a complex affair, given the messy code (originally copied from
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * Osmocom) that appears in FreeCalypso host tools for the rvinterf
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * local socket interface. Hence I am factoring that mess out into
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * its own library function this time around.
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 */
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <sys/types.h>
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <sys/socket.h>
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <sys/un.h>
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <string.h>
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <strings.h>
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 void
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 fill_sockaddr_un(pathname, sunp, lenp)
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *pathname;
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 struct sockaddr_un *sunp;
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned *lenp;
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 /* local socket binding voodoo copied from osmocon */
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 sunp->sun_family = AF_UNIX;
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 strncpy(sunp->sun_path, pathname, sizeof(sunp->sun_path));
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 sunp->sun_path[sizeof(sunp->sun_path) - 1] = '\0';
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* we use the same magic that X11 uses in Xtranssock.c for
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * calculating the proper length of the sockaddr */
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sunp->sun_len = strlen(sunp->sun_path);
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #endif
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *lenp = SUN_LEN(sunp);
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #else
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *lenp = strlen(sunp->sun_path) +
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 offsetof(struct sockaddr_un, sun_path) + 1;
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #endif
dbc0a8677b69 libutil: import from ThemWi1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }