2 * swift interface for raw sockets
4 * Simulates the classic socket syscalls (socket, bind, send, recv).
5 * Implementation uses raw sockets (AF_INET, SOCK_RAW).
7 * Subsequently, implementation is to be ported into kernel space and
8 * the interface is going to be offered by the Linux syscall API.
10 * Heavily inspired from GLIBC's <sys/socket.h>
11 * (/usr/include/sys/socket.h).
13 * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
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.
32 * swift: protocol is IPPROTO_SWIFT.
34 extern int sw_socket (int __domain, int __type, int __protocol) __THROW;
37 * Give the socket FD the local address ADDR (which is LEN bytes long).
39 * swift: ADDR is of type struct sockaddr_sw.
41 extern int sw_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
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;
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.
52 * This function is a cancellation point and therefore not marked with
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);
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.
65 * This function is a cancellation point and therefore not marked with
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);
73 * Send a message described MESSAGE on socket FD.
74 * Returns the number of bytes sent, or -1 for errors.
76 * This function is a cancellation point and therefore not marked with
79 extern ssize_t sw_sendmsg (int __fd, __const struct msghdr *__message,
83 * Receive a message as described by MESSAGE from socket FD.
84 * Returns the number of bytes read or -1 for errors.
86 * This function is a cancellation point and therefore not marked with
89 extern ssize_t sw_recvmsg (int __fd, struct msghdr *__message, int __flags);
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.
96 extern int sw_getsockopt (int __fd, int __level, int __optname,
97 void *__restrict __optval,
98 socklen_t *__restrict __optlen) __THROW;
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.
106 extern int sw_setsockopt (int __fd, int __level, int __optname,
107 __const void *__optval, socklen_t __optlen) __THROW;
110 * Shut down all or part of the connection open on socket FD.
111 * HOW determines what to shut down:
112 * SHUT_RD = No more receptions;
113 * SHUT_WR = No more transmissions;
114 * SHUT_RDWR = No more receptions or transmissions.
115 * Returns 0 on success, -1 for errors.
117 extern int sw_shutdown (int __fd, int __how) __THROW;
123 #endif /* SWIFT_RAW_ */