summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorEdwin Groothuis <edwin@FreeBSD.org>2003-04-01 00:49:48 +0000
committerEdwin Groothuis <edwin@FreeBSD.org>2003-04-01 00:49:48 +0000
commitfd7e8698abcbdf8abb049c07acbff5238dbd54ff (patch)
tree96c15bcf8ad29fdce9dd30050b8fd4f7b7f0e5c3 /net
parentUpdate of mail/wmbiff to 0.4.15 and add support for gnutls (SSL). (diff)
socketbind - new port submission
This library allows you to bind any application which is dynamically linked with libc to certain IP address. It provides convient way to bind socket's source IP to one of the multiple IP's available on computer. PR: ports/50147 Submitted by: Gaspar Chilingarov <nm@web.am>
Notes
Notes: svn path=/head/; revision=77877
Diffstat (limited to 'net')
-rw-r--r--net/Makefile1
-rw-r--r--net/socketbind/Makefile37
-rw-r--r--net/socketbind/files/Makefile11
-rw-r--r--net/socketbind/files/socketbind.c46
-rw-r--r--net/socketbind/pkg-descr11
-rw-r--r--net/socketbind/pkg-plist4
6 files changed, 110 insertions, 0 deletions
diff --git a/net/Makefile b/net/Makefile
index 87f6f38b3a53..a82d2637010e 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -588,6 +588,7 @@
SUBDIR += sniffit
SUBDIR += sntop
SUBDIR += socat
+ SUBDIR += socketbind
SUBDIR += socks5
SUBDIR += spread
SUBDIR += ssldump
diff --git a/net/socketbind/Makefile b/net/socketbind/Makefile
new file mode 100644
index 000000000000..6652b81aa033
--- /dev/null
+++ b/net/socketbind/Makefile
@@ -0,0 +1,37 @@
+# New ports collection makefile for: socketbind
+# Date created: 20 Mar 2003
+# Whom: Gaspar Chilingarov <nm@web.am>
+#
+# $FreeBSD$
+#
+
+PORTNAME= socketbind
+PORTVERSION= 1
+CATEGORIES= net
+MASTER_SITES= # none
+DISTFILES= # none
+
+MAINTAINER= nm@web.am
+COMMENT= Library to bind applications on multihomed machines to specefic IP address
+
+INSTALLS_SHLIB= YES
+NOMAN= YES
+INSTALL_TARGET=
+PLIST_SUB= "DOCSDIR=share/doc/${PORTNAME}"
+
+post-extract:
+ ${MKDIR} ${WRKSRC}
+ ${CP} -R ${PATCHDIR}/ ${WRKSRC}
+
+pre-install:
+ ${INSTALL_PROGRAM} ${WRKSRC}/libsocketbind.so.1 ${PREFIX}/lib
+ ${LN} -s ${PREFIX}/lib/libsocketbind.so.1 ${PREFIX}/lib/libsocketbind.so
+ ${MKDIR} ${DOCSDIR}
+ ${ECHO} "This library allows to bind arbitrary program, " >> ${DOCSDIR}/README
+ ${ECHO} "which is dynamically linked to libc.so." >> ${DOCSDIR}/README
+ ${ECHO} "Load library before your program (set environment " >> ${DOCSDIR}/README
+ ${ECHO} "variable LD_PRELOAD=${PREFIX}/lib/libsocketbind.so.1) " >> ${DOCSDIR}/README
+ ${ECHO} "and set address to bind to (set environment variable " >> ${DOCSDIR}/README
+ ${ECHO} "BINDTO=ip address to bind)" >> ${DOCSDIR}/README
+
+.include <bsd.port.mk>
diff --git a/net/socketbind/files/Makefile b/net/socketbind/files/Makefile
new file mode 100644
index 000000000000..fa3232ac9c11
--- /dev/null
+++ b/net/socketbind/files/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+LIB=socketbind
+SHLIB_MAJOR=1
+
+DESTDIR=/usr/local
+SRCS=socketbind.c
+NOMAN=YES
+#DEBUG_FLAGS=-DDEBUG
+
+
+.include <bsd.lib.mk>
diff --git a/net/socketbind/files/socketbind.c b/net/socketbind/files/socketbind.c
new file mode 100644
index 000000000000..51d929d9b794
--- /dev/null
+++ b/net/socketbind/files/socketbind.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <dlfcn.h>
+
+static void *socket_p, *dl_handle;
+
+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) {
+ char *str;
+ dl_handle = dlopen("/usr/lib/libc.so", RTLD_LAZY);
+ if (dl_handle == NULL)
+ return -1;
+ socket_p = dlsym(dl_handle, "socket");
+ if (!socket_p)
+ return -1;
+#ifdef DEBUG
+ printf("Loaded socket %x\n", socket_p);
+#endif
+
+ if ((str = getenv("BINDTO")) != NULL) {
+#ifdef DEBUG
+ printf("Thinking about bind\n");
+#endif
+ if (ascii2addr(AF_INET, str, &bind_addr.sin_addr)) {
+ do_bind = 1;
+ bind_addr.sin_len = INET_ADDRSTRLEN;
+ bind_addr.sin_family = AF_INET;
+#ifdef DEBUG
+ printf("WILL DO BIND %s, %x\n", str, bind_addr.sin_addr.s_addr);
+#endif
+ }
+ }
+ }
+ res = ((int(*)(int a, int b, int c))socket_p)(domain, type, protocol);
+ if (do_bind) {
+ bind(res, (struct sockaddr*)&bind_addr, INET_ADDRSTRLEN);
+ }
+ return res;
+};
+
diff --git a/net/socketbind/pkg-descr b/net/socketbind/pkg-descr
new file mode 100644
index 000000000000..29558cecb0e6
--- /dev/null
+++ b/net/socketbind/pkg-descr
@@ -0,0 +1,11 @@
+This library allows you to bind any application which is dynamically linked
+with libc. It provides convient way to bind socket's source IP to one of the
+multiple IP's available on computer.
+
+To use it first of all point LD_PRELOAD to installed library and set BINDTO
+variable to desired IP address to bind.
+
+Here is the wrapper to run any command binded to some IP address:
+env LD_PRELOAD=/usr/local/lib/libsocketbind.so.1 BINDTO=$MY_IP_ADDRESS $*
+
+Author can be reached at "nm at web dot am" address.
diff --git a/net/socketbind/pkg-plist b/net/socketbind/pkg-plist
new file mode 100644
index 000000000000..550ede79f431
--- /dev/null
+++ b/net/socketbind/pkg-plist
@@ -0,0 +1,4 @@
+lib/libsocketbind.so.1
+lib/libsocketbind.so
+%%DOCSDIR%%/README
+@dirrm %%DOCSDIR%%