]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/rebuildhosts.c
1 /* IPCop helper program - rebuildhosts
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Alan Hourihane, 2003
9 * $Id: rebuildhosts.c,v 1.3.2.6 2005/07/11 10:56:47 franck78 Exp $
13 #include "libsmooth.h"
18 #include <sys/types.h>
26 struct keyvalue
*kv
= NULL
;
28 void exithandler(void)
38 int main(int argc
, char *argv
[])
40 char hostname
[STRING_SIZE
] = "";
41 char domainname
[STRING_SIZE
] = "";
42 char gateway
[STRING_SIZE
] = "";
43 char address
[STRING_SIZE
] = "";
51 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings")))
53 fprintf(stderr
, "Couldn't read ethernet settings\n");
56 findkey(kv
, "GREEN_ADDRESS", address
);
60 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
62 fprintf(stderr
, "Couldn't read main settings\n");
65 strcpy(hostname
, SNAME
);
66 findkey(kv
, "HOSTNAME", hostname
);
67 findkey(kv
, "DOMAINNAME", domainname
);
71 if ((gw
= fopen(CONFIG_ROOT
"/red/remote-ipaddress", "r"))) {
72 if (fgets(gateway
, STRING_SIZE
, gw
) == NULL
) {
73 fprintf(stderr
, "Couldn't read remote-ipaddress\n");
77 fprintf(stderr
, "Couldn't open remote-ipaddress file\n");
80 if (!(hosts
= fopen("/etc/hosts", "w")))
82 fprintf(stderr
, "Couldn't open /etc/hosts file\n");
85 fprintf(hosts
, "127.0.0.1\tlocalhost\n");
86 if (strlen(domainname
))
87 fprintf(hosts
, "%s\t%s.%s\t%s\n",address
,hostname
,domainname
,hostname
);
89 fprintf(hosts
, "%s\t%s\n",address
,hostname
);
91 if (strlen(gateway
) > 0)
92 fprintf(hosts
, "%s\tgateway\n", gateway
);