diff -burN copy/src/lib/libc/amd64/SYS.h src/lib/libc/amd64/SYS.h
--- copy/src/lib/libc/amd64/SYS.h	Sun Feb 22 02:11:39 2004
+++ src/lib/libc/amd64/SYS.h	Wed Sep 21 14:53:49 2005
@@ -64,3 +64,13 @@
 			mov __CONCAT($SYS_,x),%rax; KERNCALL; ret
 
 #define KERNCALL	movq %rcx, %r10; syscall
+
+#ifdef PIC
+#define	RSYSCALL2(x)	ENTRY(__CONCAT(___sys_,x));			\
+			mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret; \
+			2: movq PIC_GOT(HIDENAME(cerror)),%rcx; jmp *%rcx
+#else
+#define	RSYSCALL2(x)	ENTRY(__CONCAT(___sys_,x));			\
+			mov __CONCAT($SYS_,x),%rax; KERNCALL; jb 2f; ret; \
+			2: jmp HIDENAME(cerror)
+#endif
diff -burN copy/src/lib/libc/amd64/sys/Makefile.inc src/lib/libc/amd64/sys/Makefile.inc
--- copy/src/lib/libc/amd64/sys/Makefile.inc	Thu Oct 23 06:07:09 2003
+++ src/lib/libc/amd64/sys/Makefile.inc	Wed Sep 21 14:53:49 2005
@@ -4,7 +4,7 @@
 SRCS+=	amd64_get_fsbase.c amd64_get_gsbase.c amd64_set_fsbase.c amd64_set_gsbase.c
 
 MDASM=	vfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
-	reboot.S sbrk.S setlogin.S sigreturn.S
+	reboot.S sbrk.S setlogin.S sigreturn.S bind.S listen.S connect.S
 
 # Don't generate default code for these syscalls:
 NOASM=	break.o exit.o ftruncate.o getdomainname.o getlogin.o \
diff -burN copy/src/lib/libc/amd64/sys/bind.S src/lib/libc/amd64/sys/bind.S
--- copy/src/lib/libc/amd64/sys/bind.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/amd64/sys/bind.S	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,3 @@
+#include "SYS.h"
+
+RSYSCALL2(bind)
diff -burN copy/src/lib/libc/amd64/sys/connect.S src/lib/libc/amd64/sys/connect.S
--- copy/src/lib/libc/amd64/sys/connect.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/amd64/sys/connect.S	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,3 @@
+#include "SYS.h"
+
+RSYSCALL2(connect)
diff -burN copy/src/lib/libc/amd64/sys/listen.S src/lib/libc/amd64/sys/listen.S
--- copy/src/lib/libc/amd64/sys/listen.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/amd64/sys/listen.S	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,3 @@
+#include "SYS.h"
+
+RSYSCALL2(listen)
diff -burN copy/src/lib/libc/i386/SYS.h src/lib/libc/i386/SYS.h
--- copy/src/lib/libc/i386/SYS.h	Tue Sep 17 01:48:51 2002
+++ src/lib/libc/i386/SYS.h	Thu Sep 22 07:03:02 2005
@@ -59,3 +59,10 @@
 #define	LCALL(x,y)	.byte 0x9a ; .long y; .word x
 
 #define KERNCALL	int $0x80
+
+/* overriden syscalls */
+#define        SYSCALL2(x)     2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror));\
+                       ENTRY(__CONCAT(___sys_,x));                     \
+                       mov __CONCAT($SYS_,x),%eax; KERNCALL; jb 2b
+
+#define        RSYSCALL2(x)    SYSCALL2(x); ret
diff -burN copy/src/lib/libc/i386/sys/Makefile.inc src/lib/libc/i386/sys/Makefile.inc
--- copy/src/lib/libc/i386/sys/Makefile.inc	Mon Apr 25 20:30:24 2005
+++ src/lib/libc/i386/sys/Makefile.inc	Thu Sep 22 07:03:39 2005
@@ -10,7 +10,7 @@
 .endif
 
 MDASM=	Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \
-	reboot.S sbrk.S setlogin.S sigreturn.S syscall.S
+	reboot.S sbrk.S setlogin.S sigreturn.S syscall.S bind.S listen.S connect.S
 
 # Don't generate default code for these syscalls:
 NOASM=	break.o exit.o ftruncate.o getdomainname.o getlogin.o \
diff -burN copy/src/lib/libc/i386/sys/bind.S src/lib/libc/i386/sys/bind.S
--- copy/src/lib/libc/i386/sys/bind.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/i386/sys/bind.S	Thu Sep 22 07:03:55 2005
@@ -0,0 +1,2 @@
+#include "SYS.h"
+RSYSCALL2(bind)
diff -burN copy/src/lib/libc/i386/sys/connect.S src/lib/libc/i386/sys/connect.S
--- copy/src/lib/libc/i386/sys/connect.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/i386/sys/connect.S	Thu Sep 22 07:04:17 2005
@@ -0,0 +1,2 @@
+#include "SYS.h"
+RSYSCALL2(connect)
diff -burN copy/src/lib/libc/i386/sys/listen.S src/lib/libc/i386/sys/listen.S
--- copy/src/lib/libc/i386/sys/listen.S	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/i386/sys/listen.S	Thu Sep 22 07:04:39 2005
@@ -0,0 +1,2 @@
+#include "SYS.h"
+RSYSCALL2(listen)
diff -burN copy/src/lib/libc/include/p2plab.h src/lib/libc/include/p2plab.h
--- copy/src/lib/libc/include/p2plab.h	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/include/p2plab.h	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,6 @@
+#ifndef P2PLAB_H
+#define P2PLAB_H
+
+#undef P2PLAB_DEBUG
+
+#endif
diff -burN copy/src/lib/libc/net/Makefile.inc src/lib/libc/net/Makefile.inc
--- copy/src/lib/libc/net/Makefile.inc	Thu Mar 31 01:52:53 2005
+++ src/lib/libc/net/Makefile.inc	Wed Sep 21 14:53:49 2005
@@ -18,7 +18,8 @@
 	nsdispatch.c nslexer.c nsparser.c nss_compat.c \
 	nsap_addr.c rcmd.c rcmdsh.c recv.c res_comp.c res_data.c res_debug.c \
 	res_init.c res_mkquery.c res_mkupdate.c res_query.c res_send.c \
