diff --git a/nix/dev-shells/default.nix b/nix/dev-shells/default.nix index 73e04d7b..88c0b483 100644 --- a/nix/dev-shells/default.nix +++ b/nix/dev-shells/default.nix @@ -48,6 +48,13 @@ inputs.nixpkgs.lib.genAttrs networkSub = with pkgs; [ perl + perlPackages.libnet + perlPackages.Expect + perlPackages.TermReadKey + perlPackages.NetSFTPForeign + scale-network.perlNetArp + scale-network.perlNetInterface + scale-network.perlNetPing ghostscript ]; in diff --git a/nix/packages/default.nix b/nix/packages/default.nix index 68f83b55..666c3f36 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -9,5 +9,8 @@ inputs.nixpkgs.lib.genAttrs massflash scaleInventory serverspec + perlNetArp + perlNetInterface + perlNetPing ; }) diff --git a/nix/packages/perl-net-arp/package.nix b/nix/packages/perl-net-arp/package.nix new file mode 100644 index 00000000..8d9506a2 --- /dev/null +++ b/nix/packages/perl-net-arp/package.nix @@ -0,0 +1,13 @@ +{ + perlPackages, + fetchurl, +}: + +perlPackages.buildPerlPackage { + pname = "NetArp"; + version = "1.0.12"; + src = fetchurl { + url = "mirror://cpan/authors/id/C/CR/CRAZYDJ/Net-ARP-1.0.12.tar.gz"; + hash = "sha256-KK2GBaOh4PhoqYmIJvVGHYCSPm66GtXgRzfmDoug7HA="; + }; +} diff --git a/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch b/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch new file mode 100644 index 00000000..eb742ded --- /dev/null +++ b/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch @@ -0,0 +1,16 @@ +diff --git a/Makefile.PL b/Makefile.PL +index 973e65e..6ad0d51 100644 +--- a/Makefile.PL ++++ b/Makefile.PL +@@ -176,11 +176,6 @@ unless (open(F,'./netsymbolC.inc')) { + exit; + } + +-unless (scalar grep {/# define\s+_NI_AF_INET/} ()) { +- close F; +- die "AF_INET not found in netsymbolsC.inc,\nprerequisite development library header files missing from /usr/include/sys\n"; +- exit 0; +-} + close F; + + WriteMakefile(%makeparms); diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix new file mode 100644 index 00000000..eaf3d27a --- /dev/null +++ b/nix/packages/perl-net-interface/package.nix @@ -0,0 +1,17 @@ +{ + perlPackages, + fetchurl, +}: +perlPackages.buildPerlPackage { + pname = "NetInterface"; + version = "1.016"; + + src = fetchurl { + url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz"; + hash = "sha256-e+RGk14BPQ7dPTcfkvuQo7s4q+mVYoidgXiVMSnlNQg="; + }; + + patches = [ ./net-interface-remove-grep-af-inet.patch ]; + + doCheck = false; +} diff --git a/nix/packages/perl-net-ping/linux-isroot-capability.patch b/nix/packages/perl-net-ping/linux-isroot-capability.patch new file mode 100644 index 00000000..f100dd3f --- /dev/null +++ b/nix/packages/perl-net-ping/linux-isroot-capability.patch @@ -0,0 +1,48 @@ +diff --git a/lib/Net/Ping.pm b/lib/Net/Ping.pm +index 0b7be8c..60aca57 100644 +--- a/lib/Net/Ping.pm ++++ b/lib/Net/Ping.pm +@@ -227,13 +227,21 @@ sub new + } + elsif ($self->{proto} eq "icmp") + { +- croak("icmp ping requires root privilege") if !_isroot(); ++ croak("icmp ping requires root privilege") if !_isroot() && ($^O ne "linux"); + $self->{proto_num} = eval { (getprotobyname('icmp'))[2] } || + croak("Can't get icmp protocol by name"); + $self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid + $self->{fh} = FileHandle->new(); +- socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) || +- croak("icmp socket error - $!"); ++ if ($^O eq "linux") ++ { ++ socket($self->{fh}, PF_INET, SOCK_DGRAM, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } ++ else ++ { ++ socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } + $self->_setopts(); + if ($self->{'ttl'}) { + setsockopt($self->{fh}, IPPROTO_IP, IP_TTL, pack("I*", $self->{'ttl'})) +@@ -250,8 +258,16 @@ sub new + croak("Can't get ipv6-icmp protocol by name"); # 58 + $self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid + $self->{fh} = FileHandle->new(); +- socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) || +- croak("icmp socket error - $!"); ++ if ($^O eq "linux") ++ { ++ socket($self->{fh}, $AF_INET6, SOCK_DGRAM, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } ++ else ++ { ++ socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } + $self->_setopts(); + if ($self->{'gateway'}) { + my $g = $self->{gateway}; diff --git a/nix/packages/perl-net-ping/package.nix b/nix/packages/perl-net-ping/package.nix new file mode 100644 index 00000000..0b2a7dd9 --- /dev/null +++ b/nix/packages/perl-net-ping/package.nix @@ -0,0 +1,9 @@ +{ + perlPackages, +}: + +perlPackages.NetPing.overrideAttrs { + # Owen's patch for _isroot should consider CAP_NET_RAW capability on Linux + # related to: https://rt.cpan.org/Public/Bug/Display.html?id=139820 + patches = [ ./linux-isroot-capability.patch ]; +}