[BACK]Return to patch-aa CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / chat / sirc / patches

File: [cvs.NetBSD.org] / pkgsrc / chat / sirc / patches / patch-aa (download)

Revision 1.1, Thu Dec 21 23:02:38 2000 UTC (16 years, 7 months ago) by hubertf
Branch: MAIN
CVS Tags: pkgviews-base, pkgviews, pkgsrc-2017Q2-base, pkgsrc-2017Q2, pkgsrc-2017Q1-base, pkgsrc-2017Q1, pkgsrc-2016Q4-base, pkgsrc-2016Q4, pkgsrc-2016Q3-base, pkgsrc-2016Q3, pkgsrc-2016Q2-base, pkgsrc-2016Q2, pkgsrc-2016Q1-base, pkgsrc-2016Q1, pkgsrc-2015Q4-base, pkgsrc-2015Q4, pkgsrc-2015Q3-base, pkgsrc-2015Q3, pkgsrc-2015Q2-base, pkgsrc-2015Q2, pkgsrc-2015Q1-base, pkgsrc-2015Q1, pkgsrc-2014Q4-base, pkgsrc-2014Q4, pkgsrc-2014Q3-base, pkgsrc-2014Q3, pkgsrc-2014Q2-base, pkgsrc-2014Q2, pkgsrc-2014Q1-base, pkgsrc-2014Q1, pkgsrc-2013Q4-base, pkgsrc-2013Q4, pkgsrc-2013Q3-base, pkgsrc-2013Q3, pkgsrc-2013Q2-base, pkgsrc-2013Q2, pkgsrc-2013Q1-base, pkgsrc-2013Q1, pkgsrc-2012Q4-base, pkgsrc-2012Q4, pkgsrc-2012Q3-base, pkgsrc-2012Q3, pkgsrc-2012Q2-base, pkgsrc-2012Q2, pkgsrc-2012Q1-base, pkgsrc-2012Q1, pkgsrc-2011Q4-base, pkgsrc-2011Q4, pkgsrc-2011Q3-base, pkgsrc-2011Q3, pkgsrc-2011Q2-base, pkgsrc-2011Q2, pkgsrc-2011Q1-base, pkgsrc-2011Q1, pkgsrc-2010Q4-base, pkgsrc-2010Q4, pkgsrc-2010Q3-base, pkgsrc-2010Q3, pkgsrc-2010Q2-base, pkgsrc-2010Q2, pkgsrc-2010Q1-base, pkgsrc-2010Q1, pkgsrc-2009Q4-base, pkgsrc-2009Q4, pkgsrc-2009Q3-base, pkgsrc-2009Q3, pkgsrc-2009Q2-base, pkgsrc-2009Q2, pkgsrc-2009Q1-base, pkgsrc-2009Q1, pkgsrc-2008Q4-base, pkgsrc-2008Q4, pkgsrc-2008Q3-base, pkgsrc-2008Q3, pkgsrc-2008Q2-base, pkgsrc-2008Q2, pkgsrc-2008Q1-base, pkgsrc-2008Q1, pkgsrc-2007Q4-base, pkgsrc-2007Q4, pkgsrc-2007Q3-base, pkgsrc-2007Q3, pkgsrc-2007Q2-base, pkgsrc-2007Q2, pkgsrc-2007Q1-base, pkgsrc-2007Q1, pkgsrc-2006Q4-base, pkgsrc-2006Q4, pkgsrc-2006Q3-base, pkgsrc-2006Q3, pkgsrc-2006Q2-base, pkgsrc-2006Q2, pkgsrc-2006Q1-base, pkgsrc-2006Q1, pkgsrc-2005Q4-base, pkgsrc-2005Q4, pkgsrc-2005Q3-base, pkgsrc-2005Q3, pkgsrc-2005Q2-base, pkgsrc-2005Q2, pkgsrc-2005Q1-base, pkgsrc-2005Q1, pkgsrc-2004Q4-base, pkgsrc-2004Q4, pkgsrc-2004Q3-base, pkgsrc-2004Q3, pkgsrc-2004Q2-base, pkgsrc-2004Q2, pkgsrc-2004Q1-base, pkgsrc-2004Q1, pkgsrc-2003Q4-base, pkgsrc-2003Q4, netbsd-1-6-RELEASE-base, netbsd-1-6-1-base, netbsd-1-6-1, netbsd-1-6, netbsd-1-5-PATCH003, netbsd-1-5-PATCH001, cwrapper, cube-native-xorg-base, cube-native-xorg, buildlink2-base, buildlink2, HEAD

Add patch to work with IPv6. Also tested on (non-v6) NetBSD 1.4 and with
v4 servers on v6-enabled system.

$NetBSD: patch-aa,v 1.1 2000/12/21 23:02:38 hubertf Exp $

