From 1cf86e0385b91f5cbe27a173dd2db36c0411156c Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Mon, 9 Apr 2012 14:09:25 -0400 Subject: [PATCH] Script for a slice to serve DNS --- Makefile | 5 ++++- fd_bind53.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 fd_bind53.c diff --git a/Makefile b/Makefile index 40a1cb3..e455aae 100644 --- 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 index 0000000..e5582bb --- /dev/null +++ b/fd_bind53.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#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); +} -- 2.43.0