a8b69f907e0d8bdd5030ab6123c379c925c3bfc8
[swifty.git] / src / swift_types.h
1 /*
2  * swift interface for raw sockets
3  *
4  * Simulates the classic socket syscalls (socket, bind, send, recv).
5  * Implementation uses raw sockets (AF_INET, SOCK_RAW).
6  *
7  * Subsequently, implementation is to be ported into kernel space and
8  * the interface is going to be offered by the Linux syscall API.
9  *
10  * 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
11  */
12
13 #ifndef SWIFT_RAW_
14 #define SWIFT_RAW_      1
15
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /*
25  * swift address
26  *   - IP address (Network Layer)
27  *   - file hash (or hash for part of a file)
28  *       - a seeder (sender) publishes that hash
29  *       - a leecher (receiver) requests that hash
30  *       - stands as port number both for sender and receiver
31  */
32
33 #define SWIFT_HASH_SIZE         8
34
35 struct sw_hash {
36         unsigned char h_array[SWIFT_HASH_SIZE];
37 };
38
39 struct sockaddr_sw {
40         __SOCKADDR_COMMON(sin_);
41         struct in_addr sin_addr;
42         struct sw_hash sw_hash;
43
44         /* Pad to size of `struct sockaddr'.  */
45         unsigned char sw_zero[sizeof(struct sockaddr) -
46                 __SOCKADDR_COMMON_SIZE -
47                 sizeof(sw_hash) -
48                 sizeof(struct in_addr)];
49 };
50
51 /*
52  * swift header (work in progress)
53  */
54
55 struct swhdr {
56         /* file hash (to be seeded or requested) */
57         u_int8_t base_hash[SWIFT_HASH_SIZE];
58         /* TODO */
59 };
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 #endif /* SWIFT_RAW_ */