Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when gethostbyaddr did not return anything #7

Open
egore opened this issue Aug 27, 2013 · 0 comments
Open

Fix warning when gethostbyaddr did not return anything #7

egore opened this issue Aug 27, 2013 · 0 comments

Comments

@egore
Copy link

egore commented Aug 27, 2013

I get the following error lots of times:
Use of uninitialized value $host in substitution (s///) at ./mytop line 958.

This happens when gethostbyaddr returns null. In that case we should show the IP instead:

From 602d063dbac4ae94b2d2273ceef9fbf01f9ca1d9 Mon Sep 17 00:00:00 2001
From: Christoph Brill <[email protected]>
Date: Tue, 27 Aug 2013 16:11:13 +0200
Subject: [PATCH] If gethostbyaddr return nothing, keep using the IP

---
 mytop | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mytop b/mytop
index fba27fd..8d6bf42 100755
--- a/mytop
+++ b/mytop
@@ -955,8 +955,11 @@ sub GetData()
         {
             $thread->{Host} =~ s/:\d+$//;
             my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET);
-            $host =~ s/^([^.]+).*/$1/;
-            $thread->{Host} = $host;
+            if ($host)
+            {
+                $host =~ s/^([^.]+).*/$1/;
+                $thread->{Host} = $host;
+            }
         }

         ## Fix possible undefs
-- 
1.8.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant