瀏覽代碼

Applied IPV6 improvements from 1.6cvs
-linking over ipv6
-dcc chat over ipv6
Added several compatability functions


svn: 105

Eggheads Development Team (Ported by Bryan) 23 年之前
父節點
當前提交
65e3fb0115

+ 9 - 0
acconfig.h

@@ -7,6 +7,12 @@
  * 
  */
 
+/* Define if you want to enable IPv6 support. */
+#undef HAVE_IPV6
+
+/* Define if you have support for socklen_t. */
+#undef HAVE_SOCKLEN_T
+
 /* Define if modules will work on your system  */
 #undef MODULES_OK
 
@@ -19,6 +25,9 @@
 /* Define if running on OSF/1 platform.  */
 #undef OSF1_HACKS
 
+/* Define to use Eggdrop's snprintf functions without regard to HAVE_SNPRINTF. */
+#undef BROKEN_SNPRINTF
+
 /* Define if running on OSF/1 platform.  */
 #undef STOP_UAC
 

+ 51 - 12
aclocal.m4

@@ -22,6 +22,56 @@ EOF
 fi
 ])dnl
 
+dnl  EGG_IPV6_OPTIONS()
+dnl
+AC_DEFUN(EGG_IPV6_OPTIONS, [dnl
+AC_MSG_CHECKING(whether or not you enabled IPv6 support)
+AC_ARG_ENABLE(ipv6, [  --enable-ipv6           enable IPv6 support],
+[ ac_cv_ipv6="yes"
+  if test "$egg_cv_ipv6_supported" = "no"; then
+    ac_cv_ipv6="no"
+  fi
+  AC_MSG_RESULT($ac_cv_ipv6)
+],
+[ ac_cv_ipv6="no"
+  AC_MSG_RESULT(no)
+])
+if test "$ac_cv_ipv6" = "yes"; then
+  AC_DEFINE(HAVE_IPV6)
+  ENABLEIPV6="--enable-ipv6"
+fi
+AC_SUBST(ENABLEIPV6)
+])dnl
+
+
+dnl  EGG_CHECK_SOCKLEN_T()
+dnl
+AC_DEFUN(EGG_CHECK_SOCKLEN_T, [dnl
+AC_MSG_CHECKING(for socklen_t)
+AC_CACHE_VAL(egg_cv_socklen_t,[
+  AC_TRY_RUN([
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int main()
+{
+  socklen_t test = sizeof(int);
+
+  return 0;
+}
+  ],
+egg_cv_socklen_t=yes, egg_cv_socklen_t=no, egg_cv_socklen_t=no)])
+if test "$egg_cv_socklen_t" = "yes"; then
+  AC_DEFINE(HAVE_SOCKLEN_T)
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_RESULT(no)
+fi
+])dnl
+
 
 dnl  EGG_CHECK_CCPIPE()
 dnl
@@ -259,6 +309,7 @@ case "$egg_cv_var_system_type" in
       ;;
     esac
     AC_DEFINE(STOP_UAC)dnl
+    AC_DEFINE(BROKEN_SNPRINTF)dnl
   ;;
   SunOS)
     if test "`echo $egg_cv_var_system_release | cut -d . -f 1`" = "5"
@@ -880,18 +931,6 @@ fi
 ])dnl
 
 