--- dsirc	Wed Sep 27 09:34:49 2000
+++ dsirc6	Thu Dec 21 23:19:02 2000
@@ -52,6 +52,8 @@
 }
 
 if ($] >= 5 && (eval "use Socket;", $@ eq '')) {
+    print "used Socket\n";
+    use Socket6;
 } elsif (-f "$libdir/sircsock.ph") {
   do "$libdir/sircsock.ph";
 } elsif (-f $ENV{'HOME'}."/sircsock.ph") {
@@ -95,6 +97,7 @@
 $restrict=$opt_R;
 $set{"LOCALHOST"}=$opt_H || $ENV{"SIRCHOST"} || $ENV{"IRCHOST"} ||
 		$ENV{"LOCALHOST"} || "";
+$use_ipv6=0;   # enabled when the given server gets resolved by gethostbyname2
 
 if ($set{"LOCALHOST"}) {
   $bindaddr=&resolve($set{"LOCALHOST"});
@@ -148,7 +151,16 @@
   } elsif ($_[0] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
     return pack("c4", $1, $2, $3, $4);
   } else {
-    return (gethostbyname($_[0]))[4];
+      local $rc;
+
+      $rc = (gethostbyname2($_[0], AF_INET6))[4];
+
+      if ($rc) {
+	  $use_ipv6 = 1;
+	  return $rc;
+      } else {
+	  return (gethostbyname($_[0]))[4];
+      }
   }
 }
 
@@ -162,19 +174,31 @@
   local($fh, $host, $port)=@_;
   local($adr, $otherend)=&resolve($host);
   &tell("*\cbE\cb* Hostname `$host' not found"), return 0 unless $adr;
-  $otherend=pack("S n a4 x8", &AF_INET, $port, $adr);
-  &print("*\cbE\cb* Out of file descriptors"), return 0
-    unless socket($fh, &PF_INET, &SOCK_STREAM, 0);
-  if ($set{"LOCALHOST"}) {
-    bind($fh, pack("S n a4 x8", &AF_INET, 0, $bindaddr)) ||
-      &tell("*\cbE\cb* Warning: can't bind to sirc host ".$set{'LOCALHOST'});
+  if ($use_ipv6) {
+      $otherend=pack_sockaddr_in6($port, $adr);
+      &print("*\cbE\cb* Out of file descriptors"), return 0
+	  unless socket($fh, &PF_INET6, &SOCK_STREAM, 0);
+  } else {
+      $otherend=pack_sockaddr_in($port, $adr);
+      &print("*\cbE\cb* Out of file descriptors"), return 0
+	  unless socket($fh, &PF_INET, &SOCK_STREAM, 0);
+  }
+  if (! $use_ipv6) {
+      if ($set{"LOCALHOST"}) {
+	  bind($fh, pack("S n a4 x8", &AF_INET, 0, $bindaddr)) ||
+	      &tell("*\cbE\cb* Warning: can't bind to sirc host ".$set{'LOCALHOST'});
+      }
   }
   $trysock=$fh;
   $SIG{'QUIT'}='sigquit';
   &print("*\cbE\cb* Can't connect to host: $!"), close $fh,
     $SIG{'QUIT'}='IGNORE', return 0 unless connect($fh, $otherend);
   $SIG{'QUIT'}='IGNORE';
-  $bindaddr=(unpack("S n a4", getsockname($fh)))[2] if !$bindaddr;
+  if ($use_ipv6) {
+      $bindaddr=(unpack_sockaddr_in6(getsockname($fh)))[2] if !$bindaddr;
+  } else {
+      $bindaddr=(unpack_sockaddr_in(getsockname($fh)))[2] if !$bindaddr;
+  }
   select($fh); $|=1; select(STDOUT);
   return 1;
 }
@@ -183,15 +207,26 @@
   $_[0]=&newfh;
   local($fh, $port)=@_;
   local($thisend);
-  $bindaddr=pack("x4", 0) unless $bindaddr;
-  $thisend=pack("S n a4 x8", &AF_INET, $port+0, $bindaddr);
-  &tell("*\cbE\cb* Out of file descriptors"), return 0
-    unless socket($fh, &PF_INET, &SOCK_STREAM, 0);
+  if ($use_ipv6) {
+      $bindaddr=pack_sockaddr_in6(0, 0) unless $bindaddr;
+      $thisend=pack_sockaddr_in6($port+0, $bindaddr);
+      &tell("*\cbE\cb* Out of file descriptors"), return 0
+	  unless socket($fh, &PF_INET6, &SOCK_STREAM, 0);
+  } else {
+      $bindaddr=pack_sockaddr_in(0, 0) unless $bindaddr;
+      $thisend=pack_sockaddr_in($port+0, $bindaddr);
+      &tell("*\cbE\cb* Out of file descriptors"), return 0
+	  unless socket($fh, &PF_INET, &SOCK_STREAM, 0);
+  }
   &tell("*\cbE\cb* Can't bind local socket!"), close $fh, return 0
     unless bind($fh, $thisend);
   &tell("*\cbE\cb* Can't listen to socket!"), close $fh, return
     unless listen($fh, 5);
-  return (unpack("S n", getsockname($fh)))[1];
+  if ($use_ipv6) {
+      return (unpack_sockaddr_in6(getsockname($fh)))[1];
+  } else {
+      return (unpack_sockaddr_in(getsockname($fh)))[1];
+  }
 }
 
 sub accept {