summaryrefslogtreecommitdiff
path: root/libc/inet
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet')
-rw-r--r--libc/inet/Makefile11
-rw-r--r--libc/inet/socketcalls.c232
2 files changed, 242 insertions, 1 deletions
diff --git a/libc/inet/Makefile b/libc/inet/Makefile
index 95432060e..45db1c13f 100644
--- a/libc/inet/Makefile
+++ b/libc/inet/Makefile
@@ -35,7 +35,12 @@ MOBJ2=encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \
formquery.o dnslookup.o resolveaddress.o resolvemailbox.o \
opennameservers.o closenameservers.o resolvename.o gethostbyname.o\
gethostbyaddr.o
-OBJS=$(MOBJ) $(MOBJ2)
+
+MSRC3=socketcalls.c
+MOBJ3= accept.o bind.o connect.o getpeername.o getsockname.o getsockopt.o \
+ listen.o recv.o recvfrom.o recvmsg.o send.o sendmsg.o sendto.o \
+ setsockopt.o shutdown.o socket.o socketpair.o
+OBJS=$(MOBJ) $(MOBJ2) $(MOBJ3)
all: $(OBJS) $(LIBC)
@@ -53,6 +58,10 @@ $(MOBJ2): $(MSRC2)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
+$(MOBJ3): $(MSRC2)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
$(OBJS): Makefile
clean: subdirs_clean
diff --git a/libc/inet/socketcalls.c b/libc/inet/socketcalls.c
new file mode 100644
index 000000000..162e0770b
--- /dev/null
+++ b/libc/inet/socketcalls.c
@@ -0,0 +1,232 @@
+#include <errno.h>
+#include <syscall.h>
+#include <sys/socket.h>
+#include <sys/socketcall.h>
+
+extern int socketcall(int call, unsigned long *args);
+
+#ifdef L_accept
+int accept(int s, struct sockaddr *addr, socklen_t * addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = s;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) addrlen;
+ return socketcall(SYS_ACCEPT, args);
+}
+#endif
+
+#ifdef L_bind
+int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) myaddr;
+ args[2] = addrlen;
+ return socketcall(SYS_BIND, args);
+}
+#endif
+
+#ifdef L_connect
+int connect(int sockfd, const struct sockaddr *saddr, socklen_t addrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) saddr;
+ args[2] = addrlen;
+ return socketcall(SYS_CONNECT, args);
+}
+#endif
+
+#ifdef L_getpeername
+int getpeername(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) paddrlen;
+ return socketcall(SYS_GETPEERNAME, args);
+}
+#endif
+
+#ifdef L_getsockname
+int getsockname(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
+{
+ unsigned long args[3];
+
+ args[0] = sockfd;
+ args[1] = (unsigned long) addr;
+ args[2] = (unsigned long) paddrlen;
+ return socketcall(SYS_GETSOCKNAME, args);
+}
+#endif
+
+#ifdef L_getsockopt
+int getsockopt(int fd, int level, int optname, __ptr_t optval,
+ socklen_t * 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));
+}
+#endif
+
+#ifdef L_listen
+int listen(int sockfd, unsigned int backlog)
+{
+ unsigned long args[2];
+
+ args[0] = sockfd;
+ args[1] = backlog;
+ return socketcall(SYS_LISTEN, args);
+}
+#endif
+
+#ifdef L_recv
+/* recv, recvfrom added by bir7@leland.stanford.edu */
+int recv(int sockfd, __ptr_t 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));
+}
+#endif
+
+#ifdef L_recvfrom
+/* recv, recvfrom added by bir7@leland.stanford.edu */
+int recvfrom(int sockfd, __ptr_t buffer, size_t len, int flags,
+ struct sockaddr *to, socklen_t * 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));
+}
+#endif
+
+#ifdef L_recvmsg
+int 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));
+}
+#endif
+
+#ifdef L_send
+/* send, sendto added by bir7@leland.stanford.edu */
+int 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));
+}
+#endif
+
+#ifdef L_sendmsg
+int 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));
+}
+#endif
+
+#ifdef L_sendto
+/* send, sendto added by bir7@leland.stanford.edu */
+int sendto(int sockfd, const void *buffer, size_t len, int flags,
+ const struct sockaddr *to, socklen_t 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));
+}
+#endif
+
+#ifdef L_setsockopt
+/* [sg]etsockoptions by bir7@leland.stanford.edu */
+int setsockopt(int fd, int level, int optname, const void *optval,
+ socklen_t 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));
+}
+#endif
+
+#ifdef L_shutdown
+/* shutdown by bir7@leland.stanford.edu */
+int shutdown(int sockfd, int how)
+{
+ unsigned long args[2];
+
+ args[0] = sockfd;
+ args[1] = how;
+ return (socketcall(SYS_SHUTDOWN, args));
+}
+#endif
+
+#ifdef L_socket
+int 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);
+}
+#endif
+
+#ifdef L_socketpair
+int 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);
+}
+#endif
+