-dnl  EGG_TCL_CHECK_PRE75()
-dnl
-AC_DEFUN(EGG_TCL_CHECK_PRE75, [dnl
-# Are we using a pre 7.5 Tcl version ?
-TCL_VER_PRE75=`echo $egg_cv_var_tcl_version | $AWK '{split([$]1, i, "."); if (((i[[1]] == 7) && (i[[2]] < 5)) || (i[[1]] < 7)) print "yes"; else print "no"}'`
-if test "$TCL_VER_PRE75" = "yes"
-then
-  AC_DEFINE(HAVE_PRE7_5_TCL)dnl
-fi
-])dnl
-
-
 dnl  EGG_TCL_TESTLIBS()
 dnl
 AC_DEFUN(EGG_TCL_TESTLIBS, [dnl

+ 2 - 2
build

@@ -93,10 +93,10 @@ TCLDIR=`cat pack/conf.h 2>&1 | grep "//" | awk '/TCLDIR/ {print $2}' |  sed -e '
 if test -z ${TCLDIR}
 then
   echo "[*] Searching for TCL in default dirs (edit $packname to change)"
-  ./configure --silent --disable-tcl-threads
+  ./configure --silent --disable-tcl-threads --enable-ipv6
 else
   echo "[*] Searching for TCL in: $TCLDIR"
-  ./configure --silent --disable-tcl-threads --with-tcllib=${TCLDIR}/lib/libtcl8.4.a --with-tclinc=${TCLDIR}/include/tcl.h
+  ./configure --silent --disable-tcl-threads --enable-ipv6 --with-tcllib=${TCLDIR}/lib/libtcl8.4.a --with-tclinc=${TCLDIR}/include/tcl.h
 fi
 
 # make clean, just in case

+ 127 - 142
config.h.in

@@ -1,11 +1,54 @@
-/* config.h.in.  Generated from configure.in by autoheader.  */
+/* config.h.in.  Generated automatically from configure.in by autoheader 2.13.  */
 #ifndef _EGG_CONFIG_H
 #define _EGG_CONFIG_H
-/* 
- * acconfig.h
- *   template file autoheader uses when building config.h.in
- * 
- */
+
+/* Define if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+#undef _ALL_SOURCE
+#endif
+
+/* Define to empty if the keyword does not work.  */
+#undef const
+
+/* Define if you have <sys/wait.h> that is POSIX.1 compatible.  */
+#undef HAVE_SYS_WAIT_H
+
+/* Define as __inline if that's what the C compiler calls it.  */
+#undef inline
+
+/* Define if on MINIX.  */
+#undef _MINIX
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef pid_t
+
+/* Define if the system does not provide POSIX.1 features except
+   with this defined.  */
+#undef _POSIX_1_SOURCE
+
+/* Define if you need to in order for stat and other things to work.  */
+#undef _POSIX_SOURCE
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+#undef size_t
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#undef TIME_WITH_SYS_TIME
+
+/* Define if your processor stores words with the most significant
+   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
+#undef WORDS_BIGENDIAN
+
+/* Define if you want to enable IPv6 support. */
+#undef HAVE_IPV6
+
+/* Define if you have support for socklen_t. */
+#undef HAVE_SOCKLEN_T
 
 /* Define if modules will work on your system  */
 #undef MODULES_OK
@@ -19,6 +62,9 @@
 /* Define if running on OSF/1 platform.  */
 #undef OSF1_HACKS
 
+/* Define to use Eggdrop's snprintf functions without regard to HAVE_SNPRINTF. */
+#undef BROKEN_SNPRINTF
+
 /* Define if running on OSF/1 platform.  */
 #undef STOP_UAC
 
@@ -37,9 +83,6 @@
 /* Define if we need dlopen (for module support)  */
 #undef HAVE_DLOPEN
 
-/* Define for pre Tcl 7.5 compat  */
-#undef HAVE_PRE7_5_TCL
-
 /* Define for Tcl that has Tcl_Free() (7.5p1 and later)  */
 #undef HAVE_TCL_FREE
 
@@ -49,200 +92,142 @@
 /* Defines the current eggdrop version  */
 #undef EGG_VERSION
 
-/* Define if you have the `clock' function. */
-#undef HAVE_CLOCK
+/* The number of bytes in a int.  */
+#undef SIZEOF_INT
 
-/* Define if you have the <dirent.h> header file, and it defines `DIR'. */
-#undef HAVE_DIRENT_H
+/* The number of bytes in a long.  */
+#undef SIZEOF_LONG
 
-/* Define if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
+/* Define if you have the clock function.  */
+#undef HAVE_CLOCK
 
-/* Define if you have the `dlopen' function. */
+/* Define if you have the dlopen function.  */
 #undef HAVE_DLOPEN
 
-/* Define if you have the `dprintf' function. */
+/* Define if you have the dprintf function.  */
 #undef HAVE_DPRINTF
 
-/* Define if you have the `fsync' function. */
+/* Define if you have the fsync function.  */
 #undef HAVE_FSYNC
 
-/* Define if you have the `ipv6' support. */
-#define USE_IPV6
-
-/* Define if you have the `getdtablesize' function. */
+/* Define if you have the getdtablesize function.  */
 #undef HAVE_GETDTABLESIZE
 
-/* Define if you have the `getrusage' function. */
+/* Define if you have the gethostbyname2 function.  */
+#undef HAVE_GETHOSTBYNAME2
+
+/* Define if you have the getipnodebyname function.  */
+#undef HAVE_GETIPNODEBYNAME
+
+/* Define if you have the getrusage function.  */
 #undef HAVE_GETRUSAGE
 
-/* Define if you have the `inet_aton' function. */
+/* Define if you have the inet_aton function.  */
 #undef HAVE_INET_ATON
 
-/* Define if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
+/* Define if you have the inet_ntop function.  */
+#undef HAVE_INET_NTOP
 
-/* Define if you have the `isascii' function. */
+/* Define if you have the isascii function.  */
 #undef HAVE_ISASCII
 
-/* Define if you have the `dl' library (-ldl). */
-#undef HAVE_LIBDL
-
-/* Define if you have the `dld' library (-ldld). */
-#undef HAVE_LIBDLD
-
-/* Define if you have the `dns' library (-ldns). */
-#undef HAVE_LIBDNS
-
-/* Define if you have the `nsl' library (-lnsl). */
-#undef HAVE_LIBNSL
-
-/* Define if you have the `socket' library (-lsocket). */
-#undef HAVE_LIBSOCKET
-
-/* Define if you have the <limits.h> header file. */
-#undef HAVE_LIMITS_H
-
-/* Define if you have the `memcpy' function. */
+/* Define if you have the memcpy function.  */
 #undef HAVE_MEMCPY
 
-/* Define if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define if you have the `memset' function. */
+/* Define if you have the memset function.  */
 #undef HAVE_MEMSET
 
-/* Define if you have the <ndir.h> header file, and it defines `DIR'. */
-#undef HAVE_NDIR_H
-
-/* Define if you have the `random' function. */
+/* Define if you have the random function.  */
 #undef HAVE_RANDOM
 
-/* Define if you have the `rename' function. */
+/* Define if you have the rename function.  */
 #undef HAVE_RENAME
 
-/* Define if you have the `setpgid' function. */
+/* Define if you have the setpgid function.  */
 #undef HAVE_SETPGID
 
-/* Define if you have the `sigaction' function. */
+/* Define if you have the sigaction function.  */
 #undef HAVE_SIGACTION
 
-/* Define if you have the `sigemptyset' function. */
+/* Define if you have the sigemptyset function.  */
 #undef HAVE_SIGEMPTYSET
 
-/* Define if you have the `snprintf' function. */
+/* Define if you have the snprintf function.  */
 #undef HAVE_SNPRINTF
 
-/* Define if you have the `srandom' function. */
+/* Define if you have the srandom function.  */
 #undef HAVE_SRANDOM
 
-/* Define if you have the <stdarg.h> header file. */
-#undef HAVE_STDARG_H
-
-/* Define if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define if you have the <std_args.h> header file. */
-#undef HAVE_STD_ARGS_H
-
-/* Define if you have the `strcasecmp' function. */
+/* Define if you have the strcasecmp function.  */
 #undef HAVE_STRCASECMP
 
-/* Define if you have the `strftime' function. */
+/* Define if you have the strftime function.  */
 #undef HAVE_STRFTIME
 
-/* Define if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define if you have the `strncasecmp' function. */
+/* Define if you have the strncasecmp function.  */
 #undef HAVE_STRNCASECMP
 
-/* Define if you have the <sys/dir.h> header file, and it defines `DIR'. */
-#undef HAVE_SYS_DIR_H
-
-/* Define if you have the <sys/ndir.h> header file, and it defines `DIR'. */
-#undef HAVE_SYS_NDIR_H
-
-/* Define if you have the <sys/rusage.h> header file. */
-#undef HAVE_SYS_RUSAGE_H
-
-/* Define if you have the <sys/select.h> header file. */
-#undef HAVE_SYS_SELECT_H
-
-/* Define if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
+/* Define if you have the uname function.  */
+#undef HAVE_UNAME
 
-/* Define if you have the <sys/time.h> header file. */
-#undef HAVE_SYS_TIME_H
+/* Define if you have the vsnprintf function.  */
+#undef HAVE_VSNPRINTF
 
-/* Define if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
+/* Define if you have the vsprintf function.  */
+#undef HAVE_VSPRINTF
 
-/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
-#undef HAVE_SYS_WAIT_H
+/* Define if you have the <dirent.h> header file.  */
+#undef HAVE_DIRENT_H
 
-/* Define if you have the `uname' function. */
-#undef HAVE_UNAME
+/* Define if you have the <dlfcn.h> header file.  */
+#undef HAVE_DLFCN_H
 
-/* Define if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
+/* Define if you have the <limits.h> header file.  */
+#undef HAVE_LIMITS_H
 
-/* Define if you have the `vsnprintf' function. */
-#undef HAVE_VSNPRINTF
+/* Define if you have the <ndir.h> header file.  */
+#undef HAVE_NDIR_H
 
-/* Define if you have the `vsprintf' function. */
-#undef HAVE_VSPRINTF
+/* Define if you have the <std_args.h> header file.  */
+#undef HAVE_STD_ARGS_H
 
-/* The size of a `int', as computed by sizeof. */
-#undef SIZEOF_INT
+/* Define if you have the <stdarg.h> header file.  */
+#undef HAVE_STDARG_H
 
-/* The size of a `long', as computed by sizeof. */
-#undef SIZEOF_LONG
+/* Define if you have the <strings.h> header file.  */
+#undef HAVE_STRINGS_H
 
-/* Define if you have the ANSI C header files. */
-#undef STDC_HEADERS
+/* Define if you have the <sys/dir.h> header file.  */
+#undef HAVE_SYS_DIR_H
 
-/* Define if you can safely include both <sys/time.h> and <time.h>. */
-#undef TIME_WITH_SYS_TIME
+/* Define if you have the <sys/ndir.h> header file.  */
+#undef HAVE_SYS_NDIR_H
 
-/* Define if your processor stores words with the most significant byte first
-   (like Motorola and SPARC, unlike Intel and VAX). */
-#undef WORDS_BIGENDIAN
+/* Define if you have the <sys/rusage.h> header file.  */
+#undef HAVE_SYS_RUSAGE_H
 
-/* Define if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
-#ifndef _ALL_SOURCE
-# undef _ALL_SOURCE
-#endif
+/* Define if you have the <sys/select.h> header file.  */
+#undef HAVE_SYS_SELECT_H
 
-/* Define if on MINIX. */
-#undef _MINIX
+/* Define if you have the <sys/time.h> header file.  */
+#undef HAVE_SYS_TIME_H
 
-/* Define if the system does not provide POSIX.1 features except with this
-   defined. */
-#undef _POSIX_1_SOURCE
+/* Define if you have the <unistd.h> header file.  */
+#undef HAVE_UNISTD_H
 
-/* Define if you need to in order for `stat' and other things to work. */
-#undef _POSIX_SOURCE
+/* Define if you have the dl library (-ldl).  */
+#undef HAVE_LIBDL
 
-/* Define to empty if `const' does not conform to ANSI C. */
-#undef const
+/* Define if you have the dld library (-ldld).  */
+#undef HAVE_LIBDLD
 
-/* Define as `__inline' if that's what the C compiler calls it, or to nothing
-   if it is not supported. */
-#undef inline
+/* Define if you have the dns library (-ldns).  */
+#undef HAVE_LIBDNS
 
-/* Define to `int' if <sys/types.h> does not define. */
-#undef pid_t
+/* Define if you have the nsl library (-lnsl).  */
+#undef HAVE_LIBNSL
 
-/* Define to `unsigned' if <sys/types.h> does not define. */
-#undef size_t
+/* Define if you have the socket library (-lsocket).  */
+#undef HAVE_LIBSOCKET
 
 #endif /* !_EGG_CONFIG_H */

文件差異過大導致無法顯示
+ 123 - 118
configure


+ 11 - 5
configure.in

@@ -49,8 +49,15 @@ AC_C_INLINE
 AC_CHECK_SIZEOF(long, 0)
 AC_CHECK_SIZEOF(int, 0)
 
+
+# Check for IPv6 support
+#EGG_IPV6_SUPPORTED
+EGG_IPV6_OPTIONS
+EGG_CHECK_SOCKLEN_T
+
 # Checks for library functions
-AC_CHECK_FUNCS(clock getrusage setpgid uname sigaction sigemptyset rename strcasecmp strncasecmp getdtablesize memset random srandom dlopen dprintf snprintf vsnprintf isascii inet_aton memcpy strftime fsync)
+AC_CHECK_FUNCS(clock getrusage setpgid uname sigaction sigemptyset rename strcasecmp strncasecmp getdtablesize memset random srandom)
+AC_CHECK_FUNCS(dlopen dprintf snprintf vsnprintf isascii inet_aton inet_ntop memcpy strftime fsync gethostbyname2 getipnodebyname)
 EGG_CHECK_FUNC_VSPRINTF
 
 # Make sure we have stdc headers, since we can't compile without them
@@ -67,10 +74,10 @@ EGG_EXEEXT
 # (well, what used to be robey's Tcl thingies...)
 
 # Latest tested Tcl version to recommend if Tcl isn't found
-tclrecommendver="8.3.3"
+tclrecommendver="8.3.4"
 
 # Site recommended to download Tcl from
-tclrecommendsite="ftp://ftp.eggheads.org/pub/tcl/tcl8_3/"
+tclrecommendsite="ftp://tcl.activestate.com/pub/tcl/tcl8_3/"
 
 # Tcl library filename prefixes (also used for Tcl header dir on FreeBSD)
 tcllibnames="tcl tcl8.4 tcl84 tcl8.3 tcl83 tcl8.2 tcl82 tcl8.1 tcl81 \
@@ -78,7 +85,7 @@ tcllibnames="tcl tcl8.4 tcl84 tcl8.3 tcl83 tcl8.2 tcl82 tcl8.1 tcl81 \
 	tcl7.3 tcl73 tcl7.2 tcl72 tcl7.1 tcl71 tcl7.0 tcl70"
 
 # Tcl library filename suffixes
-tcllibextensions=".so .so.1 .so.1.0 .so.1.2 .a .sl .dll"
+tcllibextensions=".so .so.1 .so.1.0 .so.1.2 .a .sl .dll .dylib"
 
 # Tcl library search paths
 tcllibpaths="$HOME/lib $HOME/tcl/lib $HOME \
@@ -107,7 +114,6 @@ EGG_TCL_DETECT_CHANGE
 
 EGG_TCL_CHECK_VERSION
 EGG_TCL_CHECK_PRE70
-EGG_TCL_CHECK_PRE75
 EGG_TCL_TESTLIBS
 EGG_TCL_CHECK_FREE
 EGG_TCL_ENABLE_THREADS

+ 3 - 0
doc/CREDITS

@@ -9,8 +9,11 @@ ryguy for providing some cosmetic dcc login code.
 Blackjac for helping with the bx auth script with his Sentinel script.
 passwd for being so dedicated at suggesting improvements and finding bugs.
 pgpkeys for suggestions.
+qFox for providing an mIRC $md5() alias, not requiring a dll or >6.03
 syt for giving me inspiration to code a more secure bot.
 
+
+
 The following botpacks gave me inspiration and ideas (no code):
 awptic by lordoptic
 celdrop by excelsior

+ 25 - 25
src/Makefile.in

@@ -105,126 +105,126 @@ eggdrop.h:
 ../stringfix: stringfix.c
 bg.o: ./bg.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  bg.h
 botcmd.o: ./botcmd.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h tandem.h modules.h mod/modvals.h
 botmsg.o: ./botmsg.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h tandem.h
 botnet.o: ./botnet.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h tandem.h
 chanprog.o: ./chanprog.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h modules.h mod/modvals.h
 cmds.o: ./cmds.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  tandem.h modules.h mod/modvals.h
 dcc.o: ./dcc.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  modules.h mod/modvals.h tandem.h md5/md5.h
 dccutil.o: ./dccutil.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h modules.h mod/modvals.h tandem.h
 dns.o: ./dns.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  dns.h
 flags.o: ./flags.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h
 main.o: ./main.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  modules.h mod/modvals.h tandem.h bg.h md5/md5.h
 match.o: ./match.c ./main.h
 mem.o: ./mem.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  mod/modvals.h
 misc.o: ./misc.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  stat.h
 misc_file.o: ./misc_file.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h stat.h
 modules.o: ./modules.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h modules.h mod/modvals.h tandem.h
 net.o: ./net.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h
 rfc1459.o: ./rfc1459.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h
 stringfix.o: stringfix.c
 tcl.o: ./tcl.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h
 tcldcc.o: ./tcldcc.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h tandem.h modules.h mod/modvals.h
 tclhash.o: ./tclhash.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h match.c
 tclmisc.o: ./tclmisc.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h modules.h mod/modvals.h tandem.h md5/md5.h
 tcluser.o: ./tcluser.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h tandem.h
 userent.o: ./userent.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h
 userrec.o: ./userrec.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
- users.h compat/compat.h compat/inet_aton.h ../src/main.h \
+ users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \
  compat/snprintf.h compat/memset.h compat/memcpy.h compat/strcasecmp.h \
  compat/strftime.h modules.h mod/modvals.h tandem.h
 users.o: ./users.c main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
- compat/compat.h compat/inet_aton.h ../src/main.h compat/snprintf.h \
+ compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
  modules.h mod/modvals.h tandem.h
 settings.o: ./settings.c eggdrop.h ../src/main.h

+ 16 - 3
src/botnet.c

@@ -1042,7 +1042,11 @@ static void botlink_resolve_success(int i)
   strcpy(dcc[i].u.bot->sysname, "*");
   dcc[i].u.bot->numver = idx;
   dcc[i].u.bot->port = dcc[i].port;		/* Remember where i started */
-  dcc[i].sock =  getsock(SOCK_STRONGCONN,getprotocol(dcc[i].host));
+#ifdef USE_IPV6
+  dcc[i].sock = getsock(SOCK_STRONGCONN, getprotocol(dcc[i].host));
+#else
+  dcc[i].sock = getsock(SOCK_STRONGCONN);
+#endif /* USE_IPV6 */
   nfree(linker);
   if (dcc[i].sock < 0 ||
       open_telnet_raw(dcc[i].sock, iptostr(htonl(dcc[i].addr)),
@@ -1078,7 +1082,11 @@ static void failed_tandem_relay(int idx)
     return;
   }
   killsock(dcc[idx].sock);
-  dcc[idx].sock = getsock(SOCK_STRONGCONN,getprotocol(dcc[idx].host));
+#ifdef USE_IPV6
+  dcc[idx].sock = getsock(SOCK_STRONGCONN, getprotocol(dcc[idx].host));
+#else
+  dcc[idx].sock = getsock(SOCK_STRONGCONN);
+#endif /* USE_IPV6 */
   dcc[uidx].u.relay->sock = dcc[idx].sock;
   dcc[idx].port++;
   dcc[idx].timeval = now;
@@ -1125,7 +1133,12 @@ void tandem_relay(int idx, char *nick, register int i)
     return;
   }
 
-  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL,getprotocol(bi->address));
+#ifdef USE_IPV6
+  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, getprotocol(bi->address));
+#else
+  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
+#endif /* USE_IPV6 */
+
   if (dcc[i].sock < 0) {
     lostdcc(i);
     dprintf(idx, "%s\n", MISC_NOFREESOCK);

+ 35 - 5
src/cmds.c

@@ -1532,15 +1532,20 @@ static void cmd_uplink(struct userrec *u, int idx, char *par)
 static void cmd_chaddr(struct userrec *u, int idx, char *par)
 {
   int telnet_port = 3333, relay_port = 3333;
+#ifdef USE_IPV6
+  char *handle, *addr, *p, *q, *r;
+#else
   char *handle, *addr, *p, *q;
+#endif /* USE_IPV6 */
   struct bot_addr *bi;
   struct userrec *u1;
 
+  handle = newsplit(&par);
   if (!par[0]) {
-    dprintf(idx, "Usage: chaddr <botname> <address[:telnet-port[/relay-port]]>\n");
+    dprintf(idx, "Usage: chaddr <botname> "
+            "<address[:telnet-port[/relay-port]]>\n");
     return;
   }
-  handle = newsplit(&par);
   addr = newsplit(&par);
   if (strlen(addr) > UHOSTMAX)
     addr[UHOSTMAX] = 0;
@@ -1571,16 +1576,41 @@ static void cmd_chaddr(struct userrec *u, int idx, char *par)
     bi->telnet_port = telnet_port;
     bi->relay_port = relay_port;
   } else {
+#ifdef USE_IPV6
+    r = strchr(addr, '[');
+    if (r) { /* ipv6 notation [3ffe:80c0:225::] */
+      *addr++;
+      r = strchr(addr, ']');
+      bi->address = user_malloc(r - addr + 1);
+      strncpyz(bi->address, addr, r - addr + 1);
+      addr = r;
+      *addr++;
+    } else {
+      bi->address = user_malloc(q - addr + 1);
+      strncpyz(bi->address, addr, q - addr + 1);
+    }
+    q = strchr(addr, ':');
+    if (q) {
+      p = q + 1;
+      bi->telnet_port = atoi(p);
+      q = strchr(p, '/');
+      if (!q) {
+        bi->relay_port = telnet_port;
+      } else {
+        bi->relay_port = atoi(q + 1);
+      }
+    }
+#else
     bi->address = user_malloc(q - addr + 1);
     strncpyz(bi->address, addr, q - addr + 1);
     p = q + 1;
     bi->telnet_port = atoi(p);
     q = strchr(p, '/');
-    if (!q) {
+    if (!q)
       bi->relay_port = bi->telnet_port;
-    } else {
+    else
       bi->relay_port = atoi(q + 1);
-    }
+#endif /* USE_IPV6 */
   }
   set_user(&USERENTRY_BOTADDR, u1, bi);
 }

