summaryrefslogtreecommitdiff
path: root/cesar/host/src/socketcalls.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/host/src/socketcalls.c')
-rw-r--r--cesar/host/src/socketcalls.c237
1 files changed, 237 insertions, 0 deletions
diff --git a/cesar/host/src/socketcalls.c b/cesar/host/src/socketcalls.c
new file mode 100644
index 0000000000..dce3f163b4
--- /dev/null
+++ b/cesar/host/src/socketcalls.c
@@ -0,0 +1,237 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+/**
+ * \file socket.c
+ * \brief The socket layer for ecos synthetic
+ * \ingroup host
+ *
+ * This file provide the socket functions for eCos synthetic
+ *
+ * \todo
+ */
+
+#include "common/std.h"
+#ifndef UNIT_TEST
+#include "host/syscall.h"
+#endif
+#include "host/socket.h"
+#include <errno.h>
+
+#ifdef UNIT_TEST
+int socketcall(int call, unsigned long *args)
+{
+ return 0;
+}
+#else /* UNIT_TEST */
+extern int socketcall(int call, unsigned long *args);
+#endif /* UNIT_TEST */
+
+/* Various socketcall numbers */
+#define SYS_SOCKET 1
+#define SYS_BIND 2
+#define SYS_CONNECT 3
+#define SYS_LISTEN 4
+#define SYS_ACCEPT 5
+#define SYS_GETSOCKNAME 6
+#define SYS_GETPEERNAME 7
+#define SYS_SOCKETPAIR 8
+#define SYS_SEND 9
+#define SYS_RECV 10
+#define SYS_SENDTO 11
+#define SYS_RECVFROM 12
+#define SYS_SHUTDOWN 13
+#define SYS_SETSOCKOPT 14
+#define SYS_GETSOCKOPT 15
+#define SYS_SENDMSG 16
+#define SYS_RECVMSG 17
+
+int host_accept(int s, const struct host_sockaddr *addr, unsigned int * addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = s;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) addrlen;
+ return socketcall(SYS_ACCEPT, args);
+}
+
+int host_bind(int sockfd, const struct host_sockaddr *myaddr, unsigned int addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) myaddr;
+ args[2] = addrlen;
+ return socketcall(SYS_BIND, args);
+}
+
+int host_connect(int sockfd, const struct host_sockaddr *saddr, unsigned int addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) saddr;
+ args[2] = addrlen;
+ return socketcall(SYS_CONNECT, args);
+}
+
+int host_getpeername(int sockfd, const struct host_sockaddr *addr, unsigned int * paddrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) paddrlen;
+ return socketcall(SYS_GETPEERNAME, args);
+}
+
+int host_getsockname(int sockfd, const struct host_sockaddr *addr, unsigned int * paddrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) paddrlen;
+ return socketcall(SYS_GETSOCKNAME, args);
+}
+
+int host_getsockopt(int fd, int level, int optname, void * optval,
+ unsigned int * optlen)
+{
+ unsigned long args[5];
+
+ args[0] = fd;
+ args[1] = level;
+ args[2] = optname;
+ args[3] = (unsigned long) optval;
+ args[4] = (unsigned long) optlen;
+ return (socketcall(SYS_GETSOCKOPT, args));
+}
+
+int host_listen(int sockfd, int backlog)
+{
+ unsigned long args[2];
+
+ args[0] = sockfd;
+ args[1] = backlog;
+ return socketcall(SYS_LISTEN, args);
+}
+
+ssize_t host_recv(int sockfd, void * buffer, size_t len, int flags)
+{
+ unsigned long args[4];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) buffer;
+ args[2] = len;
+ args[3] = flags;
+ return (socketcall(SYS_RECV, args));
+}
+
+ssize_t host_recvfrom(int sockfd, void * buffer, size_t len, int flags,
+ const struct host_sockaddr *to, unsigned int * tolen)
+{
+ unsigned long args[6];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) buffer;
+ args[2] = len;
+ args[3] = flags;
+ args[4] = (unsigned long) to;
+ args[5] = (unsigned long) tolen;
+ return (socketcall(SYS_RECVFROM, args));
+}
+/*ssize_t host_recvmsg(int sockfd, struct msghdr *msg, int flags)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) msg;
+ args[2] = flags;
+ return (socketcall(SYS_RECVMSG, args));
+}*/
+
+ssize_t host_send(int sockfd, const void *buffer, size_t len, int flags)
+{
+ unsigned long args[4];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) buffer;
+ args[2] = len;
+ args[3] = flags;
+ return (socketcall(SYS_SEND, args));
+}
+
+/*ssize_t host_sendmsg(int sockfd, const struct msghdr *msg, int flags)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) msg;
+ args[2] = flags;
+ return (socketcall(SYS_SENDMSG, args));
+}*/
+
+ssize_t host_sendto(int sockfd, const void *buffer, size_t len, int flags,
+ const struct host_sockaddr *to, unsigned int tolen)
+{
+ unsigned long args[6];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) buffer;
+ args[2] = len;
+ args[3] = flags;
+ args[4] = (unsigned long) to;
+ args[5] = tolen;
+ return (socketcall(SYS_SENDTO, args));
+}
+
+int host_setsockopt(int fd, int level, int optname, const void *optval,
+ unsigned int optlen)
+{
+ unsigned long args[5];
+
+ args[0] = fd;
+ args[1] = level;
+ args[2] = optname;
+ args[3] = (unsigned long) optval;
+ args[4] = optlen;
+ return (socketcall(SYS_SETSOCKOPT, args));
+}
+
+int host_shutdown(int sockfd, int how)
+{
+ unsigned long args[2];
+
+ args[0] = sockfd;
+ args[1] = how;
+ return (socketcall(SYS_SHUTDOWN, args));
+}
+
+int host_socket(int family, int type, int protocol)
+{
+ unsigned long args[3];
+
+ args[0] = family;
+ args[1] = type;
+ args[2] = (unsigned long) protocol;
+ return socketcall(SYS_SOCKET, args);
+}
+
+int host_socketpair(int family, int type, int protocol, int sockvec[2])
+{
+ unsigned long args[4];
+
+ args[0] = family;
+ args[1] = type;
+ args[2] = protocol;
+ args[3] = (unsigned long) sockvec;
+ return socketcall(SYS_SOCKETPAIR, args);
+}
+