annotate libutil/sockinit.c @ 6:33d8b3177540

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