From dac716be9f8a4e09181db210c03d4f843f39d16c Mon Sep 17 00:00:00 2001 From: Mikolaj Kucharski Date: Sun, 10 Dec 2017 16:58:27 +0000 Subject: [PATCH 1/3] Fix build flags after switching to Module::Build --- Build.PL | 62 +++++++++++++++++++++++++++++++++++++++++---- Changes | 4 +++ MANIFEST | 2 -- lib/IO/Interface.pm | 2 +- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/Build.PL b/Build.PL index 8f93f76..393e216 100644 --- a/Build.PL +++ b/Build.PL @@ -2,6 +2,51 @@ use strict; use Module::Build; +use Config; + +sub compiler_flags() { + my @flags = (); + my %cfg = ( + 'freebsd' => '-D__USE_BSD', + 'netbsd' => '-D__USE_BSD', + 'openbsd' => '-D__USE_BSD', + ); + + print "Checking for BSD-like operating system..."; + if (exists $cfg{$^O}) { + push @flags, $cfg{$^O}; + print " Okay, present.\n"; + } else { + print " Nope, not present.\n"; + } + + print "Checking for SIOCGIFCONF..."; + if (!-r "/usr/include/sys/sockio.h") { + print " Nope, will not use it.\n"; + } else { + push @flags, '-DSIOCGIFCONF'; + print " Okay, I will use it.\n"; + } + + print "Checking for getifaddrs()..."; + eval { require 'ifaddrs.ph' }; + if ($@ && !-r "/usr/include/ifaddrs.h") { + print " Nope, will not use it.\n"; + } else { + push @flags, '-DUSE_GETIFADDRS'; + print " Okay, I will use it.\n"; + } + + print "Checking for sockaddr_dl..."; + if (!-r "/usr/include/net/if_dl.h") { + print " Nope, will not use it.\n"; + } else { + push @flags, '-DHAVE_SOCKADDR_DL_STRUCT'; + print " Okay, I will use it.\n"; + } + + return \@flags; +} my $build = Module::Build->new( module_name => 'IO::Interface', @@ -9,13 +54,20 @@ my $build = Module::Build->new( dist_author => 'Lincoln Stein ', dist_abstract => 'Access and modify network interface card configuration', license => 'perl', - build_requires => { - 'ExtUtils::CBuilder' => 0, + dynamic_config => 1, + extra_compiler_flags => compiler_flags(), + build_requires => { + 'Config' => 0, + 'ExtUtils::CBuilder' => 0, }, - requires => { - 'perl' => '5.005', + requires => { + 'perl' => '5.005', }, - ); + 'resources' => { + 'homepage' => 'http://search.cpan.org/dist/IO-Interface/', + 'repository' => 'https://github.com/lstein/LibIO-Interface-Perl/', + }, +); $build->create_build_script(); diff --git a/Changes b/Changes index 9be2ad3..ed49d7c 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,8 @@ Revision history for Perl extension IO::Interface. + +1.10 Sun Dec 10 15:54:57 GMT 2017 + -Fix build flags after switching to Module::Build + 1.09 Tue Dec 9 11:22:56 EST 2014 -Converted to use Module::Build diff --git a/MANIFEST b/MANIFEST index e8d2d0d..f3cdb52 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,8 +5,6 @@ lib/IO/Interface.xs lib/IO/Interface/Simple.pm LICENSE MANIFEST -META.json -META.yml Module meta-data (added by MakeMaker) README.md t/basic.t t/simple.t diff --git a/lib/IO/Interface.pm b/lib/IO/Interface.pm index 419aa00..8d5096d 100644 --- a/lib/IO/Interface.pm +++ b/lib/IO/Interface.pm @@ -27,7 +27,7 @@ my @flags = qw(IFF_ALLMULTI IFF_AUTOMEDIA IFF_BROADCAST @EXPORT = qw( ); @ISA = qw(Exporter DynaLoader); -$VERSION = '1.09'; +$VERSION = '1.10'; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant() From 151113ffde800b5dd5be5a1d0f5d54530ed1522f Mon Sep 17 00:00:00 2001 From: Bill Sommerfeld Date: Wed, 29 Jan 2025 17:38:40 -0800 Subject: [PATCH 2/3] Fix detection and use of sockio.h --- Build.PL | 4 ++-- lib/IO/Interface.xs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Build.PL b/Build.PL index 393e216..6b912c3 100644 --- a/Build.PL +++ b/Build.PL @@ -20,11 +20,11 @@ sub compiler_flags() { print " Nope, not present.\n"; } - print "Checking for SIOCGIFCONF..."; + print "Checking for sockio.h..."; if (!-r "/usr/include/sys/sockio.h") { print " Nope, will not use it.\n"; } else { - push @flags, '-DSIOCGIFCONF'; + push @flags, '-DHAVE_SOCKIO_H'; print " Okay, I will use it.\n"; } diff --git a/lib/IO/Interface.xs b/lib/IO/Interface.xs index 9d500d9..878dded 100644 --- a/lib/IO/Interface.xs +++ b/lib/IO/Interface.xs @@ -28,7 +28,7 @@ #endif -#ifndef SIOCGIFCONF +#if defined(HAVE_SOCKIO_H) #include #endif From e3dddbcf406388c241c33967a292fe8bde14c219 Mon Sep 17 00:00:00 2001 From: Bill Sommerfeld Date: Wed, 29 Jan 2025 17:29:39 -0800 Subject: [PATCH 3/3] Switch from bzero to memcpy --- lib/IO/Interface.xs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/IO/Interface.xs b/lib/IO/Interface.xs index 878dded..903931f 100644 --- a/lib/IO/Interface.xs +++ b/lib/IO/Interface.xs @@ -426,7 +426,7 @@ if_addr(sock, name, ...) if (strncmp(name,"any",3) == 0) { RETVAL = "0.0.0.0"; } else { - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); ifr.ifr_addr.sa_family = AF_INET; if (items > 2) { @@ -465,7 +465,7 @@ if_broadcast(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFBRDADDR)) XSRETURN_UNDEF; #else - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); ifr.ifr_addr.sa_family = AF_INET; if (items > 2) { @@ -503,7 +503,7 @@ if_netmask(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFNETMASK)) XSRETURN_UNDEF; #else - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); ifr.ifr_addr.sa_family = AF_INET; if (items > 2) { @@ -544,7 +544,7 @@ if_dstaddr(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFDSTADDR)) XSRETURN_UNDEF; #else - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); ifr.ifr_addr.sa_family = AF_INET; if (items > 2) { @@ -621,7 +621,7 @@ if_hwaddr(sock, name, ...) RETVAL = hwaddr; #elif (defined(HAS_IOCTL) && defined(SIOCGIFHWADDR)) - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); ifr.ifr_hwaddr.sa_family = AF_UNSPEC; if (items > 2) { @@ -658,7 +658,7 @@ if_flags(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFFLAGS)) XSRETURN_UNDEF; #endif - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); if (items > 2) { ifr.ifr_flags = SvIV(ST(2)); @@ -690,7 +690,7 @@ if_mtu(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFFLAGS)) XSRETURN_UNDEF; #endif - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); if (items > 2) { ifr.ifr_flags = SvIV(ST(2)); @@ -722,7 +722,7 @@ if_metric(sock, name, ...) #if !(defined(HAS_IOCTL) && defined(SIOCGIFFLAGS)) XSRETURN_UNDEF; #endif - bzero((void*)&ifr,sizeof(struct ifreq)); + memset((void*)&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name,name,IFNAMSIZ-1); if (items > 2) { ifr.ifr_flags = SvIV(ST(2));