Fix dns dhcp client helper script.
[ipfire-2.x.git] / src / initscripts / helper / getdnsfromdhcpc.pl
CommitLineData
069680ac 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
069680ac
MT
21
22use strict;
23require '/var/ipfire/general-functions.pl';
24
25my $count = $ARGV[0];
26my ($dhcp, $dns, @alldns, %dhcpc);
27
28if ($count eq "" || $count < 1) {
29 die "Bad DNS number given"; }
30
31if (open(FILE, "${General::swroot}/red/iface")) {
32 my $iface = <FILE>;
33 close FILE;
34 chomp ($iface);
35 if (!&General::readhash("${General::swroot}/dhcpc/dhcpcd-$iface.info", \%dhcpc)) {
36 die "Could not open dhcpc info file";
37 }
38} else {
39 die "Could not open interface file";
40}
41
42
26617b09 43$dns = $dhcpc{'domain_name_servers'};
069680ac 44
d25238aa 45@alldns = split(' ', $dns);
069680ac
MT
46
47print "$alldns[$count - 1]\n";