Subject: | [PATCH] Workaround for systems without getprotobyname() |
Howdy!
The attached patch adds support for systems without getprotobyname. Realistically, this really just means Android :)
With the patch applied, the module builds and tests cleanly:
shell@android:home # perl -MNet::SNMP -E 'say "$^O: ", Net::SNMP->VERSION'
android: v6.0.1
Subject: | 0001-Workaround-for-systems-without-getprotobyname.patch |
From 7d813e4c3967855fb8263c87d74ee05aa82561d5 Mon Sep 17 00:00:00 2001
From: Brian Fraser <fraserbn@gmail.com>
Date: Tue, 19 Aug 2014 21:51:57 +0200
Subject: [PATCH] Workaround for systems without getprotobyname()
Some systems, like Android, have no getprotobyname(),
which causes the module to throw an exception when the
functions are used.
Thankfully, Socket.pm always defines these constants,
so they are safe to use, and, as a bonus, slightly faster
than calling a function.
---
lib/Net/SNMP/Transport/IPv4/TCP.pm | 6 ++++++
lib/Net/SNMP/Transport/IPv4/UDP.pm | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/lib/Net/SNMP/Transport/IPv4/TCP.pm b/lib/Net/SNMP/Transport/IPv4/TCP.pm
index a070a1e..e318ee4 100644
--- a/lib/Net/SNMP/Transport/IPv4/TCP.pm
+++ b/lib/Net/SNMP/Transport/IPv4/TCP.pm
@@ -23,6 +23,7 @@ use Net::SNMP::Transport qw(
use Net::SNMP::Message qw( SEQUENCE );
+use Socket (); # For the constants
use IO::Socket qw( SOCK_STREAM );
## Version of the Net::SNMP::Transport::IPv4::TCP module
@@ -262,6 +263,11 @@ sub _protocol_name
return 'tcp';
}
+sub _protocol
+{
+ return Socket::IPPROTO_TCP;
+}
+
sub _protocol_type
{
return SOCK_STREAM;
diff --git a/lib/Net/SNMP/Transport/IPv4/UDP.pm b/lib/Net/SNMP/Transport/IPv4/UDP.pm
index 0200e77..15a7e8b 100644
--- a/lib/Net/SNMP/Transport/IPv4/UDP.pm
+++ b/lib/Net/SNMP/Transport/IPv4/UDP.pm
@@ -19,6 +19,7 @@ use strict;
use Net::SNMP::Transport qw( DOMAIN_UDPIPV4 );
+use Socket (); # For the constants
use IO::Socket qw( SOCK_DGRAM );
## Version of the Net::SNMP::Transport::IPv4::UDP module
@@ -109,6 +110,11 @@ sub _protocol_name
return 'udp';
}
+sub _protocol
+{
+ return Socket::IPPROTO_UDP;
+}
+
sub _protocol_type
{
return SOCK_DGRAM;
--
1.7.12.4 (Apple Git-37)