[Frugalware-darcs] setup-current: netconfig: added /etc/networks
section to writeconfig()
VMiklos
vmiklos at frugalware.org
Thu Mar 16 18:10:10 CET 2006
[netconfig: added /etc/networks section to writeconfig()
VMiklos <vmiklos at frugalware.org>**20060119114947] {
hunk ./src/config/netconfig.c 93
+/*
+ * based on pacman's config parser, which is
+ * Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+ */
hunk ./src/config/netconfig.c 554
-void writeconfig(char *host, char *nettype, char *dhcphost, char *ipaddr, char *netmask, char *gateway, char *dns)
+/* Copyright 1994 by David Niemi. Written in about 30 minutes on 13 Aug.
+ * The author places no restrictions on the use of this program, provided
+ * that this copyright is preserved in any derived source code.
+ */
+char *netaddr(char *ip, char *nm)
+{
+ unsigned long netmask, ipaddr, netaddr;
+ int in[4], i;
+ unsigned char na[4];
+
+ // sanility checks for netmask
+ if (4 != sscanf(ip,"%d.%d.%d.%d", &in[0],&in[1],&in[2],&in[3]))
+ // invalid netmask
+ return(NULL);
+ for (i=0; i<4; ++i)
+ if (in[i]<0 || in[i]>255)
+ // invalid octet in netmask
+ return(NULL);
+ netmask = in[3] + 256 * (in[2] + 256 * (in[1] + 256 * in[0]));
+
+ // sanility check for ip
+ if (4 != sscanf(nm,"%d.%d.%d.%d", &in[0],&in[1],&in[2],&in[3]))
+ // invalid ip
+ return(NULL);
+ for (i=0; i<4; ++i)
+ if (in[i]<0 || in[i]>255)
+ // invalied octet in ip
+ return(NULL);
+
+ ipaddr = in[3] + 256 * (in[2] + 256 * (in[1] + 256 * in[0]));
+
+ netaddr = ipaddr & netmask;
+ na[0] = netaddr / 256 / 256 / 256;
+ na[1] = (netaddr / 256 / 256) % 256;
+ na[2] = (netaddr / 256) % 256;
+ na[3] = netaddr % 256;
+
+ return(g_strdup_printf("%d.%d.%d.%d", na[0], na[1], na[2], na[3]));
+}
+
+int writeconfig(char *host, char *nettype, char *dhcphost, char *ipaddr, char *netmask, char *gateway, char *dns)
hunk ./src/config/netconfig.c 598
+ char *network=NULL;
hunk ./src/config/netconfig.c 603
- return;
+ return(1);
hunk ./src/config/netconfig.c 628
+ if(strcmp(nettype, "static"))
+ {
+ fakeip=1;
+ ipaddr=strdup("127.0.0.1");
+ network=strdup("127.0.0.0");
+ }
+ else
+ network=netaddr(ipaddr, netmask);
+
hunk ./src/config/netconfig.c 639
- return;
+ return(1);
hunk ./src/config/netconfig.c 650
- if(strcmp(nettype, "static"))
- {
- fakeip=1;
- ipaddr=strdup("127.0.0.1");
- }
hunk ./src/config/netconfig.c 654
- // FIXME: /etc/networks
+ fp = fopen("/etc/networks", "w");
+ if(fp==NULL)
+ return(1);
+ fprintf(fp, "#\n"
+ "# networks This file describes a number of netname-to-address\n"
+ "# mappings for the TCP/IP subsystem. It is mostly\n"
+ "# used at boot time, when no name servers are running.\n"
+ "#\n\n"
+ "loopback 127.0.0.0\n");
+ fprintf(fp, "localnet %s\n", network);
+ fprintf(fp, "\n# End of networks.\n");
+ fclose(fp);
hunk ./src/config/netconfig.c 672
+ free(network);
+ return(0);
hunk ./src/config/netconfig.c 694
- // FIXME: if !lo and wireless, then ask for essid and key
+ // TODO: if !lo and wireless, then ask for essid and key
}
More information about the Frugalware-darcs
mailing list