2 * swift implementation of syscall API>
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 by 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>
23 #include "swift_raw.h"
26 * Create a new socket of type TYPE in domain DOMAIN, using
27 * protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
28 * Returns a file descriptor for the new socket, or -1 for errors.
30 * swift: protocol is IPPROTO_SWIFT.
32 int sw_socket (int __domain, int __type, int __protocol)
42 * Give the socket FD the local address ADDR (which is LEN bytes long).
44 * swift: ADDR is of type struct sockaddr_sw.
46 int sw_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
53 /* Put the local address of FD into *ADDR and its length in *LEN. */
54 int sw_getsockname (int __fd, __SOCKADDR_ARG __addr,
55 socklen_t *__restrict __len)
63 * Send N bytes of BUF on socket FD to peer at address ADDR (which is
64 * ADDR_LEN bytes long). Returns the number sent, or -1 for errors.
66 * This function is a cancellation point and therefore not marked with
69 ssize_t sw_sendto (int __fd, __const void *__buf, size_t __n,
70 int __flags, __CONST_SOCKADDR_ARG __addr,
81 * Read N bytes into BUF through socket FD.
82 * If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
83 * the sender, and store the actual size of the address in *ADDR_LEN.
84 * Returns the number of bytes read or -1 for errors.
86 * This function is a cancellation point and therefore not marked with
89 ssize_t sw_recvfrom (int __fd, void *__restrict __buf, size_t __n,
90 int __flags, __SOCKADDR_ARG __addr,
91 socklen_t *__restrict __addr_len)
101 * Send a message described MESSAGE on socket FD.
102 * Returns the number of bytes sent, or -1 for errors.
104 * This function is a cancellation point and therefore not marked with
107 ssize_t sw_sendmsg (int __fd, __const struct msghdr *__message,
118 * Receive a message as described by MESSAGE from socket FD.
119 * Returns the number of bytes read or -1 for errors.
121 * This function is a cancellation point and therefore not marked with
124 ssize_t sw_recvmsg (int __fd, struct msghdr *__message, int __flags)
134 * Put the current value for socket FD's option OPTNAME at protocol level
135 * LEVEL into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the
136 * value's actual length. Returns 0 on success, -1 for errors.
138 int sw_getsockopt (int __fd, int __level, int __optname,
139 void *__restrict __optval,
140 socklen_t *__restrict __optlen)
142 /* Call classical interface of getsockopt(2). */
143 return getsockopt(__fd, __level, __optname, __optval, __optlen);
147 * Set socket FD's option OPTNAME at protocol level LEVEL
148 * to *OPTVAL (which is OPTLEN bytes long).
149 * Returns 0 on success, -1 for errors.
152 int sw_setsockopt (int __fd, int __level, int __optname,
153 __const void *__optval, socklen_t __optlen)
155 /* Call classical interface of setsockopt(2). */
156 return setsockopt(__fd, __level, __optname, __optval, __optlen);
160 * Shut down all or part of the connection open on socket FD.
161 * HOW determines what to shut down:
162 * SHUT_RD = No more receptions;
163 * SHUT_WR = No more transmissions;
164 * SHUT_RDWR = No more receptions or transmissions.
165 * Returns 0 on success, -1 for errors.
167 int sw_shutdown (int __fd, int __how)
169 /* Call classical interface of shutdown(2). */
170 return shutdown(__fd, __how);