raw: Add file declarations in source test files.
[swifty.git] / src / raw / swift_raw.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  * Heavily inspired from GLIBC's <sys/socket.h>
11  * (/usr/include/sys/socket.h).
12  *
13  * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
14  */
15
16 #ifndef SWIFT_RAW_
17 #define SWIFT_RAW_      1
18
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /*
28  * Create a new socket of type TYPE in domain DOMAIN, using
29  * protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
30  * Returns a file descriptor for the new socket, or -1 for errors.
31  *
32  * swift: protocol is IPPROTO_SWIFT.
33  */
34 extern int sw_socket (int __domain, int __type, int __protocol) __THROW;
35
36 /*
37  * Give the socket FD the local address ADDR (which is LEN bytes long).
38  *
39  * swift: ADDR is of type struct sockaddr_sw.
40  */
41 extern int sw_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
42      __THROW;
43
44 /* Put the local address of FD into *ADDR and its length in *LEN.  */
45 extern int sw_getsockname (int __fd, __SOCKADDR_ARG __addr,
46                         socklen_t *__restrict __len) __THROW;
47
48 /*
49  * Send N bytes of BUF on socket FD to peer at address ADDR (which is
50  * ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
51  *
52  * This function is a cancellation point and therefore not marked with
53  * __THROW.
54  */
55 extern ssize_t sw_sendto (int __fd, __const void *__buf, size_t __n,
56                        int __flags, __CONST_SOCKADDR_ARG __addr,
57                        socklen_t __addr_len);
58
59 /*
60  * Read N bytes into BUF through socket FD.
61  * If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
62  * the sender, and store the actual size of the address in *ADDR_LEN.
63  * Returns the number of bytes read or -1 for errors.
64  *
65  * This function is a cancellation point and therefore not marked with
66  * __THROW.
67  */
68 extern ssize_t sw_recvfrom (int __fd, void *__restrict __buf, size_t __n,
69                          int __flags, __SOCKADDR_ARG __addr,
70                          socklen_t *__restrict __addr_len);
71
72 /*
73  * Send a message described MESSAGE on socket FD.
74  * Returns the number of bytes sent, or -1 for errors.
75  *
76  * This function is a cancellation point and therefore not marked with
77  * __THROW.
78  */
79 extern ssize_t sw_sendmsg (int __fd, __const struct msghdr *__message,
80                         int __flags);
81
82 /*
83  * Receive a message as described by MESSAGE from socket FD.
84  * Returns the number of bytes read or -1 for errors.
85  *
86  * This function is a cancellation point and therefore not marked with
87  * __THROW.
88  */
89 extern ssize_t sw_recvmsg (int __fd, struct msghdr *__message, int __flags);
90
91 /*
92  * Put the current value for socket FD's option OPTNAME at protocol level
93  * LEVEL into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the
94  * value's actual length.  Returns 0 on success, -1 for errors.
95  */
96 extern int sw_getsockopt (int __fd, int __level, int __optname,
97                        void *__restrict __optval,
98                        socklen_t *__restrict __optlen) __THROW;
99
100 /*
101  * Set socket FD's option OPTNAME at protocol level LEVEL
102  * to *OPTVAL (which is OPTLEN bytes long).
103  * Returns 0 on success, -1 for errors.
104  */
105
106 extern int sw_setsockopt (int __fd, int __level, int __optname,
107                        __const void *__optval, socklen_t __optlen) __THROW;
108
109 /*
110  * Close file descriptor for socket FD.
111  * Returns 0 on success, -1 for errors.
112  */
113 extern int sw_close (int __fd);
114
115 #ifdef __cplusplus
116 }
117 #endif
118
119 #endif /* SWIFT_RAW_ */