[1728] in Moira

home help back first fref pref prev next nref lref last post

dhcp.pc patch

daemon@ATHENA.MIT.EDU (Nick Martin)
Thu Jan 4 05:13:04 2001

Date: Thu, 4 Jan 2001 05:13:00 -0500
From: Nick Martin <nim@MIT.EDU>
To: moiradev@MIT.EDU
Message-Id: <20010104051259.K17384@piku.mit.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii

Here is a patch to:
1) colonify hardware addresses
2) not add a logserver line if there is no log server specified in
moira.

It seems to generate a dhcpd.conf file that parses. No other testing
has been done.

Index: dhcp.pc
===================================================================
RCS file: /mit/moiradev/repository/moira/gen/dhcp.pc,v
retrieving revision 1.2
diff -u -r1.2 dhcp.pc
--- dhcp.pc	2000/08/17 05:52:49	1.2
+++ dhcp.pc	2001/01/04 09:52:45
@@ -1,6 +1,6 @@
 /* $Id: dhcp.pc,v 1.2 2000/08/17 05:52:49 zacheiss Exp $
  *
- * This generates the dhcpd.conf.pring and associated files.
+ * This generates the dhcpd.conf.print and associated files.
  *
  * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
  * For copying and distribution information, please see the file
@@ -20,6 +20,8 @@
 
 #include "util.h"
 
+#define MACHINE_CHWADDR_SIZE 18
+
 EXEC SQL INCLUDE sqlca;
 
 RCSID("$Header: /mit/moiradev/repository/moira/gen/dhcp.pc,v 1.2 2000/08/17 05:52:49 zacheiss Exp $");
@@ -27,12 +29,15 @@
 char *whoami = "dhcp.gen";
 char *db = "moira/moira";
 
+void hwcolonify(char* from, char* to);
+
 void sqlerr(void);
 
 int main(int argc, char **argv)
 {
   EXEC SQL BEGIN DECLARE SECTION;
   char name[MACHINE_NAME_SIZE], hwaddr[MACHINE_HWADDR_SIZE];
+  char chwaddr[MACHINE_CHWADDR_SIZE];
   char ohwaddr[MACHINE_HWADDR_SIZE], hwtype[PRINTERS_HWTYPE_SIZE];
   char addr[MACHINE_ADDRESS_SIZE], location[PRINTERS_LOCATION_SIZE];
   char contact[PRINTERS_CONTACT_SIZE], logaddr[MACHINE_ADDRESS_SIZE];
@@ -110,6 +115,8 @@
 	}
       strcpy(ohwaddr, hwaddr);
 
+      hwcolonify(hwaddr, chwaddr); 
+
       strtrim(name);
       strtrim(addr);
       strtrim(logaddr);
@@ -129,9 +136,12 @@
 	continue;
 
       fprintf(out, "# %s: %s\n# contact: %s\nhost %s {\n\t"
-	      "hardware ethernet %s;\n\tfixed-address %s;\n"
-	      "\toption log-servers %s;\n",
-	      shortname, location, contact, name, hwaddr, addr, logaddr);
+	      "hardware ethernet %s;\n\tfixed-address %s;\n",
+	      shortname, location, contact, name, chwaddr, addr);
+      
+      if (strlen(logaddr) != 0)
+	      fprintf(out, "\toption log-servers %s;\n", logaddr);
+	      
       if (!strncmp(hwtype, "HP", 2))
 	fprintf(out, "\toption option-144 \"/hp/%s\";\n", shortname);
       fprintf(out, "}\n\n");
@@ -217,6 +227,23 @@
   tarfile_close(tf);
 
   exit(MR_SUCCESS);
+}
+
+void hwcolonify(char* from, char* to)
+{
+	int f = 0, t = 0;
+	int mod = 2;
+
+	for (f = 0 ; f < MACHINE_HWADDR_SIZE - 1 ; )
+	{
+		to[t++] = from[f++];
+		if (f % mod == 0)
+			to[t++] = ':';
+	}
+	
+	if (f % mod == 0)
+		t--;
+	to[t] = '\0';
 }
 
 void sqlerr(void)



-- 
Nick Martin, nim@mit.edu, http://www.nimlabs.com

Absolute faith corrupts as absolutely as absolute power.
 -- Eric Hoffer


home help back first fref pref prev next nref lref last post