+ 27 - 13
src/compat/Makefile.in

@@ -17,7 +17,7 @@ STRIP = @STRIP@
 CFLAGS = @CFLAGS@ -I../.. -I$(top_srcdir) -I$(top_srcdir)/src @DEFS@ $(CFLGS)
 CPPFLAGS = @CPPFLAGS@
 
-OBJS = inet_aton.o snprintf.o memset.o memcpy.o strcasecmp.o strftime.o
+OBJS = inet_aton.o inet_ntop.o snprintf.o memset.o memcpy.o strcasecmp.o strftime.o
 
 doofus:
 	@echo ""
@@ -42,51 +42,65 @@ compat: $(OBJS)
 
 #safety hash
 gnu_strftime.o: ./gnu_strftime.c
-inet_aton.o: ./inet_aton.c ../../src/main.h ../../config.h ../../pack/conf.h \
+inet_aton.o: ./inet_aton.c ../../src/main.h ../../pack/conf.h ../../config.h \
  ../../src/lang.h ../../src/eggdrop.h ../../src/flags.h \
  ../../src/proto.h ../../lush.h ../../src/misc_file.h ../../src/cmdt.h \
  ../../src/tclegg.h ../../src/tclhash.h ../../src/chan.h \
  ../../src/users.h ../../src/compat/compat.h \
  ../../src/compat/inet_aton.h ../../src/compat/snprintf.h \
  ../../src/compat/memset.h ../../src/compat/memcpy.h \
- ../../src/compat/strcasecmp.h ../../src/compat/strftime.h inet_aton.h
-memcpy.o: ./memcpy.c ../../src/main.h ../../config.h ../../pack/conf.h ../../src/lang.h \
+ ../../src/compat/strcasecmp.h ../../src/compat/strftime.h inet_aton.h \
+ ../../src/compat/inet_ntop.h
+ inet_ntop.o: ./inet_ntop.c ../../src/main.h ../../pack/conf.h ../../config.h \
+ ../../src/lang.h ../../src/eggdrop.h ../../src/flags.h \
+ ../../src/proto.h ../../lush.h ../../src/misc_file.h ../../src/cmdt.h \
+ ../../src/tclegg.h ../../src/tclhash.h ../../src/chan.h \
+ ../../src/users.h ../../src/compat/compat.h \
+ ../../src/compat/inet_ntop.h ../../src/compat/snprintf.h \
+ ../../src/compat/memset.h ../../src/compat/memcpy.h \
+ ../../src/compat/strcasecmp.h ../../src/compat/strftime.h inet_ntop.h \
+ ../../src/compat/inet_aton.h
+memcpy.o: ./memcpy.c ../../src/main.h ../../pack/conf.h ../../config.h ../../src/lang.h \
  ../../src/eggdrop.h ../../src/flags.h ../../src/proto.h ../../lush.h \
  ../../src/misc_file.h ../../src/cmdt.h ../../src/tclegg.h \
  ../../src/tclhash.h ../../src/chan.h ../../src/users.h \
  ../../src/compat/compat.h ../../src/compat/inet_aton.h \
  ../../src/compat/snprintf.h ../../src/compat/memset.h \
  ../../src/compat/memcpy.h ../../src/compat/strcasecmp.h \
- ../../src/compat/strftime.h memcpy.h
-memset.o: ./memset.c ../../src/main.h ../../config.h ../../pack/conf.h ../../src/lang.h \
+ ../../src/compat/strftime.h memcpy.h  ../../src/compat/inet_ntop.h
+memset.o: ./memset.c ../../src/main.h ../../pack/conf.h ../../config.h ../../src/lang.h \
  ../../src/eggdrop.h ../../src/flags.h ../../src/proto.h ../../lush.h \
  ../../src/misc_file.h ../../src/cmdt.h ../../src/tclegg.h \
  ../../src/tclhash.h ../../src/chan.h ../../src/users.h \
  ../../src/compat/compat.h ../../src/compat/inet_aton.h \
  ../../src/compat/snprintf.h ../../src/compat/memset.h \
  ../../src/compat/memcpy.h ../../src/compat/strcasecmp.h \
- ../../src/compat/strftime.h memset.h
-snprintf.o: ./snprintf.c ../../src/main.h ../../config.h ../../pack/conf.h \
+ ../../src/compat/strftime.h memset.h  ../../src/compat/inet_ntop.h
+snprintf.o: ./snprintf.c ../../src/main.h ../../pack/conf.h ../../config.h \
  ../../src/lang.h ../../src/eggdrop.h ../../src/flags.h \
  ../../src/proto.h ../../lush.h ../../src/misc_file.h ../../src/cmdt.h \
  ../../src/tclegg.h ../../src/tclhash.h ../../src/chan.h \
  ../../src/users.h ../../src/compat/compat.h \
  ../../src/compat/inet_aton.h ../../src/compat/snprintf.h \
  ../../src/compat/memset.h ../../src/compat/memcpy.h \
- ../../src/compat/strcasecmp.h ../../src/compat/strftime.h snprintf.h
-strcasecmp.o: ./strcasecmp.c ../../src/main.h ../../config.h ../../pack/conf.h \
+ ../../src/compat/strcasecmp.h   ../../src/compat/inet_ntop.h \
+ ../../src/compat/strftime.h snprintf.h
+strcasecmp.o: ./strcasecmp.c ../../src/main.h ../../pack/conf.h ../../config.h \
  ../../src/lang.h ../../src/eggdrop.h ../../src/flags.h \
  ../../src/proto.h ../../lush.h ../../src/misc_file.h ../../src/cmdt.h \
  ../../src/tclegg.h ../../src/tclhash.h ../../src/chan.h \
  ../../src/users.h ../../src/compat/compat.h \
  ../../src/compat/inet_aton.h ../../src/compat/snprintf.h \
  ../../src/compat/memset.h ../../src/compat/memcpy.h \
- ../../src/compat/strcasecmp.h ../../src/compat/strftime.h memcpy.h
-strftime.o: ./strftime.c ../../src/main.h ../../config.h ../../pack/conf.h \
+ ../../src/compat/strcasecmp.h   ../../src/compat/inet_ntop.h \
+ ../../src/compat/strftime.h memcpy.h
+strftime.o: ./strftime.c ../../src/main.h ../../pack/conf.h ../../config.h \
  ../../src/lang.h ../../src/eggdrop.h ../../src/flags.h \
  ../../src/proto.h ../../lush.h ../../src/misc_file.h ../../src/cmdt.h \
  ../../src/tclegg.h ../../src/tclhash.h ../../src/chan.h \
  ../../src/users.h ../../src/compat/compat.h \
  ../../src/compat/inet_aton.h ../../src/compat/snprintf.h \
  ../../src/compat/memset.h ../../src/compat/memcpy.h \
- ../../src/compat/strcasecmp.h ../../src/compat/strftime.h strftime.h
+ ../../src/compat/strcasecmp.h   ../../src/compat/inet_ntop.h \
+ ../../src/compat/strftime.h strftime.h
+

+ 3 - 1
src/compat/compat.h

@@ -8,10 +8,12 @@
 #define _EGG_COMPAT_COMPAT_H
 
 #include "inet_aton.h"
+#include "inet_ntop.h"
 #include "snprintf.h"
 #include "memset.h"
 #include "memcpy.h"
 #include "strcasecmp.h"
 #include "strftime.h"
 
-#endif	/* !__EGG_COMPAT_COMPAT_H */
+#endif /* !__EGG_COMPAT_COMPAT_H */
+

+ 188 - 0
src/compat/inet_ntop.c

