swifty: Add swift_types.h.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 14 May 2011 15:11:55 +0000 (18:11 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 14 May 2011 15:11:59 +0000 (18:11 +0300)
Defines struct sockaddr_sw.

src/swift_types.h [new file with mode: 0644]

diff --git a/src/swift_types.h b/src/swift_types.h
new file mode 100644 (file)
index 0000000..3decae6
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * swift interface for raw sockets
+ *
+ * Simulates the classic socket syscalls (socket, bind, send, recv).
+ * Implementation uses raw sockets (AF_INET, SOCK_RAW).
+ *
+ * Subsequently, implementation is to be ported into kernel space and
+ * the interface is going to be offered by the Linux syscall API.
+ *
+ * 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+ */
+
+#ifndef SWIFT_RAW_
+#define SWIFT_RAW_     1
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * swift address
+ *   - IP address (Network Layer)
+ *   - file hash (or hash for part of a file)
+ *       - a seeder (sender) publishes that hash
+ *       - a leecher (receiver) requests that hash
+ *       - stands as port number both for sender and receiver
+ */
+
+#define SWIFT_HASH_SIZE                8
+
+struct sw_hash {
+       unsigned char h_array[SWIFT_HASH_SIZE];
+};
+
+struct sockaddr_sw {
+       __SOCKADDR_COMMON(sin_);
+       struct in_addr sin_addr;
+       struct sw_hash sw_hash;
+
+       /* Pad to size of `struct sockaddr'.  */
+       unsigned char sw_zero[sizeof(struct sockaddr) -
+               __SOCKADDR_COMMON_SIZE -
+               sizeof(sw_hash) -
+               sizeof(struct in_addr)];
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SWIFT_RAW_ */