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