@@ -0,0 +1,188 @@
+/*
+ * inet_ntop.c --
+ *
+ *	provides inet_ntop()
+ */
+
+
+#include "main.h"
+#include "inet_ntop.h"
+
+#if defined(USE_IPV6) && !defined(HAVE_INET_NTOP)
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef SPRINTF_CHAR
+# define SPRINTF(x) strlen(sprintf/**/x)
+#else
+# define SPRINTF(x) ((size_t)sprintf x)
+#endif
+
+#define NS_INADDRSZ     4       /* IPv4 T_A */
+#define NS_IN6ADDRSZ    16      /* IPv6 T_AAAA */
+#define NS_INT16SZ      2       /* #/bytes of data in a u_int16_t */
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static const char *egg_inet_ntop4 (const u_char *src, char *dst, socklen_t size);
+static const char *egg_inet_ntop6 (const u_char *src, char *dst, socklen_t size);
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ *	convert a network format address to presentation format.
+ * return:
+ *	pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ *	Paul Vixie, 1996.
+ */
+const char *
+egg_inet_ntop(af, src, dst, size)
+	int af;
+	const void *src;
+	char *dst;
+	socklen_t size;
+{
+	switch (af) {
+	case AF_INET:
+		return (egg_inet_ntop4(src, dst, size));
+	case AF_INET6:
+		return (egg_inet_ntop6(src, dst, size));
+	default:
+		return (NULL);
+	}
+	/* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ *	format an IPv4 address
+ * return:
+ *	`dst' (as a const)
+ * notes:
+ *	(1) uses no statics
+ *	(2) takes a u_char* not an in_addr as input
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static const char *
+egg_inet_ntop4(src, dst, size)
+	const u_char *src;
+	char *dst;
+	socklen_t size;
+{
+	static const char fmt[] = "%u.%u.%u.%u";
+	char tmp[sizeof "255.255.255.255"];
+
+	if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
+		return (NULL);
+	}
+	return strcpy(dst, tmp);
+}
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ *	convert IPv6 binary address into presentation (printable) format
+ * author:
+ *	Paul Vixie, 1996.
+ */
+static const char *
+egg_inet_ntop6(src, dst, size)
+	const u_char *src;
+	char *dst;
+	socklen_t size;
+{
+	/*
+	 * Note that int32_t and int16_t need only be "at least" large enough
+	 * to contain a value of the specified size.  On some systems, like
+	 * Crays, there is no such thing as an integer variable with 16 bits.
+	 * Keep this in mind if you think this function should have been coded
+	 * to use pointer overlays.  All the world's not a VAX.
+	 */
+	char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+	struct { int base, len; } best, cur;
+	u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
+	int i;
+
+	/*
+	 * Preprocess:
+	 *	Copy the input (bytewise) array into a wordwise array.
+	 *	Find the longest run of 0x00's in src[] for :: shorthanding.
+	 */
+	egg_memset(words, '\0', sizeof words);
+	for (i = 0; i < NS_IN6ADDRSZ; i += 2)
+		words[i / 2] = (src[i] << 8) | src[i + 1];
+	best.base = -1;
+	cur.base = -1;
+	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+		if (words[i] == 0) {
+			if (cur.base == -1)
+				cur.base = i, cur.len = 1;
+			else
+				cur.len++;
+		} else {
+			if (cur.base != -1) {
+				if (best.base == -1 || cur.len > best.len)
+					best = cur;
+				cur.base = -1;
+			}
+		}
+	}
+	if (cur.base != -1) {
+		if (best.base == -1 || cur.len > best.len)
+			best = cur;
+	}
+	if (best.base != -1 && best.len < 2)
+		best.base = -1;
+
+	/*
+	 * Format the result.
+	 */
+	tp = tmp;
+	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
+		/* Are we inside the best run of 0x00's? */
+		if (best.base != -1 && i >= best.base &&
+		    i < (best.base + best.len)) {
+			if (i == best.base)
+				*tp++ = ':';
+			continue;
+		}
+		/* Are we following an initial run of 0x00s or any real hex? */
+		if (i != 0)
+			*tp++ = ':';
+		/* Is this address an encapsulated IPv4? */
+		if (i == 6 && best.base == 0 &&
+		    (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
+			if (!egg_inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
+				return (NULL);
+			tp += strlen(tp);
+			break;
+		}
+		tp += SPRINTF((tp, "%x", words[i]));
+	}
+	/* Was it a trailing run of 0x00's? */
+	if (best.base != -1 && (best.base + best.len) ==
+	    (NS_IN6ADDRSZ / NS_INT16SZ))
+		*tp++ = ':';
+	*tp++ = '\0';
+
+	/*
+	 * Check for overflow, copy, and we're done.
+	 */
+	if ((socklen_t)(tp - tmp) > size) {
+		return (NULL);
+	}
+	return strcpy(dst, tmp);
+}
+#endif /* !HAVE_INET_NTOP */

+ 26 - 0
src/compat/inet_ntop.h

@@ -0,0 +1,26 @@
+/*
+ * inet_ntop.h --
+ *
+ *	prototypes for inet_ntop.c
+ */
+
+#ifndef _EGG_COMPAT_INET_NTOP_H
+#define _EGG_COMPAT_INET_NTOP_H
+
+#include "src/main.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef USE_IPV6
+#  ifndef HAVE_INET_NTOP
+const char *egg_inet_ntop(int af, const void *src, char *dst, socklen_t size);
+#  else
+#    define egg_inet_ntop inet_ntop
+#  endif
+#else
+#  define egg_inet_ntop 0
+#endif
+
+#endif /* !_EGG_COMPAT_INET_NTOP_H */

+ 11 - 0
src/compat/snprintf.h

@@ -10,6 +10,17 @@
 #include "src/main.h"
 #include <stdio.h>
 
+/* Check for broken snprintf versions */
+#ifdef BROKEN_SNPRINTF
+#  ifdef HAVE_VSNPRINTF
+#    undef HAVE_VSNPRINTF
+#  endif
+#  ifdef HAVE_SNPRINTF
+#    undef HAVE_SNPRINTF
+#  endif
+#endif
+
+
 /* Use the system libraries version of vsnprintf() if available. Otherwise
  * use our own.
  */

+ 34 - 2
src/eggdrop.h

@@ -11,6 +11,16 @@
 
 #define SDEBUG 1
 
+/*
+ * Enable IPv6 support?
+ */
+#define USE_IPV6
+
+/*
+ * Enable IPv6 debugging?
+ */
+#define DEBUG_IPV6
+
 // If you undefine this, be ready for a good novel of errors. (Not Finished)
 #ifndef S_IRCNET
 #define S_IRCNET
@@ -105,6 +115,19 @@
 #  include "error_you_need_vsprintf_to_compile_eggdrop"
 #endif
 
+/* IPv6 sanity checks. */
+#ifdef USE_IPV6
+#  ifndef HAVE_IPV6
+#    undef USE_IPV6
+#  endif
+#  ifndef HAVE_GETHOSTBYNAME2
+#    ifndef HAVE_GETIPNODEBYNAME
+#      undef USE_IPV6
+#    endif
+#  endif
+#endif
+
+
 #if HAVE_UNISTD_H
 #  include <unistd.h>
 #endif
@@ -170,6 +193,11 @@
 #  define sigemptyset(x) ((*(int *)(x))=0)
 #endif
 
+#if !HAVE_SOCKLEN_T
+typedef int socklen_t;
+#endif
+
+
 /*
  *    Handy aliases for memory tracking and core dumps
  */
@@ -271,6 +299,10 @@ struct dcc_t {
   long sock;			/* This should be a long to keep 64-bit
 				   machines sane			 */
   IP addr;			/* IP address in host byte order	 */
+#ifdef USE_IPV6
+  char addr6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
+  int af_type;                  /* AF_INET or AF_INET6 */
+#endif /* USE_IPV6 */
   unsigned int port;
   struct userrec *user;
   char hash[33];                /* used for dcc authing */
@@ -639,11 +671,11 @@ typedef struct {
   int gz; /* gzip compression */
   char okey[17];
   char ikey[17];
-//  char okey[33];
-//  char ikey[33];
 
   unsigned long	 inbuflen;	/* Inbuf could be binary data	*/
+#ifdef USE_IPV6
   unsigned int af;
+#endif /* USE_IPV6 */
 } sock_list;
 #ifdef S_DCCPASS
 typedef struct cmd_pass {

+ 15 - 3
src/main.c

@@ -253,7 +253,11 @@ void write_debug()
      *       _not_ safe <cybah>
      */
     x = creat("DEBUG.DEBUG", 0600);
-    setsock(x, SOCK_NONSOCK,AF_INET);
+#ifdef USE_IPV6
+    setsock(x, SOCK_NONSOCK, AF_INET);
+#else
+    setsock(x, SOCK_NONSOCK);
+#endif /* USE_IPV6 */
     if (x >= 0) {
       strncpyz(s, ctime(&now), sizeof s);
       dprintf(-x, "Debug (%s) written %s\n", ver, s);
@@ -276,7 +280,11 @@ void write_debug()
 	 cx_line[cx_ptr], cx_note[cx_ptr][0] ? cx_note[cx_ptr] : "");
 //  putlog(LOG_MISC, "*", "* Please REPORT this BUG to bryan (send him ~/DEBUG as well)!");
   x = creat("DEBUG", 0600);
-  setsock(x, SOCK_NONSOCK,AF_INET);
+#ifdef USE_IPV6
+  setsock(x, SOCK_NONSOCK, AF_INET);
+#else
+  setsock(x, SOCK_NONSOCK);
+#endif /* USE_IPV6 */
   if (x < 0) {
     putlog(LOG_MISC, "*", "* Failed to write DEBUG");
   } else {
@@ -1761,7 +1769,11 @@ Context;
       userlist = adduser(userlist, "HQ", "none", "-", USER_OP | USER_PARTY | USER_CHUBA | USER_HUBA);
       dcc[n].user = get_user_by_handle(userlist, "HQ");
     }
-    setsock(STDOUT, 0,AF_INET);                /* Entry in net table */
+#ifdef USE_IPV6
+    setsock(STDOUT, 0, AF_INET); /* Entry in net table */
+#else
+    setsock(STDOUT, 0);          /* Entry in net table */
+#endif /* USE_IPV6 */
     dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n");
     dcc_chatter(n);
   }

+ 1 - 1
src/mod/channels.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/compress.mod/Makefile.in

@@ -35,7 +35,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/console.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/ctcp.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/lang.h ../../../src/eggdrop.h ../../../src/flags.h \
  ../../../src/proto.h ../../../lush.h ../../../src/misc_file.h \
  ../../../src/cmdt.h ../../../src/tclegg.h ../../../src/tclhash.h \
- ../../../src/chan.h ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/chan.h ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h  \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/dns.mod/Makefile.in

@@ -36,7 +36,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/irc.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 7 - 0
src/mod/module.h

@@ -60,6 +60,9 @@
 #ifdef egg_inet_aton
 #  undef egg_inet_aton
 #endif
+#ifdef egg_inet_ntop
+#  undef egg_inet_ntop
+#endif
 #ifdef egg_vsnprintf
 #  undef egg_vsnprintf
 #endif
@@ -523,6 +526,10 @@
 #define cmdprefix ((char *)(global[325]))
 #define replace ((char*(*)(char *, char *, char *))global[326])
 #define degarble ((char *(*)(int, char *))global[327])
+#define open_listen_by_af ((int (*) (int *, int))global[328])
+/* 329 - 332 */
+#define egg_inet_ntop ((int (*)(int af, const void *src, char *dst, socklen_t size))global[329])
+
 
 
 /* This is for blowfish module, couldnt be bothered making a whole new .h

+ 1 - 1
src/mod/notes.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 1 - 1
src/mod/server.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 73 - 9
src/mod/server.mod/server.c

@@ -923,7 +923,11 @@ static void queue_server(int which, char *buf, int len)
 static void add_server(char *ss)
 {
   struct server_list *x, *z;
+#ifdef USE_IPV6
+  char *p, *q, *r;
+#else
   char *p, *q;
+#endif /* USE_IPV6 */
 
   for (z = serverlist; z && z->next; z = z->next);
   while (ss) {
@@ -947,6 +951,16 @@ static void add_server(char *ss)
       x->name = nmalloc(strlen(ss) + 1);
       strcpy(x->name, ss);
     } else {
+#ifdef USE_IPV6
+      if (ss[0] == '[') {
+        *ss++;
+        q = strchr(ss, ']');
+        *q++ = 0; /* intentional */
+        r = strchr(q, ':');
+        if (!r)
+          x->port = default_port;
+      }
+#endif /* USE_IPV6 */
       *q++ = 0;
       x->name = nmalloc(q - ss);
       strcpy(x->name, ss);
@@ -959,7 +973,13 @@ static void add_server(char *ss)
 	x->pass = nmalloc(strlen(q) + 1);
 	strcpy(x->pass, q);
       }
+#ifdef USE_IPV6
+      if (!x->port) {
+        x->port = atoi(ss);
+      }
+#else
       x->port = atoi(ss);
+#endif /* USE_IPV6 */
     }
     ss = p;
   }
