summaryrefslogtreecommitdiff
path: root/net/socketbind/files
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2023-10-05 20:05:10 +0700
committerEugene Grosbein <eugen@FreeBSD.org>2023-10-05 20:16:51 +0700
commit03a9755147acbd1933f5c991ce33ae1bc375746d (patch)
treefc79283f7f568b5d39836ad2607e60f20fd61f43 /net/socketbind/files
parentaudio/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/files')
-rw-r--r--net/socketbind/files/socketbind.c15
1 files changed, 7 insertions, 8 deletions
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;