Client-side library for big sockets.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Mon, 30 Mar 2009 14:57:09 +0000 (14:57 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Mon, 30 Mar 2009 14:57:09 +0000 (14:57 +0000)
bmsocket/bmsocket.c [new file with mode: 0644]

diff --git a/bmsocket/bmsocket.c b/bmsocket/bmsocket.c
new file mode 100644 (file)
index 0000000..873f4fc
--- /dev/null
@@ -0,0 +1,38 @@
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "fdpass.h"
+
+#define VSYS_BMSOCKET "/vsys/fd_bmsocket.control"
+
+int socket(int domain, int type, int protocol)
+{
+    int sfd;
+    struct sockaddr_un addr;
+    int remotefd;
+
+    sfd = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (sfd == -1) {
+        perror("Could not create UNIX socket\n");
+        exit(-1);
+    }
+
+    memset(&addr, 0, sizeof(struct sockaddr_un));
+    /* Clear structure */
+    addr.sun_family = AF_UNIX;
+    strncpy(addr.sun_path, VSYS_BMSOCKET,
+            sizeof(addr.sun_path) - 1);
+
+    if (connect(sfd, (struct sockaddr *) &addr,
+                sizeof(struct sockaddr_un)) == -1) {
+        perror("Could not connect to Vsys control socket");
+        exit(-1);
+    }
+
+
+    remotefd = receive_fd(sfd);
+    return remotefd;
+}
+