@@ -1602,19 +1622,39 @@ static int ctcp_DCC_CHAT(char *nick, char *from, char *handle,
       putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", dcc[i].nick, ip);
       return 1;
     }
+#ifdef USE_IPV6
+    if (ip[4] == ':') {
+      debug1("ipv6 addr: %s",ip);
+      strcpy(dcc[i].addr6,ip);
+      debug1("ipv6 addr: %s",dcc[i].addr6);
+      dcc[i].af_type = AF_INET6;
+    } else {
+      dcc[i].addr = my_atoul(ip);
+    }
+#else
     dcc[i].addr = my_atoul(ip);
+#endif /* USE_IPV6 */
     dcc[i].port = atoi(prt);
     dcc[i].sock = -1;
     strcpy(dcc[i].nick, u->handle);
     strcpy(dcc[i].host, from);
     dcc[i].timeval = now;
     dcc[i].user = u;
-    dcc[i].u.dns->ip = dcc[i].addr;
-    dcc[i].u.dns->dns_type = RES_HOSTBYIP;
-    dcc[i].u.dns->dns_success = dcc_chat_hostresolved;
-    dcc[i].u.dns->dns_failure = dcc_chat_hostresolved;
-    dcc[i].u.dns->type = &DCC_CHAT_PASS;
-    dcc_dnshostbyip(dcc[i].addr);
+#ifdef USE_IPV6
+    if (dcc[i].af_type != AF_INET6) {
+#endif /* USE_IPV6 */
+/* remove me? */
+      dcc[i].addr = my_atoul(ip);
+      dcc[i].u.dns->ip = dcc[i].addr;
+      dcc[i].u.dns->dns_type = RES_HOSTBYIP;
+      dcc[i].u.dns->dns_success = dcc_chat_hostresolved;
+      dcc[i].u.dns->dns_failure = dcc_chat_hostresolved;
+      dcc[i].u.dns->type = &DCC_CHAT_PASS;
+      dcc_dnshostbyip(dcc[i].addr);
+#ifdef USE_IPV6
+    } else
+      dcc_chat_hostresolved(i); /* Don't try to look it up */
+#endif /* USE_IPV6 */
   }
   return 1;
 }
@@ -1626,16 +1666,40 @@ static void dcc_chat_hostresolved(int i)
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
 
   egg_snprintf(buf, sizeof buf, "%d", dcc[i].port);
+#ifndef USE_IPV6
   if (!hostsanitycheck_dcc(dcc[i].nick, dcc[i].host, dcc[i].addr,
-			   dcc[i].u.dns->host, buf)) {
+                           dcc[i].u.dns->host, buf)) {
     lostdcc(i);
     return;
   }
+#else
+  if (dcc[i].af_type == AF_INET6) {
+    strcpy(ip,dcc[i].addr6); /* safe, addr6 is 121 */
+    debug0("afinet6, af_type, strcpy");
+  } else
+#endif /* !USE_IPV6 */
   egg_snprintf(ip, sizeof ip, "%lu", iptolong(htonl(dcc[i].addr)));
-  dcc[i].sock = getsock(0,getprotocol(ip));
+#ifdef USE_IPV6
+  if (dcc[i].af_type == AF_INET6) {
+#  ifdef IPV6_DEBUG
+    debug2("af_inet6 %s / %s", dcc[i].addr6, ip);
+#  endif /* IPV6_DEBUG */
+    dcc[i].sock = getsock(0, AF_INET6);
+  } else {
+#  ifdef IPV6_DEBUG
+    debug0("af_inet");
+#  endif /* IPV6_DEBUG */
+    dcc[i].sock = getsock(0, AF_INET);
+  }
+#else
+  dcc[i].sock = getsock(0);
+#  ifdef IPV6_DEBUG
+  debug2("sock: %d %s", dcc[i].sock, ip);
+#  endif /* IPV6_DEBUG */
+#endif /* USE_IPV6 */
   if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, buf) < 0) {
     neterror(buf);
-    if(!quiet_reject)
+    if (!quiet_reject)
       dprintf(DP_HELP, "NOTICE %s :%s (%s)\n", dcc[i].nick,
 	      DCC_CONNECTFAILED1, buf);
     putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", DCC_CONNECTFAILED2,

+ 8 - 0
src/mod/server.mod/servmsg.c

@@ -1619,7 +1619,11 @@ static void connect_server(void)
     /* I'm resolving... don't start another server connect request */
     resolvserv = 1;
     /* Resolve the hostname. */
+#ifdef USE_IPV6
     server_resolve_success(servidx);
+#else
+    dcc_dnsipbyhost(dcc[servidx].host);
+#endif /* USE_IPV6 */
   }
 }
 
@@ -1644,7 +1648,11 @@ static void server_resolve_success(int servidx)
   dcc[servidx].addr = dcc[servidx].u.dns->ip;
   strcpy(pass, dcc[servidx].u.dns->cbuf);
   changeover_dcc(servidx, &SERVER_SOCKET, 0);
+#ifdef USE_IPV6
   serv = open_telnet(dcc[servidx].host, dcc[servidx].port);
+#else
+  serv = open_telnet(iptostr(htonl(dcc[servidx].addr)), dcc[servidx].port);
+#endif /* USE_IPV6 */
   if (serv < 0) {
     neterror(s);
     putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,

+ 1 - 1
src/mod/share.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 5 - 1
src/mod/share.mod/share.c

@@ -1135,7 +1135,11 @@ static void share_userfileq(int idx, char *par)
 /* us <ip> <port> <length>
  */
 static void share_ufsend(int idx, char *par)
-    sock = getsock(SOCK_BINARY,getprotocol(ip));       /* Don't buffer this -> mark binary. */
+{
+    sock = getsock(SOCK_BINARY, getprotocol(ip)); /* Don't buffer this -> mark binary. */
+  char s[1024];
+  int i, sock;
+  FILE *f;
 
   egg_snprintf(s, sizeof s, "%s.share.%s.%lu.users", tempdir, botnetnick, now);
   if (!(b_status(idx) & STAT_SHARE)) {

+ 1 - 1
src/mod/transfer.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h ../../../src/chan.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 10 - 4
src/mod/transfer.mod/transfer.c

@@ -1567,14 +1567,20 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from,
   if (dccfilesize == 0)
     return DCCSEND_FEMPTY;
   if (reserved_port_min > 0 && reserved_port_min < reserved_port_max) {
-    for (port = reserved_port_min; port <= reserved_port_max; port++) {
-  zz = open_listen(&port);
-     if (zz != (-1))
+    for (port = reserved_port_min; port <= reserved_port_max; port++)
+#ifdef USE_IPV6
+      if ((zz = open_listen_by_af(&port, AF_INET6)) != -1) /* no idea how we want to handle this -poptix 02/03/03 */
+#else
+      if ((zz = open_listen(&port)) != -1)
+#endif /* USE_IPV6 */
        break;
-    }
   } else {
     port = reserved_port_min;
+#ifdef USE_IPV6
+    zz = open_listen_by_af(&port, AF_INET6);
+#else
     zz = open_listen(&port);
+#endif /* USE_IPV6 */
   }
   if (zz == (-1))
     return DCCSEND_NOSOCK;

+ 1 - 1
src/mod/update.mod/Makefile

@@ -31,7 +31,7 @@ distclean: clean
  ../../../src/eggdrop.h ../../../src/flags.h ../../../src/proto.h \
  ../../../lush.h ../../../src/misc_file.h ../../../src/cmdt.h \
  ../../../src/tclegg.h ../../../src/tclhash.h \
- ../../../src/users.h ../../../src/compat/compat.h \
+ ../../../src/users.h ../../../src/compat/compat.h ../../../src/compat/inet_ntop.h \
  ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
  ../../../src/compat/memset.h ../../../src/compat/memcpy.h \
  ../../../src/compat/strcasecmp.h ../../../src/compat/strftime.h \

+ 5 - 1
src/mod/update.mod/update.c

@@ -104,7 +104,11 @@ static void update_ufsend(int idx, char *par)
   } else {
     ip = newsplit(&par);
     port = newsplit(&par);
-    sock = getsock(SOCK_BINARY,getprotocol(ip));       /* Don't buffer this -> mark binary. */
+#ifdef USE_IPV6
+    sock = getsock(SOCK_BINARY, getprotocol(ip)); /* Don't buffer this -> mark binary. */
+#else
+    sock = getsock(SOCK_BINARY); /* Don't buffer this -> mark binary. */
+#endif /* USE_IPV6 */
     if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) {
       killsock(sock);
       putlog(LOG_BOTS, "*", "Asynchronous connection failed!");

+ 3 - 1
src/modules.c

@@ -562,7 +562,9 @@ Function global_table[] =
   (Function) myip6,
   (Function) cmdprefix,
   (Function) replace,
-  (Function) degarble
+  (Function) degarble,
+  (Function) egg_inet_ntop,
+  (Function) open_listen_by_af
 
 
 };

+ 361 - 296
src/net.c

@@ -58,6 +58,13 @@ sock_list *socklist = NULL;	/* Enough to be safe			    */
 int	MAXSOCKS = 0;
 jmp_buf	alarmret;		/* Env buffer for alarm() returns	    */
 
+#ifdef USE_IPV6
+struct hostent *myipv6he;
+char myipv6host[120];
+unsigned long notalloc = 0;
+#endif /* USE_IPV6 */
+
+
 /* Types of proxy */
 #define PROXY_SOCKS   1
 #define PROXY_SUN     2
@@ -77,30 +84,31 @@ IP my_atoul(char *s)
   return ret;
 }
 
-/* define the protocol based on a given host */
 int getprotocol(char *host)
 {
-#ifndef USE_IPV6   
-  return AF_INET;
-#else
+#ifdef USE_IPV6
   struct hostent *he;
+#  ifndef HAVE_GETHOSTBYNAME2
+  int error_num;
+#  endif /* !HAVE_GETHOSTBYNAME2 */
+
   if (!setjmp(alarmret)) {
-    debug0("net.c:99 alarm with timeout");
-printf("the timeout is: %d\n", resolve_timeout);
     alarm(resolve_timeout);
-    debug0("net.c:99 alarm (Returned)");
-printf("RESOLVING %s\n", host);
-    he = gethostbyname2(host,AF_INET6);
-    debug0("net.c:102 alarm(0)");
+
+#  ifdef HAVE_GETHOSTBYNAME2
+    he = gethostbyname2(host, AF_INET6);
+#  else
+    he = getipnodebyname(host, AF_INET6, AI_DEFAULT, &error_num);
+#  endif /* HAVE_GETHOSTBYNAME2 */
     alarm(0);
   } else
-    he=NULL;
-  if(!he)
-    {
-      return AF_INET; // we check no resolve on IPv4 and assume it, if v6 does not work
-    }
+    he = NULL;
+  if (!he)
+    return AF_INET;
   return AF_INET6;
-#endif
+#else
+  return 0;
+#endif /* USE_IPV6 */
 }
 
 /* Initialize the socklist
@@ -130,8 +138,6 @@ int expmem_net()
   return tot;
 }
 
-struct hostent *myipv6he;
-char myipv6host[120];
 /* Get my ip number
  */
 IP getmyip(int dfatal)
@@ -140,14 +146,21 @@ IP getmyip(int dfatal)
   char s[121];
   IP ip;
   struct in_addr *in;
+#if defined(USE_IPV6) && !defined(HAVE_GETHOSTBYNAME2)
+  int error_num;
+#endif /* USE_IPV6 && !HAVE_GETHOSTBYNAME2 */
 
-  myipv6he=NULL;
 #ifdef USE_IPV6
+  myipv6he=NULL;
 
     if (myip6[0]) {
       if (SDEBUG)
         printf(STR("myip6: %s\n"), myip6);
-      myipv6he=gethostbyname2(myip6,AF_INET6);
+#    ifdef HAVE_GETHOSTBYNAME2
+      myipv6he = gethostbyname2(myip6, AF_INET6);
+#    else
+      myipv6he = getipnodebyname(myip6, AF_INET6, AI_DEFAULT, &error_num);
+#    endif /* !HAVE_GETHOSTBYNAME2 */
     }
 
     if (hostname6[0] && myipv6he == NULL) {
@@ -160,17 +173,14 @@ IP getmyip(int dfatal)
     }
 
     if(myipv6he != NULL)
-    {
-      inet_ntop(AF_INET6,&myipv6he,myipv6host,119);
-    }
-#endif
+      egg_inet_ntop(AF_INET6, &myipv6he, myipv6host, 119);
+#endif /* USE_IPV6 */
 
   /* Could be pre-defined */
   if (myip[0]) {
     if ((myip[strlen(myip) - 1] >= '0') && (myip[strlen(myip) - 1] <= '9'))
       return (IP) inet_addr(myip);
   }
-
   /* Also could be pre-defined */
   if (hostname[0])
     hp = gethostbyname(hostname);
@@ -178,12 +188,17 @@ IP getmyip(int dfatal)
     gethostname(s, 120);
     hp = gethostbyname(s);
   }
