Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Mar 2003 01:00:51 +0400 (AMT)
From:      Gaspar Chilingarov <nm@web.am>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        nm@web.am
Subject:   ports/50147: socketbind - new port submission
Message-ID:  <200303202100.h2KL0ptx031202@g.web.am>

next in thread | raw e-mail | index | archive | help

>Number:         50147
>Category:       ports
>Synopsis:       socketbind - new port submission
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 20 13:10:11 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Gaspar Chilingarov
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
WEB Ltd.
>Environment:
System: FreeBSD  5.0-CURRENT FreeBSD 5.0-CURRENT #0: Thu Mar 20 22:11:55 AMT 2003 root@:/usr/obj/usr/src/sys/nm i386


	
>Description:

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.

>How-To-Repeat:
see shar archive below
>Fix:

--cut--
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	socketbind
#	socketbind/files
#	socketbind/files/Makefile
#	socketbind/files/socketbind.c
#	socketbind/Makefile
#	socketbind/pkg-plist
#	socketbind/pkg-descr
#
echo c - socketbind
mkdir -p socketbind > /dev/null 2>&1
echo c - socketbind/files
mkdir -p socketbind/files > /dev/null 2>&1
echo x - socketbind/files/Makefile
sed 's/^X//' >socketbind/files/Makefile << 'END-of-socketbind/files/Makefile'
XLIB=socketbind
XSHLIB_MAJOR=1
X
XDESTDIR=/usr/local
XSRCS=socketbind.c
XNOMAN=YES
X#DEBUG_FLAGS=-DDEBUG
X
X
X.include <bsd.lib.mk>
END-of-socketbind/files/Makefile
echo x - socketbind/files/socketbind.c
sed 's/^X//' >socketbind/files/socketbind.c << 'END-of-socketbind/files/socketbind.c'
X#include <stdlib.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <dlfcn.h>
X
Xstatic void *socket_p, *dl_handle;
X
Xstatic struct sockaddr_in bind_addr;
Xstatic int	   do_bind;
X
Xint socket(int domain, int type, int protocol) {
X	auto int res;
X	if (dl_handle == NULL) {
X		char *str;
X		dl_handle = dlopen("/usr/lib/libc.so", RTLD_LAZY);
X		if (dl_handle == NULL) 
X			return -1;
X		socket_p = dlsym(dl_handle, "socket");
X		if (!socket_p)
X			return -1;
X#ifdef DEBUG
X		printf("Loaded socket %x\n", socket_p);
X#endif
X
X		if ((str = getenv("BINDTO")) != NULL) {
X#ifdef DEBUG
X			printf("Thinking about bind\n");
X#endif
X			if (ascii2addr(AF_INET, str, &bind_addr.sin_addr)) {
X				do_bind = 1;
X				bind_addr.sin_len = INET_ADDRSTRLEN;
X				bind_addr.sin_family = AF_INET;
X#ifdef DEBUG
X				printf("WILL DO BIND %s, %x\n", str, bind_addr.sin_addr.s_addr);
X#endif
X			}
X		}
X	}
X	res = ((int(*)(int a, int b, int c))socket_p)(domain, type, protocol); 
X	if (do_bind) {
X		bind(res, (struct sockaddr*)&bind_addr, INET_ADDRSTRLEN);
X	}
X	return res;
X};
X
END-of-socketbind/files/socketbind.c
echo x - socketbind/Makefile
sed 's/^X//' >socketbind/Makefile << 'END-of-socketbind/Makefile'
X# New ports collection makefile for:    socketbind
X# Date created:         		20 Mar 2003
X# Whom:                 		Gaspar Chilingarov <nm@web.am>
X#
X# $FreeBSD:$
X#
X
XMAINTAINER=	nm@web.am
XCOMMENT=Library to bind applications on multihomed machines to specefic IP address. 
X
XPORTNAME=socketbind
XPORTVERSION=1
XCATEGORIES=net
XDISTFILES=
XINSTALLS_SHLIB=YES
XNOMAN=YES
XINSTALL_TARGET=
XPLIST_SUB="DOCSDIR=share/doc/${PORTNAME}"
X
X
Xpost-extract:
X	${MKDIR} ${WRKSRC}
X	${CP} -R ${PATCHDIR}/ ${WRKSRC}
X
Xpre-install:
X	${INSTALL_PROGRAM} ${WRKSRC}/libsocketbind.so.1 ${PREFIX}/lib
X	${LN} -s ${PREFIX}/lib/libsocketbind.so.1 ${PREFIX}/lib/libsocketbind.so
X	${MKDIR} ${DOCSDIR}
X	echo "This library allows to bind arbitrary program, " >> ${DOCSDIR}/README 
X	echo "which is dynamically linked to libc.so." >> ${DOCSDIR}/README 
X	echo "Load library before your program (set environment " >> ${DOCSDIR}/README 
X	echo "variable LD_PRELOAD=${PREFIX}/lib/libsocketbind.so.1) " >> ${DOCSDIR}/README 
X	echo "and set address to bind to (set environment variable " >> ${DOCSDIR}/README 
X	echo "BINDTO=ip address to bind)" >> ${DOCSDIR}/README 
X
X.include <bsd.port.mk>
X
END-of-socketbind/Makefile
echo x - socketbind/pkg-plist
sed 's/^X//' >socketbind/pkg-plist << 'END-of-socketbind/pkg-plist'
Xlib/libsocketbind.so.1
Xlib/libsocketbind.so
X%%DOCSDIR%%/README
X@dirrm %%DOCSDIR%%
END-of-socketbind/pkg-plist
echo x - socketbind/pkg-descr
sed 's/^X//' >socketbind/pkg-descr << 'END-of-socketbind/pkg-descr'
XThis library allows you to bind any application which is dynamically linked
Xwith libc. It provides convient way to bind socket's source IP to one of the
Xmultiple IP's available on computer.
X
XTo use it first of all point LD_PRELOAD to installed library and set BINDTO
Xvariable to desired IP address to bind.
X
XHere is the wrapper to run any command binded to some IP address:
Xenv LD_PRELOAD=/usr/local/lib/libsocketbind.so.1 BINDTO=$MY_IP_ADDRESS $*
X
XAuthor can be reached at "nm at web dot am" address.
END-of-socketbind/pkg-descr
exit
--cut--

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303202100.h2KL0ptx031202>