-	res_update.c rthdr.c send.c sockatmark.c vars.c
+	res_update.c rthdr.c send.c sockatmark.c vars.c \
+	mybind.c mylisten.c myconnect.c
 
 CFLAGS+=-DINET6 -I${.OBJDIR}
 
diff -burN copy/src/lib/libc/net/mybind.c src/lib/libc/net/mybind.c
--- copy/src/lib/libc/net/mybind.c	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/net/mybind.c	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by John Birrell.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libc_r/uthread/uthread_bind.c,v 1.11 2001/04/10 04:19:19 deischen Exp $
+ */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include "un-namespace.h"
+#include "p2plab.h"
+
+__weak_reference(__sys_bind, bind);
+__weak_reference(__sys_bind, _bind);
+
+extern int ___sys_bind(int fd, const struct sockaddr * name, socklen_t namelen);
+
+int
+__sys_bind(int fd, const struct sockaddr * name, socklen_t namelen)
+{
+	int             ret;
+	char * bindip;
+#ifdef P2PLAB_DEBUG
+	printf("Inside bind()\n");
+	if (name->sa_family == AF_INET) {
+		printf("SA_FAMILY OK\n");
+	}
+	if (getenv("BINDIP")) {
+		printf("getenv() OK\n");
+	}
+#endif
+	if (name->sa_family == AF_INET && (bindip = getenv("BINDIP")))
+	{
+		struct sockaddr_in * sin = (struct sockaddr_in *) name;
+		struct in_addr sin_addrbak = sin->sin_addr;
+		if (inet_aton(bindip, &(sin->sin_addr)) == 0) {
+#ifdef P2PLAB_DEBUG
+			printf("Problem while resolving address\n");
+#endif
+			sin->sin_addr = sin_addrbak;
+		}
+		ret = ___sys_bind(fd, name, namelen);
+		if (ret != 0) {
+#ifdef P2PLAB_DEBUG
+			printf("___sys_bind() ERROR\n");
+			if (errno != EINVAL)
+				perror("___sys_bind() in bind() failed");
+#endif
+			errno = 0;
+		}
+		sin->sin_addr = sin_addrbak;
+	} else {
+		ret = ___sys_bind(fd, name, namelen);
+	}
+#ifdef P2PLAB_DEBUG
+	printf("ret: %d\n", ret);
+#endif
+	return (ret);
+}
+
diff -burN copy/src/lib/libc/net/myconnect.c src/lib/libc/net/myconnect.c
--- copy/src/lib/libc/net/myconnect.c	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/net/myconnect.c	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by John Birrell.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libc_r/uthread/uthread_connect.c,v 1.14 2002/12/19 11:39:20 ru Exp $
+ */
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include "un-namespace.h"
+#include "p2plab.h"
+
+__weak_reference(__sys_connect, connect);
+__weak_reference(__sys_connect, _connect);
+
+extern int ___sys_connect(int fd, const struct sockaddr * name, socklen_t namelen);
+extern int ___sys_bind(int fd, const struct sockaddr * name, socklen_t namelen);
+
+int
+__sys_connect(int fd, const struct sockaddr * name, socklen_t namelen)
+{
+	int ret;
+
+	char * bindip;
+#ifdef P2PLAB_DEBUG
+	printf("Inside connect()\n");
+	if (name->sa_family == AF_INET) {
+		printf("SA_FAMILY OK\n");
+	}
+	if (getenv("BINDIP")) {
+		printf("getenv() OK\n");
+	}
+#endif
+	if (name->sa_family == AF_INET && (bindip = getenv("BINDIP"))) {
+		struct sockaddr_in sin;
+		sin.sin_family = AF_INET;
+		sin.sin_port = htonl(0);
+		if (inet_aton(bindip, &(sin.sin_addr)) == 0) {
+#ifdef P2PLAB_DEBUG
+			printf("Problem while resolving address\n");
+#endif
+		} else {
+			if (___sys_bind(fd, (struct sockaddr *) &sin, sizeof(struct sockaddr_in)) != 0) {
+#ifdef P2PLAB_DEBUG
+				printf("Bind() ERROR\n");
+				if (errno != EINVAL)
+					perror("Bind() in connect() failed");
+#endif
+				errno = 0;
+			}
+		}
+	}
+
+	ret = ___sys_connect(fd, name, namelen);
+	return (ret);
+}
+
+
diff -burN copy/src/lib/libc/net/mylisten.c src/lib/libc/net/mylisten.c
--- copy/src/lib/libc/net/mylisten.c	Thu Jan  1 00:00:00 1970
+++ src/lib/libc/net/mylisten.c	Wed Sep 21 14:53:49 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by John Birrell.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/lib/libc_r/uthread/uthread_listen.c,v 1.10 2001/04/10 04:19:20 deischen Exp $
+ */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include "un-namespace.h"
+#include "p2plab.h"
+
+__weak_reference(__sys_listen, listen);
+__weak_reference(__sys_listen, _listen);
+
+extern int ___sys_listen(int fd, int backlog);
+
+int
+__sys_listen(int fd, int backlog)
+{
+	int             ret;
+	ret = ___sys_listen(fd, backlog);
+	return (ret);
+}
+