-
-  if (hp == NULL && myipv6he==NULL && dfatal)
+#ifdef USE_IPV6
+  if (hp == NULL && myipv6he == NULL && dfatal)
+#else
+  if (hp == NULL)
+#endif /* USE_IPV6 */
     fatal(STR("Hostname self-lookup failed.  Set 'my-ip' in the config"), 0);
 
-  if(hp == NULL) return 0;
-
+#ifdef USE_IPV6
+  if(hp == NULL)
+    return 0;
+#endif /* USE_IPV6 */
   in = (struct in_addr *) (hp->h_addr_list[0]);
   ip = (IP) (in->s_addr);
   return ip;
@@ -292,7 +307,11 @@ int sockoptions(int sock, int operation, int sock_options)
 
 /* Return a free entry in the socket entry
  */
-int allocsock(int sock, int options,int af_ty)
+#ifdef USE_IPV6
+int allocsock(int sock, int options, int af_ty)
+#else
+int allocsock(int sock, int options)
+#endif /* USE_IPV6 */
 {
   int i;
 
@@ -303,7 +322,9 @@ int allocsock(int sock, int options,int af_ty)
       socklist[i].inbuflen = socklist[i].outbuflen = 0;
       socklist[i].flags = options;
       socklist[i].sock = sock;
-      socklist[i].af=af_ty;
+#ifdef USE_IPV6
+      socklist[i].af = af_ty;
+#endif /* USE_IPV6 */
       socklist[i].encstatus = 0;
       socklist[i].gz = 0;
       egg_bzero(&socklist[i].okey, sizeof(socklist[i].okey));
@@ -317,13 +338,17 @@ int allocsock(int sock, int options,int af_ty)
 
 /* Request a normal socket for i/o
  */
+#ifdef USE_IPV6
 void setsock(int sock, int options, int af_ty)
 {
-  int i = allocsock(sock, options,af_ty);
-  int parm;
+  int i = allocsock(sock, options, af_ty), parm;
+#else
+void setsock(int sock, int options)
+{
+  int i = allocsock(sock, options), parm;
+#endif /* USE_IPV6 */
 
-  if (((sock != STDOUT) || backgrd) &&
-      !(socklist[i].flags & SOCK_NONSOCK)) {
+  if (((sock != STDOUT) || backgrd) && !(socklist[i].flags & SOCK_NONSOCK)) {
     parm = 1;
     setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &parm, sizeof(int));
 
@@ -339,17 +364,28 @@ void setsock(int sock, int options, int af_ty)
   fcntl(sock, F_SETFL, O_NONBLOCK);
 }
 
-int getsock(int options,int AF_DEF)
+#ifdef USE_IPV6
+int getsock(int options, int af_def)
+{
+  int sock = socket(af_def, SOCK_STREAM, 0);
+#else
+int getsock(int options)
 {
-  int sock = socket(AF_DEF, SOCK_STREAM, 0);
+  int sock = socket(AF_INET, SOCK_STREAM, 0);
+#endif /* USE_IPV6 */
 
   if (sock >= 0)
-    setsock(sock, options,AF_DEF);
+#ifdef USE_IPV6
+    setsock(sock, options, af_def);
+#else
+    setsock(sock, options);
+#endif /* USE_IPV6 */
   else
     putlog(LOG_MISC, "*", "Warning: Can't create new socket!");
   return sock;
 }
 
+
 /* Done with a socket
  */
 void killsock(register int sock)
@@ -383,70 +419,68 @@ void killsock(register int sock)
  */
 static int proxy_connect(int sock, char *host, int port, int proxy)
 {
-  #ifdef USE_IPV6
-   unsigned char x[32];
-  #else
+#ifdef USE_IPV6
+  unsigned char x[32];
+  int af_ty;
+#else
   unsigned char x[10];
-  #endif
+#endif /* USE_IPV6 */
   struct hostent *hp;
   char s[256];
-  int af_ty;
   int i;
 
-  af_ty=getprotocol(host);
+#ifdef USE_IPV6
+  af_ty = getprotocol(host);
+#endif /* USE_IPV6 */
   /* socks proxy */
   if (proxy == PROXY_SOCKS) {
     /* numeric IP? */
-    if ((host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') && af_ty!=AF_INET6) {
-      IP ip = ((IP) inet_addr(host)); /* drummer */      
-      egg_memcpy(x, &ip, 4);	/* Beige@Efnet */
+#ifdef USE_IPV6
+    if ((host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') && af_ty != AF_INET6) {
+#else
+    if (host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') {
+#endif /* USE_IPV6 */
+      IP ip = ((IP) inet_addr(host));
+      egg_memcpy(x, &ip, 4);
     } else {
       /* no, must be host.domain */
       if (!setjmp(alarmret)) {
 #ifdef USE_IPV6
-    debug0("net.c:404 alarm");
-	alarm(resolve_timeout);
-       if(af_ty==AF_INET6)
-         {
-           hp = gethostbyname(host);
-         } else {
-#endif
-	hp = gethostbyname(host);
+        alarm(resolve_timeout);
+        if (af_ty == AF_INET6)
+          hp = gethostbyname(host);
+        else
+#endif /* USE_IPV6 */
+          hp = gethostbyname(host);
 #ifdef USE_IPV6
-         }
-    debug0("net.c:413 alarm");
         alarm(0);
-#endif
-      } else {
-	hp = NULL;
-      }
+#endif /* USE_IPV6 */
+      } else
+        hp = NULL;
       if (hp == NULL) {
-	killsock(sock);
-	return -2;
+        killsock(sock);
+        return -2;
       }
       egg_memcpy(x, hp->h_addr, hp->h_length);
     }
-
     for (i = 0; i < MAXSOCKS; i++)
       if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock)
-	socklist[i].flags |= SOCK_PROXYWAIT; /* drummer */
+        socklist[i].flags |= SOCK_PROXYWAIT;    /* drummer */
 #ifdef USE_IPV6
-    if(af_ty==AF_INET6)
-      egg_snprintf(s, sizeof s,"\004\001%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s", (port >> 8) % 256, (port % 256),
-             x[0], x[1], x[2], x[3],
-             x[4], x[5], x[6], x[7],
-             x[9], x[9], x[10], x[11],
-             x[12], x[13], x[14], x[15],
-             botuser);
+    if (af_ty == AF_INET6)
+      egg_snprintf(s, sizeof s,
+                   "\004\001%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s",
+                   (port >> 8) % 256, (port % 256), x[0], x[1], x[2], x[3],
+                   x[4], x[5], x[6], x[7], x[9], x[9], x[10], x[11],  x[12],
+                   x[13], x[14], x[15], botuser);
     else
-#endif
-    egg_snprintf(s, sizeof s, "\004\001%c%c%c%c%c%c%s", (port >> 8) % 256,
-		 (port % 256), x[0], x[1], x[2], x[3], botuser);
-
-    tputs(sock, s, strlen(botuser) + 9); /* drummer */
+#endif /* USE_IPV6 */
+      egg_snprintf(s, sizeof s, "\004\001%c%c%c%c%c%c%s", (port >> 8) % 256,
+                   (port % 256), x[0], x[1], x[2], x[3], botuser);
+    tputs(sock, s, strlen(botuser) + 9);        /* drummer */
   } else if (proxy == PROXY_SUN) {
     egg_snprintf(s, sizeof s, "%s %d\n", host, port);
-    tputs(sock, s, strlen(s)); /* drummer */
+    tputs(sock, s, strlen(s));  /* drummer */
   }
   return sock;
 }
@@ -454,17 +488,21 @@ static int proxy_connect(int sock, char *host, int port, int proxy)
 /*
  * Return protocol of socket
 */
-
 int getsockproto(int sock)
 {
+#ifdef USE_IPV6
   int i;
   for (i = 0; i < MAXSOCKS; i++) {
     if (socklist[i].sock == sock)
       return socklist[i].af;
   }
-  return AF_INET; // default
+  return AF_INET;
+#else
+  return 0;
+#endif /* USE_IPV6 */
 }
 
+
 /* Starts a connection attempt to a socket
  * 
  * If given a normal hostname, this will be resolved to the corresponding
@@ -482,11 +520,14 @@ int open_telnet_raw(int sock, char *server, int sport)
   struct sockaddr_in6 name6;
   int rc;
   unsigned long succ;
-#endif 
+  int af_ty;
+#  ifndef HAVE_GETHOSTBYNAME2
+  int error_num;
+#  endif /* !HAVE_GETHOSTBYNAME2 */
+#endif /* USE_IPV6 */
   struct hostent *hp;
   char host[121];
   int i, port;
-  int af_ty;
   volatile int proxy;
 
   /* firewall?  use socks */
@@ -505,94 +546,91 @@ int open_telnet_raw(int sock, char *server, int sport)
     port = sport;
   }
 #ifdef USE_IPV6
-  af_ty=getprotocol(host);
-  if(af_ty==AF_INET6)
-    {
-      succ=getmyip(0);
-      bzero((char *) &name6, sizeof(struct sockaddr_in6));
+  af_ty = getprotocol(host);
+  if (af_ty == AF_INET6) {
+    succ = getmyip(0);
+    bzero((char *) &name6, sizeof(struct sockaddr_in6));
       
-      name6.sin6_family = AF_INET6;
-      if(myip[0]) 
-      {
-        if(myipv6he==NULL)
-          memcpy(&name6.sin6_addr,&in6addr_any,16);
-        else 
-          memcpy(&name6.sin6_addr,myipv6he->h_addr,myipv6he->h_length);
-      }
-      if (bind(sock, (struct sockaddr *) &name6, sizeof(name6)) < 0) {
-       killsock(sock);
-       return -1;
-      }
-      bzero((char *) &name6, sizeof(struct sockaddr_in6));
-      name6.sin6_family = AF_INET6;
-      name6.sin6_port = htons(port);
+    name6.sin6_family = AF_INET6;
+    if (myip[0]) {
+      if(myipv6he==NULL)
+        memcpy(&name6.sin6_addr, &in6addr_any, 16);
+      else 
+        memcpy(&name6.sin6_addr, myipv6he->h_addr, myipv6he->h_length);
+    }
+    if (bind(sock, (struct sockaddr *) &name6, sizeof(name6)) < 0) {
+     killsock(sock);
+     return -1;
+    }
+    bzero((char *) &name6, sizeof(struct sockaddr_in6));
+    name6.sin6_family = AF_INET6;
+    name6.sin6_port = htons(port);
+    if (!setjmp(alarmret)) {
+     alarm(resolve_timeout);
+#  ifdef HAVE_GETHOSTBYNAME2
+      hp = gethostbyname2(host, AF_INET6);
+#  else
+      hp = getipnodebyname(host, AF_INET6, AI_DEFAULT, &error_num);
+#  endif /* HAVE_GETHOSTBYNAME2 */
+     alarm(0);
+    } else
+     hp = NULL;
+    if (hp == NULL) {
+      killsock(sock);
+      return -2;
+    }
+    egg_memcpy((char *) &name6.sin6_addr, hp->h_addr, hp->h_length);
+    name6.sin6_family = hp->h_addrtype;
+#  ifndef HAVE_GETHOSTBYNAME2
+    freehostent(myipv6he);
+#  endif /* !HAVE_GETHOSTBYNAME2 */
+  } else {
+#endif /* USE_IPV6 */
+    egg_bzero((char *) &name, sizeof(struct sockaddr_in));
+
+    name.sin_family = AF_INET;
+    name.sin_addr.s_addr = (myip[0] ? getmyip(0) : INADDR_ANY);
+    if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
+      putlog(LOG_MISC, "*", "Error binding to ip: %s", strerror(errno));
+      return -1;
+    }
+    egg_bzero((char *) &name, sizeof(struct sockaddr_in));
+
+    name.sin_family = AF_INET;
+    name.sin_port = htons(port);
+    /* Numeric IP? */
+    if ((host[strlen(host) - 1] >= '0') && (host[strlen(host) - 1] <= '9'))
+      name.sin_addr.s_addr = inet_addr(host);
+    else {
+      /* No, must be host.domain */
+      debug0("WARNING: open_telnet_raw() is about to block in gethostbyname()!");
       if (!setjmp(alarmret)) {
-    debug0("net.c:530 alarm");
-       alarm(resolve_timeout);
-       hp = gethostbyname2(host,AF_INET6);
-    debug0("net.c:534 alarm");
-       alarm(0);
-      } else {
-       hp = NULL;
-      }
-      if (hp == NULL) {
-        killsock(sock);
+        alarm(resolve_timeout);
+        hp = gethostbyname(host);
+        alarm(0);
+      } else
+        hp = NULL;
+      if (hp == NULL)
         return -2;
-      }
-      egg_memcpy((char *) &name6.sin6_addr, hp->h_addr, hp->h_length);
-      name6.sin6_family = hp->h_addrtype;
-    } else {
-#endif
-  /* patch by tris for multi-hosted machines: */
-  egg_bzero((char *) &name, sizeof(struct sockaddr_in));
-
-  name.sin_family = AF_INET;
-  name.sin_addr.s_addr = (myip[0] ? getmyip(0) : INADDR_ANY);
-  if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
-    putlog(LOG_MISC, "*", "Error binding to ip: %s", strerror(errno));
-    return -1;
-  }
-  egg_bzero((char *) &name, sizeof(struct sockaddr_in));
-
-  name.sin_family = AF_INET;
-  name.sin_port = htons(port);
-  /* Numeric IP? */
-  if ((host[strlen(host) - 1] >= '0') && (host[strlen(host) - 1] <= '9'))
-    name.sin_addr.s_addr = inet_addr(host);
-  else {
-    /* No, must be host.domain */
-    debug0("WARNING: open_telnet_raw() is about to block in gethostbyname()!");
-    if (!setjmp(alarmret)) {
-    debug0("net.c:567 alarm");
-      alarm(resolve_timeout);
-      hp = gethostbyname(host);
-    debug0("net.c:569 alarm");
-      alarm(0);
-    } else {
-      hp = NULL;
+      egg_memcpy(&name.sin_addr, hp->h_addr, hp->h_length);
+      name.sin_family = hp->h_addrtype;
     }
-    if (hp == NULL)
-      return -2;
-    egg_memcpy(&name.sin_addr, hp->h_addr, hp->h_length);
-    name.sin_family = hp->h_addrtype;
+#ifdef USE_IPV6
   }
- #ifdef USE_IPV6
-     }
- #endif
+#endif /* USE_IPV6 */
   for (i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == sock))
       socklist[i].flags = (socklist[i].flags & ~SOCK_VIRTUAL) | SOCK_CONNECT;
   }
 #ifdef USE_IPV6
-  if(af_ty==AF_INET6)  
-    rc=connect(sock, (struct sockaddr *) &name6,
-              sizeof(struct sockaddr_in6));
+  if(af_ty == AF_INET6)  
+    rc = connect(sock, (struct sockaddr *) &name6,
+                 sizeof(struct sockaddr_in6));
   else 
-#endif
-    rc=connect(sock, (struct sockaddr *) &name,
-              sizeof(struct sockaddr_in));
-  if (rc < 0) {
-    if (errno == EINPROGRESS) {
+#endif /* USE_IPV6 */
+    rc = connect(sock, (struct sockaddr *) &name,
+                 sizeof(struct sockaddr_in));
+  if (rc < 0) {    if (errno == EINPROGRESS) {
       /* Firewall?  announce connect attempt to proxy */
       if (firewall[0])
 	return proxy_connect(sock, server, sport, proxy);
@@ -609,9 +647,12 @@ int open_telnet_raw(int sock, char *server, int sport)
 /* Ordinary non-binary connection attempt */
 int open_telnet(char *server, int port)
 {
-  int sock = getsock(0,getprotocol(server)),
-      ret = open_telnet_raw(sock, server, port);
-  putlog(LOG_DEBUG, "*", "net.c / open_telnet");
+#ifdef USE_IPV6
+  int sock = getsock(0, getprotocol(server)), ret = open_telnet_raw(sock, server, port);
+#else
+  int sock = getsock(0), ret = open_telnet_raw(sock, server, port);
+#endif /* USE_IPV6 */
+
   if (ret < 0)
     killsock(sock);
   return ret;
@@ -619,78 +660,89 @@ int open_telnet(char *server, int port)
 
 /* Returns a socket number for a listening socket that will accept any
  * connection on a certain address -- port # is returned in port
+ *
+ * 'addr' is ignored if af_def is AF_INET6 -poptix (02/03/03)
  */
+#ifdef USE_IPV6
+int open_address_listen(IP addr, int af_def, int *port)
+#else
 int open_address_listen(IP addr, int *port)
-{
-  int sock=0;
-  int af_def;
-  unsigned long ipp;
+#endif /* USE_IPV6 */
+ {
+  int sock = 0;
   unsigned int addrlen;
 #ifdef USE_IPV6
+  unsigned long ipp;
   struct sockaddr_in6 name6;
-#endif
+#endif /* USE_IPV6 */
   struct sockaddr_in name;
-  
+
   if (firewall[0]) {
     /* FIXME: can't do listen port thru firewall yet */
-    putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a firewall)");
+    putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a "
+           "firewall)");
     return -1;
   }
-
-  if(getmyip(0) > 0) {
-    af_def=AF_INET;
-    sock = getsock(SOCK_LISTEN,af_def);
-  if (sock < 1)
-    return -1;
-
-  egg_bzero((char *) &name, sizeof(struct sockaddr_in));
-  name.sin_family = AF_INET;
-  name.sin_port = htons(*port);	/* 0 = just assign us a port */
-  name.sin_addr.s_addr = addr;
-  if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
-    killsock(sock);
-  goto tryv6;
-  }
-  /* what port are we on? */
-  addrlen = sizeof(name);
-  if (getsockname(sock, (struct sockaddr *) &name, &addrlen) < 0) {
-    killsock(sock);
-    return -1;
-  }
-  *port = ntohs(name.sin_port);
-  if (listen(sock, 1) < 0) {
-    killsock(sock);
-    goto tryv6;
-  }
-  return sock;
-}
- tryv6:
 #ifdef USE_IPV6
-  ipp = getmyip(0);
-  af_def=AF_INET6;
-  if(af_def==AF_INET6 && myipv6he!=NULL)
-    {
-      sock = getsock(SOCK_LISTEN,af_def);
-      bzero((char *) &name6,sizeof(name6));
-      name6.sin6_family=af_def;
-      name6.sin6_port=htons(*port);
-      memcpy(&name6.sin6_addr,myipv6he->h_addr,myipv6he->h_length);
+  if (af_def == AF_INET6) {
+    ipp = getmyip(0);
+    if(af_def == AF_INET6 && myipv6he != NULL) {
+
+      sock = getsock(SOCK_LISTEN, af_def);
+      bzero((char *) &name6, sizeof(name6));
+      name6.sin6_family = af_def;
+      name6.sin6_port = htons(*port);
+      memcpy(&name6.sin6_addr, &in6addr_any, 16);
+      /* memcpy(&name6.sin6_addr, myipv6he->h_addr, myipv6he->h_length); */
       if (bind(sock, (struct sockaddr *) &name6, sizeof(name6)) < 0) {
-               killsock(sock);
-               return -1;
+        killsock(sock);
+        return -1;
       }
       addrlen = sizeof(name6);
       if (getsockname(sock, (struct sockaddr *) &name6, &addrlen) < 0) {
-               killsock(sock);
-    return -1;
-  }
+        killsock(sock);
+        return -1;
+      }
       *port = ntohs(name6.sin6_port);
       if (listen(sock, 1) < 0) {
-       killsock(sock);
-    return -1;
-  }
+        killsock(sock);
+        return -1;
+      }
+    }
+  } else {
+#endif /* USE_IPV6 */
+    if(getmyip(0) > 0) {
+#ifdef USE_IPV6
+      sock = getsock(SOCK_LISTEN, AF_INET);
+#else
+      sock = getsock(SOCK_LISTEN);
+#endif /* USE_IPV6 */
+      if (sock < 1)
+        return -1;
+
+      egg_bzero((char *) &name, sizeof(struct sockaddr_in));
+      name.sin_family = AF_INET;
+      name.sin_port = htons(*port); /* 0 = just assign us a port */
+      name.sin_addr.s_addr = addr;
+      if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
+        killsock(sock);
+        return -1;
+      }
+      /* what port are we on? */
+      addrlen = sizeof(name);
+      if (getsockname(sock, (struct sockaddr *) &name, &addrlen) < 0) {
+        killsock(sock);
+        return -1;
+      }
+      *port = ntohs(name.sin_port);
+      if (listen(sock, 1) < 0) {
+        killsock(sock);
+        return -1;
+      }
     }
-#endif 
+#ifdef USE_IPV6
+  }
+#endif /* USE_IPV6 */
   return sock;
 }
 
@@ -699,9 +751,27 @@ int open_address_listen(IP addr, int *port)
  */
 inline int open_listen(int *port)
 {
+#ifdef USE_IPV6
+  return open_address_listen(myip[0] ? getmyip(0) : INADDR_ANY, AF_INET, port);
+#else
   return open_address_listen(myip[0] ? getmyip(0) : INADDR_ANY, port);
+#endif /* USE_IPV6 */
 }
 
+/* Same as above, except this one can be called with an AF_ type
+ * the above is being left in for compatibility, and should NOT LONGER BE USED IN THE CORE CODE.
+ */
+
+inline int open_listen_by_af(int *port, int af_def)
+{
+#ifdef USE_IPV6
+  return open_address_listen(myip[0] ? getmyip(0) : INADDR_ANY, af_def, port);
+#else
+  return 0;
+#endif /* USE_IPV6 */
+}
+
+
 /* Given a network-style IP address, returns the hostname. The hostname
  * will be in the "##.##.##.##" format if there was an error.
  * 
@@ -716,10 +786,8 @@ char *hostnamefromip(unsigned long ip)
   static char s[UHOSTLEN];
 
   if (!setjmp(alarmret)) {
-    debug0("net.c:719 alarm");
     alarm(resolve_timeout);
     hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
-    debug0("net.c:723 alarm");
     alarm(0);
   } else {
     hp = NULL;
@@ -732,18 +800,7 @@ char *hostnamefromip(unsigned long ip)
   strncpyz(s, hp->h_name, sizeof s);
   return s;
 }
-/* einride's no resolving hub 
-char *stringip(unsigned long ip)
-{
-  unsigned long addr = ip;
-  unsigned char *p;
-  static char s[121];
 
-  p = (unsigned char *) &addr;
-  sprintf(s,"%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-  return s;
-}
-*/
 /* Returns the given network byte order IP address in the
  * dotted format - "##.##.##.##"
  */
@@ -755,7 +812,6 @@ char *iptostr(IP ip)
   return inet_ntoa(a);
 }
 
-unsigned long notalloc=0;
 /* Short routine to answer a connect received on a socket made previously
  * by open_listen ... returns hostname of the caller & the new socket
  * does NOT dispose of old "public" socket!
@@ -765,60 +821,57 @@ int answer(int sock, char *caller, unsigned long *ip, unsigned short *port,
 {
   int new_sock;
   unsigned int addrlen;
-  int af_ty;
+  struct sockaddr_in from;
 #ifdef USE_IPV6
+  int af_ty = getsockproto(sock);
   struct sockaddr_in6 from6;
-#endif
-  struct sockaddr_in from;
-  af_ty=getsockproto(sock);
-
-  addrlen = sizeof(struct sockaddr);
-  #ifdef USE_IPV6
-    if(af_ty==AF_INET6)
-      {
-        addrlen = sizeof(from6);
-        new_sock = accept(sock, (struct sockaddr *) &from6, &addrlen);
-      } else {
-  #endif
-        addrlen = sizeof(struct sockaddr);
-  new_sock = accept(sock, (struct sockaddr *) &from, &addrlen);
-  #ifdef USE_IPV6    
-      }
-  #endif
+
+  if (af_ty == AF_INET6) {
+    addrlen = sizeof(from6);
+    new_sock = accept(sock, (struct sockaddr *) &from6, &addrlen);
+  } else {
+#endif /* USE_IPV6 */
+    addrlen = sizeof(struct sockaddr);
+    new_sock = accept(sock, (struct sockaddr *) &from, &addrlen);
+#ifdef USE_IPV6
+  }
+#endif /* USE_IPV6 */
   
   if (new_sock < 0)
     return -1;
   if (ip != NULL) {
 #ifdef USE_IPV6
-    if(af_ty==AF_INET6)
-      {
-       *ip=notalloc;
-       inet_ntop(AF_INET6,&from6,caller,119);
-       caller[120]=0;
+    if(af_ty == AF_INET6) {
+       *ip = notalloc;
+       egg_inet_ntop(AF_INET6, &from6, caller, 119);
+       caller[120] = 0;
       } else {
-#endif
-    *ip = from.sin_addr.s_addr;
-    /* This is now done asynchronously. We now only provide the IP address.
-     *
-     * strncpy(caller, hostnamefromip(*ip), 120);
-     */
-    strncpyz(caller, iptostr(*ip), 121);
-    *ip = ntohl(*ip);
+#endif /* USE_IPV6 */
+      *ip = from.sin_addr.s_addr;
+      /* This is now done asynchronously. We now only provide the IP address.
+       *
+       * strncpy(caller, hostnamefromip(*ip), 120);
+       */
+      strncpyz(caller, iptostr(*ip), 121);
+      *ip = ntohl(*ip);
 #ifdef USE_IPV6 
-      }
-#endif
+    }
+#endif /* USE_IPV6 */
   }
-  if (port != NULL)
-    {
+  if (port != NULL) {
 #ifdef USE_IPV6
-      if(af_ty==AF_INET6)
-       *port = ntohs(from6.sin6_port);
+      if (af_ty == AF_INET6)
+        *port = ntohs(from6.sin6_port);
       else
-#endif
-    *port = ntohs(from.sin_port);
+#endif /* USE_IPV6 */
+        *port = ntohs(from.sin_port);
     }
   /* Set up all the normal socket crap */
-  setsock(new_sock, (binary ? SOCK_BINARY : 0),af_ty);
+#ifdef USE_IPV6
+  setsock(new_sock, (binary ? SOCK_BINARY : 0), af_ty);
+#else
+  setsock(new_sock, (binary ? SOCK_BINARY : 0));
+#endif /* USE_IPV6 */
   return new_sock;
 }
 
@@ -831,33 +884,40 @@ int open_telnet_dcc(int sock, char *server, char *port)
   char sv[500];
   unsigned char c[4];
 
+#ifdef DEBUG_IPV6
+  debug1("open_telnet_dcc %s", server);
+#endif /* DEBUG_IPV6 */
   if (port != NULL)
     p = atoi(port);
   else
     p = 2000;
 #ifdef USE_IPV6
-  if(getprotocol(server)==AF_INET6)
-    {
-      server[0]=0;
-      if(strlen(server)<500)
-       strcpy(sv,server);
-    } else {
-#endif
-  if (server != NULL)
-    addr = my_atoul(server);
-  else
-    addr = 0L;
-  if (addr < (1 << 24))
-    return -3;			/* fake address */
-  c[0] = (addr >> 24) & 0xff;
-  c[1] = (addr >> 16) & 0xff;
-  c[2] = (addr >> 8) & 0xff;
-  c[3] = addr & 0xff;
-  sprintf(sv, "%u.%u.%u.%u", c[0], c[1], c[2], c[3]);
+  if (getprotocol(server) == AF_INET6) {
+#  ifdef DEBUG_IPV6
+    debug0("open_telnet_dcc, af_inet6!");
+#  endif /* DEBUG_IPV6 */
+    strncpyz(sv, server, sizeof sv);
+    debug2("%s should be %s",sv,server);
+  } else {
+#endif /* USE_IPV6 */
+    if (server != NULL)
+      addr = my_atoul(server);
+    else
+      addr = 0L;
+    if (addr < (1 << 24))
+      return -3;			/* fake address */
+    c[0] = (addr >> 24) & 0xff;
+    c[1] = (addr >> 16) & 0xff;
+    c[2] = (addr >> 8) & 0xff;
+    c[3] = addr & 0xff;
+    sprintf(sv, "%u.%u.%u.%u", c[0], c[1], c[2], c[3]);
 #ifdef USE_IPV6
-    }   
-#endif
+    }
   /* strcpy(sv,hostnamefromip(addr)); */
+#  ifdef DEBUG_IPV6
+  debug3("open_telnet_raw %s %d %d", sv, sock,p);
+#  endif /* DEBUG_IPV6 */
+#endif /* USE_IPV6 */
   p = open_telnet_raw(sock, sv, p);
   return p;
 }
