This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH 036/114] Add implementation of socket family functions for Phoenix.
- From: Jakub Sejdak <jakub dot sejdak at phoesys dot com>
- To: newlib at sourceware dot org
- Cc: Kuba Sejdak <jakub dot sejdak at phoesys dot com>
- Date: Mon, 11 Apr 2016 12:20:54 +0200
- Subject: [PATCH 036/114] Add implementation of socket family functions for Phoenix.
- Authentication-results: sourceware.org; auth=none
- References: <1460370132-4880-1-git-send-email-jakub dot sejdak at phoesys dot com>
From: Kuba Sejdak <jakub.sejdak@phoesys.com>
---
newlib/libc/sys/phoenix/socket.c | 131 ++++++++++++++++++++++++++++++++++++++
newlib/libc/sys/phoenix/sockopt.c | 69 ++++++++++++++++++++
2 files changed, 200 insertions(+)
create mode 100644 newlib/libc/sys/phoenix/socket.c
create mode 100644 newlib/libc/sys/phoenix/sockopt.c
diff --git a/newlib/libc/sys/phoenix/socket.c b/newlib/libc/sys/phoenix/socket.c
new file mode 100644
index 0000000..f31e072
--- /dev/null
+++ b/newlib/libc/sys/phoenix/socket.c
@@ -0,0 +1,131 @@
+/* Copyright (C) 2012-2016 Phoenix Systems (http://www.phoesys.com/).
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "syscall.h"
+
+#include <errno.h>
+#include <sys/socket.h>
+
+int socket(int domain, int type, int protocol)
+{
+ int ret = syscall3(int, SYS_SOCKET, domain, type, protocol);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+ int ret = syscall3(int, SYS_BIND, sockfd, addr, addrlen);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int listen(int sockfd, int backlog)
+{
+ int ret = syscall2(int, SYS_LISTEN, sockfd, backlog);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+ int ret = syscall3(int, SYS_ACCEPT, sockfd, addr, addrlen);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+ int ret = syscall3(int, SYS_CONNECT, sockfd, addr, addrlen);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+ struct sendto_args args = { sockfd, buf, len, flags, dest_addr, addrlen };
+
+ int ret = syscall1(int, SYS_SENDTO, &args);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int send(int sockfd, const void *buf, size_t len, int flags)
+{
+ return sendto(sockfd, buf, len, flags, NULL, 0);
+}
+
+int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
+{
+ struct recvfrom_args args = { sockfd, buf, len, flags, src_addr, addrlen };
+
+ int ret = syscall1(int, SYS_RECVFROM, &args);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int recv(int sockfd, void *buf, size_t len, int flags)
+{
+ return recvfrom(sockfd, buf, len, flags, NULL, NULL);
+}
+
+int shutdown(int sockfd, int how)
+{
+ /* TODO: implement. */
+ errno = ENOSYS;
+ return -1;
+}
+
+int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+ int ret = syscall3(int, SYS_GETPEERNAME, sockfd, addr, addrlen);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
diff --git a/newlib/libc/sys/phoenix/sockopt.c b/newlib/libc/sys/phoenix/sockopt.c
new file mode 100644
index 0000000..c3ec598
--- /dev/null
+++ b/newlib/libc/sys/phoenix/sockopt.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2012-2016 Phoenix Systems.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include "syscall.h"
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+ int ret = syscall3(int, SYS_GETSOCKNAME, sockfd, addr, addrlen);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
+
+int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
+{
+ struct setsockopt_args args;
+ args.level = level;
+ args.optname = optname;
+ args.optval = optval;
+ args.optlen = *optlen;
+
+ int ret = ioctl(sockfd, IOC_GETSOCKOPT, &args);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ *optlen = args.optlen;
+ return ret;
+}
+
+int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
+{
+ struct setsockopt_args args;
+ args.level = level;
+ args.optname = optname;
+ args.optval = (void *) optval;
+ args.optlen = optlen;
+
+ int ret = ioctl(sockfd, IOC_SETSOCKOPT, &args);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+
+ return ret;
+}
--
2.5.0