diff options
author | Eugene Grosbein <eugen@FreeBSD.org> | 2023-10-05 20:05:10 +0700 |
---|---|---|
committer | Eugene Grosbein <eugen@FreeBSD.org> | 2023-10-05 20:16:51 +0700 |
commit | 03a9755147acbd1933f5c991ce33ae1bc375746d (patch) | |
tree | fc79283f7f568b5d39836ad2607e60f20fd61f43 /net/socketbind | |
parent | audio/py-pyradio: Update to 0.9.2.15 (diff) |
net/socketbind: unbreak the library
The code has multiple issues making it unusable with modern FreeBSD:
* it uses long gone ascii2addr() function removed in 2007;
* it passes hardcoded "/usr/lib/libc.so" path to dlopen(),
but now it is plain text hint file;
* this IPv4-only code neglects to check passed domain for PF_INET
messing with sockets in other domains (like PF_INET6, PF_LOCAL).
Still, it is very useful while dealing with software like Nagios
that does not support binding to specific IPv4 address
for outgoing connections. The library solves the problem with single line
in /etc/rc.conf:
nagios_env="LD_PRELOAD=/usr/local/lib/libsocketbind.so.1 BINDTO=192.168.6.1"
This changes unbreaks the library making it usable again.
Diffstat (limited to 'net/socketbind')
-rw-r--r-- | net/socketbind/Makefile | 1 | ||||
-rw-r--r-- | net/socketbind/files/socketbind.c | 15 |
2 files changed, 8 insertions, 8 deletions
diff --git a/net/socketbind/Makefile b/net/socketbind/Makefile index 3725a84f17b0..bf17612645ba 100644 --- a/net/socketbind/Makefile +++ b/net/socketbind/Makefile @@ -1,5 +1,6 @@ PORTNAME= socketbind PORTVERSION= 1 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= # none DISTFILES= # none diff --git a/net/socketbind/files/socketbind.c b/net/socketbind/files/socketbind.c index 51d929d9b794..340083adaefb 100644 --- a/net/socketbind/files/socketbind.c +++ b/net/socketbind/files/socketbind.c @@ -2,32 +2,31 @@ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> +#include <arpa/inet.h> #include <dlfcn.h> +#include <stdlib.h> -static void *socket_p, *dl_handle; +static void *socket_p = NULL; static struct sockaddr_in bind_addr; static int do_bind; int socket(int domain, int type, int protocol) { auto int res; - if (dl_handle == NULL) { + if (socket_p == NULL) { char *str; - dl_handle = dlopen("/usr/lib/libc.so", RTLD_LAZY); - if (dl_handle == NULL) - return -1; - socket_p = dlsym(dl_handle, "socket"); + socket_p = dlsym(RTLD_NEXT, "socket"); if (!socket_p) return -1; #ifdef DEBUG printf("Loaded socket %x\n", socket_p); #endif - if ((str = getenv("BINDTO")) != NULL) { + if ((domain == PF_INET) && (str = getenv("BINDTO")) != NULL) { #ifdef DEBUG printf("Thinking about bind\n"); #endif - if (ascii2addr(AF_INET, str, &bind_addr.sin_addr)) { + if (inet_aton(str, &bind_addr.sin_addr)) { do_bind = 1; bind_addr.sin_len = INET_ADDRSTRLEN; bind_addr.sin_family = AF_INET; |