@@ -1502,6 +1562,11 @@ int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
   /* According to the latest RFC, the clients SHOULD be able to handle
    * DNS names that are up to 255 characters long.  This is not broken.
    */
+
+  /* This function needs to be updated for IPv6 IP's, although it doesn't
+   * currently harm them (afaik)
+   */
+
   char badaddress[16];
   IP ip = my_atoul(ipaddy);
   int prt = atoi(port);
@@ -1509,12 +1574,12 @@ int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
   /* It is disabled HERE so we only have to check in *one* spot! */
   if (!dcc_sanitycheck)
     return 1;
-  #ifdef USE_IPV6
-  if(getprotocol(ipaddy)==AF_INET6)
-  {  
-      return 1;   
-  }
-  #endif
+
+#ifdef USE_IPV6
+  if (getprotocol(ipaddy) == AF_INET6)
+    return 1;
+#endif /* USE_IPV6 */
+
   if (prt < 1) {
     putlog(LOG_MISC, "*", "ALERT: (%s!%s) specified an impossible port of %u!",
 	   nick, from, prt);

+ 14 - 3
src/proto.h

@@ -55,6 +55,7 @@ char *decryptit (char *);
 int lfprintf(FILE *, char *, ...);
 
 /* botnet.c */
+inline int open_listen_by_af(int *, int);
 void lower_bot_linked(int idx);
 void higher_bot_linked(int idx);
 void answer_local_whom(int, int);
@@ -284,15 +285,25 @@ IP my_atoul(char *);
 unsigned long iptolong(IP);
 IP getmyip(int);
 void neterror(char *);
+#ifdef USE_IPV6
 void setsock(int, int, int);
-int allocsock(int, int,int);
-int getsock(int, int); 
+int allocsock(int, int, int);
+int getsock(int, int);
+#else
+void setsock(int, int);
+int allocsock(int, int);
+int getsock(int);
+#endif /* USE_IPV6 */
 int getprotocol(char *);
 char *hostnamefromip(unsigned long);
 void killsock(int);
 int answer(int, char *, unsigned long *, unsigned short *, int);
 inline int open_listen(int *);
-int open_address_listen(IP addr, int *port);
+#ifdef USE_IPV6
+int open_address_listen(IP addr, int af_def, int *);
+#else
+int open_address_listen(IP addr, int *);
+#endif /* USE_IPV6 */
 int open_telnet(char *, int);
 int open_telnet_dcc(int, char *, char *);
 int open_telnet_raw(int, char *, int);

部分文件因文件數量過多而無法顯示