From owner-freebsd-ports-bugs Thu Mar 20 13:10:20 2003 Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 750CE37B404 for ; Thu, 20 Mar 2003 13:10:14 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 212B943FB1 for ; Thu, 20 Mar 2003 13:10:12 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h2KLABNS022009 for ; Thu, 20 Mar 2003 13:10:11 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h2KLABIh022008; Thu, 20 Mar 2003 13:10:11 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2172037B401 for ; Thu, 20 Mar 2003 13:01:01 -0800 (PST) Received: from g.web.am (g.web.am [217.113.0.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id 88F4043F3F for ; Thu, 20 Mar 2003 13:00:59 -0800 (PST) (envelope-from nm@g.web.am) Received: from g.web.am (localhost.web.am [127.0.0.1]) by g.web.am (8.12.7/8.12.6) with ESMTP id h2KL0v7Q031203; Fri, 21 Mar 2003 01:00:57 +0400 (AMT) (envelope-from nm@g.web.am) Received: (from nm@localhost) by g.web.am (8.12.7/8.12.6/Submit) id h2KL0ptx031202; Fri, 21 Mar 2003 01:00:51 +0400 (AMT) Message-Id: <200303202100.h2KL0ptx031202@g.web.am> Date: Fri, 21 Mar 2003 01:00:51 +0400 (AMT) From: Gaspar Chilingarov To: FreeBSD-gnats-submit@FreeBSD.org Cc: nm@web.am X-Send-Pr-Version: 3.113 Subject: ports/50147: socketbind - new port submission Sender: owner-freebsd-ports-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 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 X#include X#include X#include X#include 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 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 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