# HG changeset patch # User Mychaela Falconia # Date 1656210809 28800 # Node ID dbc0a8677b6934c88ddb7accadacfcf8a5664f22 # Parent 0e907d59d8154a580014a0ca12c2d27a8bef8d1f libutil: import from ThemWi1 diff -r 0e907d59d815 -r dbc0a8677b69 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Jun 25 18:33:29 2022 -0800 @@ -0,0 +1,3 @@ +syntax: regexp + +\.[oa]$ diff -r 0e907d59d815 -r dbc0a8677b69 libutil/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/Makefile Sat Jun 25 18:33:29 2022 -0800 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= mncc_utils.o sockinit.o +LIB= libutil.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r 0e907d59d815 -r dbc0a8677b69 libutil/mncc_utils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/mncc_utils.c Sat Jun 25 18:33:29 2022 -0800 @@ -0,0 +1,18 @@ +/* simple utility functions for MNCC */ + +#include +#include +#include +#include +#include +#include "../include/mncc.h" +#include "../include/gsm48_const.h" + +mncc_set_cause(msg, loc, val) + struct gsm_mncc *msg; +{ + msg->fields |= MNCC_F_CAUSE; + msg->cause.coding = GSM48_CAUSE_CODING_GSM; + msg->cause.location = loc; + msg->cause.value = val; +} diff -r 0e907d59d815 -r dbc0a8677b69 libutil/sockinit.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/sockinit.c Sat Jun 25 18:33:29 2022 -0800 @@ -0,0 +1,40 @@ +/* + * 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 +#include +#include +#include +#include + +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 +}