15 unsigned long int counter
= 0;
17 int locker
= open("/mnt/netapp/maccounter", O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
);
18 flock(locker
, LOCK_EX
);
20 if ((fd
= fdopen(locker
, "w+")) != NULL
) {
21 if (fread(mac
, 12, sizeof(char), fd
) == 1) {
23 counter
= strtoul(mac
, NULL
, 16);
26 snprintf(mac
, 13, "%012lX\n", counter
);
28 fwrite(mac
, 12, sizeof(char), fd
);
32 pretty
[2] = ':'; pretty
[5] = ':'; pretty
[8] = ':'; pretty
[11] = ':'; pretty
[14] = ':'; pretty
[17] = '\0';
33 strncpy(&pretty
[0], &mac
[0], 2);
34 strncpy(&pretty
[3], &mac
[2], 2);
35 strncpy(&pretty
[6], &mac
[4], 2);
36 strncpy(&pretty
[9], &mac
[6], 2);
37 strncpy(&pretty
[12], &mac
[8], 2);
38 strncpy(&pretty
[15], &mac
[10], 2);
40 // dhcp-host=00:1E:C9:B3:B3:85,xen001.xen,172.16.103.1,24h
41 printf("dhcp-host=%s,%s.xen,...,24h\n", pretty
, "test");
43 // fd = fopen("/mnt/netapp/dnsmasq.conf", "a");
44 // fprintf(fd, "dhcp-host=%s,%s,", 10, sizeof(char)
48 flock(locker
, LOCK_UN
);