From ab8beaf15d10ebfdc3b25686d0ab06b66b7f0a60 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Thu, 13 Nov 2014 07:08:15 -0500 Subject: [PATCH] change detect_dhcpd tool to support Ubuntu --- xCAT-server/share/xcat/tools/detect_dhcpd | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/tools/detect_dhcpd b/xCAT-server/share/xcat/tools/detect_dhcpd index 78d33e19f..5afad8ad9 100755 --- a/xCAT-server/share/xcat/tools/detect_dhcpd +++ b/xCAT-server/share/xcat/tools/detect_dhcpd @@ -27,6 +27,11 @@ if (!GetOptions( if ($::HELP) { print $::USAGE; exit 0; } +unless (-x "/usr/sbin/tcpdump") { + print "Error: Please install tcpdump before the detecting.\n"; + exit 1; +} + my $nic; if ($::IF) { $nic = $::IF; @@ -69,8 +74,12 @@ if (-f "/etc/redhat-release") { $os = "rh"; } elsif (-f "/etc/SuSE-release") { $os = "sles"; +} elsif (-f "/etc/lsb-release") { + $os = "ubuntu"; +} elsif (-f "/etc/debian_version") { + $os = "debian"; } else { - print "Only support the redhat and sles OS.\n"; + print "Only support the redhat, sles, ubuntu and debian OS.\n"; exit 1; } # fork a process to capture the packet by tcpdump @@ -97,6 +106,15 @@ my $sock = IO::Socket::INET->new(Proto => 'udp', LocalPort => '68', PeerAddr => inet_ntoa(INADDR_BROADCAST)); +# try the any port if localport 68 has been used +unless ($sock) { + $sock = IO::Socket::INET->new(Proto => 'udp', + Broadcast => 1, + PeerPort => '67', + LocalAddr => $IP, + PeerAddr => inet_ntoa(INADDR_BROADCAST)); +} + unless ($sock) { print "Create socket error: $@\n"; kill_child();