net-misc/wakeonlan: revbump with new homepage & other fixes

Closes: https://bugs.gentoo.org/612406
Closes: https://bugs.gentoo.org/554366
Closes: https://bugs.gentoo.org/569900
Package-Manager: Portage-2.3.94, Repoman-2.3.21
Signed-off-by: Ben Kohler <bkohler@gentoo.org>
This commit is contained in:
Ben Kohler
2020-03-16 08:36:25 -05:00
parent 84b07a1e6b
commit 790d0e9905
2 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
--- wakeonlan-0.41.orig/wakeonlan
+++ wakeonlan-0.41/wakeonlan
@@ -5,6 +5,7 @@
#########################################################################
use strict;
+use Net::hostent;
use Socket;
use Getopt::Std;
use vars qw($VERSION $opt_v $opt_h $opt_i $opt_p $opt_f);
@@ -44,19 +45,64 @@
sub wake
{
- my $hwaddr = shift;
+ my $host = shift;
my $ipaddr = shift || $DEFAULT_IP;
my $port = shift || $DEFAULT_PORT;
my ($raddr, $them, $proto);
- my ($hwaddr_re, $pkt);
+ my ($hwaddr, $hwaddr_re, $pkt);
- # Validate hardware address (ethernet address)
+ # get the hardware address (ethernet address)
$hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6);
- if ($hwaddr !~ m/^$hwaddr_re$/) {
- warn "Invalid hardware address: $hwaddr\n";
- return undef;
+ if ($host =~ m/^$hwaddr_re$/) {
+ $hwaddr = $host;
+ } else {
+ # $host is not a hardware address, try to resolve it
+ my $ip_re = join('\.', ('([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))') x 4);
+ my $ip_addr;
+ if ($host =~ m/^$ip_re$/) {
+ $ip_addr = $host;
+ } else {
+ my $h;
+ unless ($h = gethost($host)) {
+ warn "$host is not a hardware address and I could not resolve it as to an IP address.\n";
+ return undef;
+ }
+ $ip_addr = inet_ntoa($h->addr);
+ }
+ # look up ip in /etc/ethers
+ unless (open (ETHERS, '<', '/etc/ethers')) {
+ warn "$host is not a hardware address and I could not open /etc/ethers.\n";
+ return undef;
+ }
+ while (<ETHERS>) {
+ if (($_ !~ m/^$/) && ($_ !~ m/^#/)) { # ignore comments
+ my ($mac, $ip);
+ ($mac, $ip) = split(' ', $_, 3);
+ if ($ip =~ m/^$ip_re$/) {
+ if ($ip eq $ip_addr) {
+ $hwaddr = $mac;
+ last;
+ }
+ next;
+ } else {
+ my $h2;
+ unless ($h2 = gethost($ip)) {
+ next;
+ }
+ if (inet_ntoa($h2->addr) eq $ip_addr) {
+ $hwaddr = $mac;
+ last;
+ }
+ }
+ }
+ }
+ close (ETHERS);
+ unless (defined($hwaddr)) {
+ warn "Could not find $host in /etc/ethers\n";
+ return undef;
+ }
}
# Generate magic sequence
@@ -68,7 +114,7 @@
# Allocate socket and send packet
- $raddr = gethostbyname($ipaddr);
+ $raddr = gethostbyname($ipaddr)->addr;
$them = pack_sockaddr_in($port, $raddr);
$proto = getprotobyname('udp');

View File

@@ -0,0 +1,25 @@
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
GENTOO_DEPEND_ON_PERL=noslotop
inherit perl-module
DESCRIPTION="Client for Wake-On-LAN"
HOMEPAGE="https://github.com/jpoliv/wakeonlan/"
SRC_URI="https://github.com/jpoliv/wakeonlan/archive/${P}.tar.gz"
LICENSE="Artistic GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~arm ~ppc ~sparc ~x86 ~amd64-linux ~x86-linux"
IUSE=""
DEPEND="virtual/perl-ExtUtils-MakeMaker"
PATCHES="${FILESDIR}/${P}-ethers-lookup-r1.patch"
src_install() {
perl-module_src_install
dodoc examples/lab001.wol
fperms u+w /usr/bin/wakeonlan /usr/share/man/man1/wakeonlan.1
}