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>
This commit is contained in:
Edwin Groothuis
2003-04-01 00:49:48 +00:00
parent 8b6ff144cb
commit fd7e8698ab
6 changed files with 110 additions and 0 deletions

View File

@@ -588,6 +588,7 @@
SUBDIR += sniffit
SUBDIR += sntop
SUBDIR += socat
SUBDIR += socketbind
SUBDIR += socks5
SUBDIR += spread
SUBDIR += ssldump

37
net/socketbind/Makefile Normal file
View File

@@ -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>

View File

@@ -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>

View File

@@ -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;
};

11
net/socketbind/pkg-descr Normal file
View File

@@ -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.

4
net/socketbind/pkg-plist Normal file
View File

@@ -0,0 +1,4 @@
lib/libsocketbind.so.1
lib/libsocketbind.so
%%DOCSDIR%%/README
@dirrm %%DOCSDIR%%