Script for a slice to serve DNS
Sapan Bhatia [Mon, 9 Apr 2012 18:09:25 +0000 (14:09 -0400)]
Makefile
fd_bind53.c [new file with mode: 0644]

index 40a1cb3..e455aae 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
 CFLAGS=-g -O2
 
-all: dcookie fd_bmsocket fd_udpsocket fd_fusemount fd_tuntap fd_tos fd_packetseer fd_netlink
+all: dcookie fd_bmsocket fd_udpsocket fd_fusemount fd_tuntap fd_tos fd_packetseer fd_netlink fd_bind53
 
 fd_tuntap: fd_tuntap.c
        gcc fd_tuntap.c -o exec/fd_tuntap
@@ -15,6 +15,9 @@ dcookie: dcookie.c
 fdpass.o: fdpass.c
        gcc -c fdpass.c -o fdpass.o
 
+fd_bind53: fd_bind53.c fdpass.o
+       gcc fd_bind53.c fdpass.o -o exec/fd_bind53
+
 fd_bmsocket: fd_bmsocket.c fdpass.o
        gcc fd_bmsocket.c fdpass.o -o exec/fd_bmsocket
 
diff --git a/fd_bind53.c b/fd_bind53.c
new file mode 100644 (file)
index 0000000..e5582bb
--- /dev/null
@@ -0,0 +1,39 @@
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include "fdpass.h"
+
+int 
+main(int argc, char *argv[]) 
+{
+    int control_channel_fd, magic_socket;
+    struct sockaddr_in my_addr;
+    
+    if (argc < 3) {
+        printf("This script is called by vsys.\n");
+        exit(1);
+    }
+
+    sscanf(argv[2],"%d", &control_channel_fd);
+
+    magic_socket = socket(AF_INET, SOCK_DGRAM, 0);
+
+    if (magic_socket == -1) {
+      fprintf(stderr, "Error creating socket: %d\n", errno);
+      exit(1);
+    }
+    
+    memset((void *) &my_addr, 0, sizeof(my_addr));
+    my_addr.sin_family = AF_INET;
+    my_addr.sin_port = htons(53);
+    my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    if (bind(magic_socket, (struct sockaddr *) &my_addr, sizeof(my_addr))==-1) {
+        printf("Could not bind to port 53");
+        exit(1);
+    }
+
+    send_fd(control_channel_fd, magic_socket);
+}