Migration support
[handlervirt.git] / experiment4.c
blobafa6da2fe111ccbcb7fbc4af20f1195418643b8f
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/file.h>
12 int main() {
13 FILE *fd;
14 char mac[13];
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) {
22 mac[12] = '\0';
23 counter = strtoul(mac, NULL, 16);
24 counter++;
26 snprintf(mac, 13, "%012lX\n", counter);
27 rewind(fd);
28 fwrite(mac, 12, sizeof(char), fd);
29 fclose(fd);
31 char pretty[18];
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)
45 // fclose(fd);
48 flock(locker, LOCK_UN);
49 close(locker);
51 return 0;