From 79a49b20156aa01a43e35ba2c219bdddbf848381 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 19 Mar 2013 22:40:37 +0100 Subject: [PATCH] Add socket interface. --- libc/Makefile | 45 ++++++ libc/arpa/inet/inet_addr.cpp | 36 +++++ libc/arpa/inet/inet_ntoa.cpp | 36 +++++ libc/arpa/inet/inet_ntop.cpp | 37 +++++ libc/arpa/inet/inet_pton.cpp | 36 +++++ libc/decl/in_addr_t.h | 4 + libc/decl/in_port_t.h | 4 + libc/decl/sa_family_t.h | 4 + libc/decl/socklen_t.h | 4 + libc/include/arpa/inet.h | 42 ++++++ libc/include/netdb.h | 142 +++++++++++++++++++ libc/include/netinet/in.h | 126 +++++++++++++++++ libc/include/sys/socket.h | 158 ++++++++++++++++++++++ libc/include/sys/un.h | 42 ++++++ libc/netdb/endhostent.cpp | 34 +++++ libc/netdb/endnetent.cpp | 34 +++++ libc/netdb/endprotoent.cpp | 34 +++++ libc/netdb/endservent.cpp | 34 +++++ libc/netdb/freeaddrinfo.cpp | 34 +++++ libc/netdb/gai_strerror.cpp | 34 +++++ libc/netdb/getaddrinfo.cpp | 36 +++++ libc/netdb/gethostent.cpp | 34 +++++ libc/netdb/getnameinfo.cpp | 36 +++++ libc/netdb/getnetbyaddr.cpp | 34 +++++ libc/netdb/getnetbyname.cpp | 34 +++++ libc/netdb/getnetent.cpp | 34 +++++ libc/netdb/getprotobyname.cpp | 34 +++++ libc/netdb/getprotobynumber.cpp | 34 +++++ libc/netdb/getprotoent.cpp | 34 +++++ libc/netdb/getservbyname.cpp | 34 +++++ libc/netdb/getservbyport.cpp | 34 +++++ libc/netdb/getservent.cpp | 34 +++++ libc/netdb/sethostent.cpp | 34 +++++ libc/netdb/setnetent.cpp | 34 +++++ libc/netdb/setprotoent.cpp | 34 +++++ libc/netdb/setservent.cpp | 34 +++++ libc/sys/socket/accept.cpp | 31 +++++ libc/sys/socket/accept4.cpp | 44 ++++++ libc/sys/socket/bind.cpp | 33 +++++ libc/sys/socket/connect.cpp | 33 +++++ libc/sys/socket/getpeername.cpp | 34 +++++ libc/sys/socket/getsockname.cpp | 34 +++++ libc/sys/socket/getsockopt.cpp | 34 +++++ libc/sys/socket/listen.cpp | 33 +++++ libc/sys/socket/recv.cpp | 33 +++++ libc/sys/socket/recvfrom.cpp | 35 +++++ libc/sys/socket/recvmsg.cpp | 34 +++++ libc/sys/socket/send.cpp | 33 +++++ libc/sys/socket/sendmsg.cpp | 34 +++++ libc/sys/socket/sendto.cpp | 35 +++++ libc/sys/socket/setsockopt.cpp | 34 +++++ libc/sys/socket/shutdown.cpp | 34 +++++ libc/sys/socket/sockatmark.cpp | 34 +++++ libc/sys/socket/socket.cpp | 78 +++++++++++ libc/sys/socket/socketpair.cpp | 34 +++++ sortix/descriptor.cpp | 33 +++++ sortix/fs/user.cpp | 41 ++++++ sortix/include/sortix/__/types.h | 1 + sortix/include/sortix/kernel/descriptor.h | 7 + sortix/include/sortix/kernel/inode.h | 16 +++ sortix/include/sortix/kernel/vnode.h | 6 + sortix/include/sortix/socket.h | 45 ++++++ sortix/include/sortix/syscallnum.h | 8 +- sortix/include/sortix/x64/bits.h | 1 + sortix/include/sortix/x86/bits.h | 1 + sortix/inode.cpp | 35 +++++ sortix/io.cpp | 69 ++++++++++ sortix/vnode.cpp | 33 +++++ 68 files changed, 2457 insertions(+), 1 deletion(-) create mode 100644 libc/arpa/inet/inet_addr.cpp create mode 100644 libc/arpa/inet/inet_ntoa.cpp create mode 100644 libc/arpa/inet/inet_ntop.cpp create mode 100644 libc/arpa/inet/inet_pton.cpp create mode 100644 libc/decl/in_addr_t.h create mode 100644 libc/decl/in_port_t.h create mode 100644 libc/decl/sa_family_t.h create mode 100644 libc/decl/socklen_t.h create mode 100644 libc/include/arpa/inet.h create mode 100644 libc/include/netdb.h create mode 100644 libc/include/netinet/in.h create mode 100644 libc/include/sys/socket.h create mode 100644 libc/include/sys/un.h create mode 100644 libc/netdb/endhostent.cpp create mode 100644 libc/netdb/endnetent.cpp create mode 100644 libc/netdb/endprotoent.cpp create mode 100644 libc/netdb/endservent.cpp create mode 100644 libc/netdb/freeaddrinfo.cpp create mode 100644 libc/netdb/gai_strerror.cpp create mode 100644 libc/netdb/getaddrinfo.cpp create mode 100644 libc/netdb/gethostent.cpp create mode 100644 libc/netdb/getnameinfo.cpp create mode 100644 libc/netdb/getnetbyaddr.cpp create mode 100644 libc/netdb/getnetbyname.cpp create mode 100644 libc/netdb/getnetent.cpp create mode 100644 libc/netdb/getprotobyname.cpp create mode 100644 libc/netdb/getprotobynumber.cpp create mode 100644 libc/netdb/getprotoent.cpp create mode 100644 libc/netdb/getservbyname.cpp create mode 100644 libc/netdb/getservbyport.cpp create mode 100644 libc/netdb/getservent.cpp create mode 100644 libc/netdb/sethostent.cpp create mode 100644 libc/netdb/setnetent.cpp create mode 100644 libc/netdb/setprotoent.cpp create mode 100644 libc/netdb/setservent.cpp create mode 100644 libc/sys/socket/accept.cpp create mode 100644 libc/sys/socket/accept4.cpp create mode 100644 libc/sys/socket/bind.cpp create mode 100644 libc/sys/socket/connect.cpp create mode 100644 libc/sys/socket/getpeername.cpp create mode 100644 libc/sys/socket/getsockname.cpp create mode 100644 libc/sys/socket/getsockopt.cpp create mode 100644 libc/sys/socket/listen.cpp create mode 100644 libc/sys/socket/recv.cpp create mode 100644 libc/sys/socket/recvfrom.cpp create mode 100644 libc/sys/socket/recvmsg.cpp create mode 100644 libc/sys/socket/send.cpp create mode 100644 libc/sys/socket/sendmsg.cpp create mode 100644 libc/sys/socket/sendto.cpp create mode 100644 libc/sys/socket/setsockopt.cpp create mode 100644 libc/sys/socket/shutdown.cpp create mode 100644 libc/sys/socket/sockatmark.cpp create mode 100644 libc/sys/socket/socket.cpp create mode 100644 libc/sys/socket/socketpair.cpp create mode 100644 sortix/include/sortix/socket.h diff --git a/libc/Makefile b/libc/Makefile index 97b335d0..2444627c 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -135,6 +135,10 @@ wctype.o \ HOSTEDOBJS=\ access.o \ +arpa/inet/inet_addr.o \ +arpa/inet/inet_ntoa.o \ +arpa/inet/inet_ntop.o \ +arpa/inet/inet_pton.o \ calltrace.o \ canonicalize_file_name_at.o \ canonicalize_file_name.o \ @@ -220,6 +224,28 @@ memstat.o \ mkdirat.o \ mkdir.o \ mktemp.o \ +netdb/endhostent.o \ +netdb/endnetent.o \ +netdb/endprotoent.o \ +netdb/endservent.o \ +netdb/freeaddrinfo.o \ +netdb/gai_strerror.o \ +netdb/getaddrinfo.o \ +netdb/gethostent.o \ +netdb/getnameinfo.o \ +netdb/getnetbyaddr.o \ +netdb/getnetbyname.o \ +netdb/getnetent.o \ +netdb/getprotobyname.o \ +netdb/getprotobynumber.o \ +netdb/getprotoent.o \ +netdb/getservbyname.o \ +netdb/getservbyport.o \ +netdb/getservent.o \ +netdb/sethostent.o \ +netdb/setnetent.o \ +netdb/setprotoent.o \ +netdb/setservent.o \ on_exit.o \ openat.o \ open.o \ @@ -261,6 +287,25 @@ signal.o \ sleep.o \ stat.o \ stdio.o \ +sys/socket/accept4.o \ +sys/socket/accept.o \ +sys/socket/bind.o \ +sys/socket/connect.o \ +sys/socket/getpeername.o \ +sys/socket/getsockname.o \ +sys/socket/getsockopt.o \ +sys/socket/listen.o \ +sys/socket/recvfrom.o \ +sys/socket/recvmsg.o \ +sys/socket/recv.o \ +sys/socket/sendmsg.o \ +sys/socket/send.o \ +sys/socket/sendto.o \ +sys/socket/setsockopt.o \ +sys/socket/shutdown.o \ +sys/socket/sockatmark.o \ +sys/socket/socket.o \ +sys/socket/socketpair.o \ system.o \ tfork.o \ time.o \ diff --git a/libc/arpa/inet/inet_addr.cpp b/libc/arpa/inet/inet_addr.cpp new file mode 100644 index 00000000..765e468a --- /dev/null +++ b/libc/arpa/inet/inet_addr.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + arpa/inet/inet_addr.cpp + Internet address manipulation routines. + +*******************************************************************************/ + +#include +#include +#include + +#include +#include + +extern "C" in_addr_t inet_addr(const char*) +{ + fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__); + abort(); +} diff --git a/libc/arpa/inet/inet_ntoa.cpp b/libc/arpa/inet/inet_ntoa.cpp new file mode 100644 index 00000000..58664384 --- /dev/null +++ b/libc/arpa/inet/inet_ntoa.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + arpa/inet/inet_ntoa.cpp + Internet address manipulation routines. + +*******************************************************************************/ + +#include +#include +#include + +#include +#include + +extern "C" char* inet_ntoa(struct in_addr) +{ + fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__); + abort(); +} diff --git a/libc/arpa/inet/inet_ntop.cpp b/libc/arpa/inet/inet_ntop.cpp new file mode 100644 index 00000000..c2234368 --- /dev/null +++ b/libc/arpa/inet/inet_ntop.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + arpa/inet/inet_ntop.cpp + Internet address manipulation routines. + +*******************************************************************************/ + +#include +#include +#include + +#include +#include + +extern "C" const char* inet_ntop(int, const void* restrict, char* restrict, + socklen_t) +{ + fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__); + abort(); +} diff --git a/libc/arpa/inet/inet_pton.cpp b/libc/arpa/inet/inet_pton.cpp new file mode 100644 index 00000000..950ecd93 --- /dev/null +++ b/libc/arpa/inet/inet_pton.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + arpa/inet/inet_pton.cpp + Internet address manipulation routines. + +*******************************************************************************/ + +#include +#include +#include + +#include +#include + +extern "C" int inet_pton(int, const char* restrict, void* restrict) +{ + fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__); + abort(); +} diff --git a/libc/decl/in_addr_t.h b/libc/decl/in_addr_t.h new file mode 100644 index 00000000..bc7b3cc2 --- /dev/null +++ b/libc/decl/in_addr_t.h @@ -0,0 +1,4 @@ +#ifndef _IN_ADDR_T_DECL +#define _IN_ADDR_T_DECL +typedef uint32_t in_addr_t; +#endif diff --git a/libc/decl/in_port_t.h b/libc/decl/in_port_t.h new file mode 100644 index 00000000..46a69111 --- /dev/null +++ b/libc/decl/in_port_t.h @@ -0,0 +1,4 @@ +#ifndef _IN_PORT_T_DECL +#define _IN_PORT_T_DECL +typedef uint16_t in_port_t; +#endif diff --git a/libc/decl/sa_family_t.h b/libc/decl/sa_family_t.h new file mode 100644 index 00000000..e1fdab6a --- /dev/null +++ b/libc/decl/sa_family_t.h @@ -0,0 +1,4 @@ +#ifndef _SA_FAMILY_T_DECL +#define _SA_FAMILY_T_DECL +typedef unsigned short int sa_family_t; +#endif diff --git a/libc/decl/socklen_t.h b/libc/decl/socklen_t.h new file mode 100644 index 00000000..abea7153 --- /dev/null +++ b/libc/decl/socklen_t.h @@ -0,0 +1,4 @@ +#ifndef _SOCKLEN_T_DECL +#define _SOCKLEN_T_DECL +typedef __socklen_t socklen_t; +#endif diff --git a/libc/include/arpa/inet.h b/libc/include/arpa/inet.h new file mode 100644 index 00000000..bf0e4b8f --- /dev/null +++ b/libc/include/arpa/inet.h @@ -0,0 +1,42 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + arpa/inet.h + Definitions for internet operations. + +*******************************************************************************/ + +#ifndef INCLUDE_ARPA_INET_H +#define INCLUDE_ARPA_INET_H + +#include + +#include + +__BEGIN_DECLS + +in_addr_t inet_addr(const char*); +char* inet_ntoa(struct in_addr); +const char* inet_ntop(int, const void* __restrict, char* __restrict, socklen_t); +int inet_pton(int, const char* __restrict, void* __restrict); +/* TODO: Also provide the various extensions supported by glibc. */ + +__END_DECLS + +#endif diff --git a/libc/include/netdb.h b/libc/include/netdb.h new file mode 100644 index 00000000..550f7ada --- /dev/null +++ b/libc/include/netdb.h @@ -0,0 +1,142 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb.h + Definitions for network database operations. + +*******************************************************************************/ + +#ifndef _NETDB_H +#define _NETDB_H 1 + +#include +#include + +__BEGIN_DECLS + +@include(in_port_t.h) +@include(in_addr_t.h) +@include(socklen_t.h) + +struct hostent +{ + char* h_name; + char** h_aliases; + char** h_addr_list; + int h_addrtype; + int h_length; +}; + +struct netent +{ + char* n_name; + char** n_aliases; + int n_addrtype; + uint32_t n_net; +}; + +struct protoent +{ + char* p_name; + char** p_aliases; + int p_proto; +}; + +struct servent +{ + char* s_name; + char** s_aliases; + char* s_proto; + int s_port; +}; + +struct addrinfo +{ + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + socklen_t ai_addrlen; + struct sockaddr* ai_addr; + char* ai_canonname; + struct addrinfo* ai_next; +}; + +/* TODO: Figure out how this relates to Sortix. */ +#define IPPORT_RESERVED 1024 + +#define AI_PASSIVE (1<<0) +#define AI_CANONNAME (1<<1) +#define AI_NUMERICHOST (1<<2) +#define AI_NUMERICSERV (1<<3) +#define AI_V4MAPPED (1<<4) +#define AI_ALL (1<<5) +#define AI_ADDRCONFIG (1<<6) + +#define NI_NOFQDN (1<<0) +#define NI_NUMERICHOST (1<<1) +#define NI_NAMEREQD (1<<2) +#define NI_NUMERICSERV (1<<3) +#define NI_NUMERICSCOPE (1<<4) +#define NI_DGRAM (1<<5) + +#define EAI_AGAIN 1 +#define EAI_BADFLAGS 2 +#define EAI_FAIL 3 +#define EAI_FAMILY 4 +#define EAI_MEMORY 5 +#define EAI_NONAME 6 +#define EAI_SERVICE 7 +#define EAI_SOCKTYPE 8 +#define EAI_SYSTEM 9 +#define EAI_OVERFLOW 10 + +/* These are not standardized, but are provided on other platforms and existing + sofware uses them, so let's just provide ourselves. */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +void endhostent(void); +void endnetent(void); +void endprotoent(void); +void endservent(void); +void freeaddrinfo(struct addrinfo*); +const char* gai_strerror(int); +int getaddrinfo(const char* restrict, const char* restrict, + const struct addrinfo* restrict, struct addrinfo** restrict); +struct hostent* gethostent(void); +int getnameinfo(const struct sockaddr* restrict, socklen_t, char* restrict, + socklen_t, char* restrict, socklen_t, int); +struct netent* getnetbyaddr(uint32_t, int); +struct netent* getnetbyname(const char*); +struct netent* getnetent(void); +struct protoent* getprotobyname(const char*); +struct protoent* getprotobynumber(int); +struct protoent* getprotoent(void); +struct servent* getservbyname(const char*, const char*); +struct servent* getservbyport(int, const char*); +struct servent* getservent(void); +void sethostent(int); +void setnetent(int); +void setprotoent(int); +void setservent(int); + +__END_DECLS + +#endif diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h new file mode 100644 index 00000000..b4413c60 --- /dev/null +++ b/libc/include/netinet/in.h @@ -0,0 +1,126 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netinet/in.h + Internet socket interface. + +*******************************************************************************/ + +#ifndef INCLUDE_NETINET_IN_H +#define INCLUDE_NETINET_IN_H + +#include +#include +#include <__/endian.h> + +__BEGIN_DECLS + +@include(in_port_t.h) +@include(in_addr_t.h) +@include(sa_family_t.h) +@include(socklen_t.h) + +struct in_addr +{ + in_addr_t s_addr; +}; + +struct sockaddr_in +{ + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; +}; + +struct in6_addr +{ + uint8_t s6_addr[16]; +}; + +struct sockaddr_in6 +{ + sa_family_t sin6_family; + in_port_t sin6_port; + uint32_t sin6_flowinfo; + struct in6_addr sin6_addr; + uint32_t sin6_scope_id; +}; + +extern const struct in6_addr in6addr_any; /* :: */ +extern const struct in6_addr in6addr_loopback; /* ::1 */ +#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } +#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } + +struct ipv6_mreq +{ + struct in6_addr ipv6mr_multiaddr; + unsigned int ipv6mr_interface; +}; + +#define IPPROTO_IP 0 +#define IPPROTO_IPV6 1 +#define IPPROTO_ICMP 2 +#define IPPROTO_RAW 3 +#define IPPROTO_TCP 4 +#define IPPROTO_UDP 5 + +#define INADDR_ANY ((in_addr_t) 0x00000000) +#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) +#define INADDR_NONE ((in_addr_t) 0xffffffff) + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +#define htons(x) __htobe16(x) +#define ntohs(x) __be16toh(x) +#define htonl(x) __htobe32(x) +#define ntohl(x) __be32toh(x) + +#define IPV6_JOIN_GROUP 0 +#define IPV6_LEAVE_GROUP 1 +#define IPV6_MULTICAST_HOPS 2 +#define IPV6_MULTICAST_IF 3 +#define IPV6_MULTICAST_LOOP 4 +#define IPV6_UNICAST_HOPS 5 +#define IPV6_V6ONLY 6 + +/* TODO: +IN6_IS_ADDR_UNSPECIFIED +IN6_IS_ADDR_LOOPBACK +IN6_IS_ADDR_MULTICAST +IN6_IS_ADDR_LINKLOCAL +IN6_IS_ADDR_SITELOCAL +IN6_IS_ADDR_V4MAPPED +IN6_IS_ADDR_V4COMPAT +IN6_IS_ADDR_MC_NODELOCAL +IN6_IS_ADDR_MC_LINKLOCAL +IN6_IS_ADDR_MC_SITELOCAL +IN6_IS_ADDR_MC_ORGLOCAL +IN6_IS_ADDR_MC_GLOBAL +*/ + +# define IN6_ARE_ADDR_EQUAL(a,b) \ + ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \ + && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \ + && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \ + && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3])) + +__END_DECLS + +#endif diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h new file mode 100644 index 00000000..5b1d0f60 --- /dev/null +++ b/libc/include/sys/socket.h @@ -0,0 +1,158 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket.h + Main sockets header. + +*******************************************************************************/ + +#ifndef _SYS_SOCKET_H +#define _SYS_SOCKET_H 1 + +#include +/* TODO: #include */ +#include + +__BEGIN_DECLS + +@include(socklen_t.h) +@include(size_t.h) +@include(ssize_t.h) +@include(sa_family_t.h) + +struct sockaddr +{ + sa_family_t sa_family; + char sa_data[16 - sizeof(sa_family_t)]; +}; + +#define __ss_aligntype unsigned long int +#define _SS_SIZE 128 +#define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype))) +struct sockaddr_storage +{ + sa_family_t ss_family; + __ss_aligntype __ss_align; + char __ss_padding[_SS_PADSIZE]; +}; + +/* TODO: struct iovec from */ + +struct msghdr +{ + void* msg_name; + socklen_t msg_namelen; + struct iovec* msg_iov; + int msg_iovlen; + void* msg_control; + socklen_t msg_controllen; + int msg_flags; +}; + +struct cmsghdr +{ + socklen_t cmsg_len; + int cmsg_level; + int cmsg_type; +}; + +#define SCM_RIGHTS 1 + +/* TODO: CMSG_DATA(cmsg) */ +/* TODO: CMSG_NXTHDR(cmsg) */ +/* TODO: CMSH_FIRSTHDR(cmsg) */ + +struct linger +{ + int l_onoff; + int l_linger; +}; + +#define SOL_SOCKET 1 + +#define SO_ACCEPTCONN 1 +#define SO_BROADCAST 2 +#define SO_DEBUG 3 +#define SO_DONTROUTE 4 +#define SO_ERROR 5 +#define SO_KEEPALIVE 6 +#define SO_LINGER 7 +#define SO_OOBINLINE 8 +#define SO_RCVBUF 9 +#define SO_RCVLOWAT 10 +#define SO_RCVTIMEO 11 +#define SO_REUSEADDR 12 +#define SO_SNDBUF 13 +#define SO_SNDLOWAT 14 +#define SO_SNDTIMEO 15 +#define SO_TYPE 16 + +#define SOMAXCONN 5 + +#define MSG_CTRUNC (1<<0) +#define MSG_DONTROUTE (1<<1) +#define MSG_EOR (1<<2) +#define MSG_OOB (1<<3) +#define MSG_NOSIGNAL (1<<4) +#define MSG_PEEK (1<<5) +#define MSG_TRUNC (1<<6) +#define MSG_WAITALL (1<<7) + +#define AF_UNSPEC 0 +#define AF_INET 1 +#define AF_INET6 2 +#define AF_UNIX 3 + +/* TODO: POSIX doesn't specifiy these and it is a bit of a BSD-ism, but they + appear to be used in some software (such as GNU wget). */ +#define PF_UNSPEC AF_UNSPEC +#define PF_INET AF_INET +#define PF_INET6 AF_INET6 +#define PF_UNIX AF_UNIX + +/* TODO: Nicely wrap this in an enum, as in glibc's header? */ +/* TODO: Should SHUT_RDWR = SHUT_RD | SHUT_WR? */ +#define SHUT_RD 0 +#define SHUT_RDWR 1 +#define SHUT_WR 2 + +int accept4(int, struct sockaddr* restrict, socklen_t* restrict, int); +int accept(int, struct sockaddr* restrict, socklen_t* restrict); +int bind(int, const struct sockaddr*, socklen_t); +int connect(int, const struct sockaddr*, socklen_t); +int getpeername(int, struct sockaddr* restrict, socklen_t* restrict); +int getsockname(int, struct sockaddr* restrict, socklen_t* restrict); +int getsockopt(int, int, int, void* restrict, socklen_t* restrict); +int listen(int, int); +ssize_t recv(int, void*, size_t, int); +ssize_t recvfrom(int, void* restrict, size_t, int, + struct sockaddr* restrict, socklen_t* restrict); +ssize_t recvmsg(int, struct msghdr*, int); +ssize_t send(int, const void*, size_t, int); +ssize_t sendmsg(int, const struct msghdr*, int); +ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t); +int setsockopt(int, int, int, const void*, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int[2]); + +__END_DECLS + +#endif diff --git a/libc/include/sys/un.h b/libc/include/sys/un.h new file mode 100644 index 00000000..aca69a10 --- /dev/null +++ b/libc/include/sys/un.h @@ -0,0 +1,42 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/un.h + Unix domain socket definitions. + +*******************************************************************************/ + +#ifndef _SYS_UN_H +#define _SYS_UN_H 1 + +#include + +__BEGIN_DECLS + +@include(sa_family_t.h) + +struct sockaddr_un +{ + sa_family_t sun_family; + char sun_path[128 - sizeof(sa_family_t)]; +}; + +__END_DECLS + +#endif diff --git a/libc/netdb/endhostent.cpp b/libc/netdb/endhostent.cpp new file mode 100644 index 00000000..64d3421c --- /dev/null +++ b/libc/netdb/endhostent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/endhostent.cpp + Get network host entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void endhostent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/endnetent.cpp b/libc/netdb/endnetent.cpp new file mode 100644 index 00000000..d8aa269f --- /dev/null +++ b/libc/netdb/endnetent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/endnetent.cpp + Get network entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void endnetent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/endprotoent.cpp b/libc/netdb/endprotoent.cpp new file mode 100644 index 00000000..5973a93f --- /dev/null +++ b/libc/netdb/endprotoent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/endprotoent.cpp + Get protocol entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void endprotoent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/endservent.cpp b/libc/netdb/endservent.cpp new file mode 100644 index 00000000..ee14c643 --- /dev/null +++ b/libc/netdb/endservent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/endservent.cpp + Get service entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void endservent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/freeaddrinfo.cpp b/libc/netdb/freeaddrinfo.cpp new file mode 100644 index 00000000..02ef72cb --- /dev/null +++ b/libc/netdb/freeaddrinfo.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/freeaddrinfo.cpp + Free address data structure. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void freeaddrinfo(struct addrinfo*) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/gai_strerror.cpp b/libc/netdb/gai_strerror.cpp new file mode 100644 index 00000000..1f7d4085 --- /dev/null +++ b/libc/netdb/gai_strerror.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/gai_strerror.cpp + Error information for getaddrinfo. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" const char* gai_strerror(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getaddrinfo.cpp b/libc/netdb/getaddrinfo.cpp new file mode 100644 index 00000000..b9d5b406 --- /dev/null +++ b/libc/netdb/getaddrinfo.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getaddrinfo.cpp + Network address and service translation. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int getaddrinfo(const char* restrict, const char* restrict, + const struct addrinfo* restrict, + struct addrinfo** restrict) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/gethostent.cpp b/libc/netdb/gethostent.cpp new file mode 100644 index 00000000..74e870e8 --- /dev/null +++ b/libc/netdb/gethostent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/gethostent.cpp + Get network host entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct hostent* gethostent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getnameinfo.cpp b/libc/netdb/getnameinfo.cpp new file mode 100644 index 00000000..8bb93f00 --- /dev/null +++ b/libc/netdb/getnameinfo.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getnameinfo.cpp + Address-to-name translation in protocol-independent manner. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int getnameinfo(const struct sockaddr* restrict, socklen_t, + char* restrict, socklen_t, char* restrict, socklen_t, + int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getnetbyaddr.cpp b/libc/netdb/getnetbyaddr.cpp new file mode 100644 index 00000000..2f193b46 --- /dev/null +++ b/libc/netdb/getnetbyaddr.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getnetbyaddr.cpp + Get network entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct netent* getnetbyaddr(uint32_t, int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getnetbyname.cpp b/libc/netdb/getnetbyname.cpp new file mode 100644 index 00000000..634e9dab --- /dev/null +++ b/libc/netdb/getnetbyname.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getnetbyname.cpp + Get network entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct netent* getnetbyname(const char*) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getnetent.cpp b/libc/netdb/getnetent.cpp new file mode 100644 index 00000000..62e2c6b4 --- /dev/null +++ b/libc/netdb/getnetent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getnetent.cpp + Get network entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct netent* getnetent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getprotobyname.cpp b/libc/netdb/getprotobyname.cpp new file mode 100644 index 00000000..59ebec6e --- /dev/null +++ b/libc/netdb/getprotobyname.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getprotobyname.cpp + Get protocol entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct protoent* getprotobyname(const char*) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getprotobynumber.cpp b/libc/netdb/getprotobynumber.cpp new file mode 100644 index 00000000..d0922cca --- /dev/null +++ b/libc/netdb/getprotobynumber.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getprotobynumber.cpp + Get protocol entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct protoent* getprotobynumber(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getprotoent.cpp b/libc/netdb/getprotoent.cpp new file mode 100644 index 00000000..6812adac --- /dev/null +++ b/libc/netdb/getprotoent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getprotoent.cpp + Get protocol entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct protoent* getprotoent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getservbyname.cpp b/libc/netdb/getservbyname.cpp new file mode 100644 index 00000000..76016b40 --- /dev/null +++ b/libc/netdb/getservbyname.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getservbyname.cpp + Get service entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct servent* getservbyname(const char*, const char*) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getservbyport.cpp b/libc/netdb/getservbyport.cpp new file mode 100644 index 00000000..ce7256f1 --- /dev/null +++ b/libc/netdb/getservbyport.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getservbyport.cpp + Get service entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct servent* getservbyport(int, const char*) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/getservent.cpp b/libc/netdb/getservent.cpp new file mode 100644 index 00000000..b4ce20c2 --- /dev/null +++ b/libc/netdb/getservent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/getservent.cpp + Get service entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" struct servent* getservent(void) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/sethostent.cpp b/libc/netdb/sethostent.cpp new file mode 100644 index 00000000..1813b447 --- /dev/null +++ b/libc/netdb/sethostent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/sethostent.cpp + Get network host entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void sethostent(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/setnetent.cpp b/libc/netdb/setnetent.cpp new file mode 100644 index 00000000..454da589 --- /dev/null +++ b/libc/netdb/setnetent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/setnetent.cpp + Get network entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void setnetent(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/setprotoent.cpp b/libc/netdb/setprotoent.cpp new file mode 100644 index 00000000..a9dad17e --- /dev/null +++ b/libc/netdb/setprotoent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/setprotoent.cpp + Get protocol entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void setprotoent(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/netdb/setservent.cpp b/libc/netdb/setservent.cpp new file mode 100644 index 00000000..387bb8a7 --- /dev/null +++ b/libc/netdb/setservent.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + netdb/setservent.cpp + Get service entry. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" void setservent(int) +{ + fprintf(stderr, "%s is not implemented, aborting.\n", __func__); + abort(); +} diff --git a/libc/sys/socket/accept.cpp b/libc/sys/socket/accept.cpp new file mode 100644 index 00000000..ee0ee4a3 --- /dev/null +++ b/libc/sys/socket/accept.cpp @@ -0,0 +1,31 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/accept.cpp + Accepts a connection from a listening socket. + +*******************************************************************************/ + +#include + +extern "C" int accept(int fd, struct sockaddr* restrict addr, + socklen_t* restrict addrlen) +{ + return accept4(fd, addr, addrlen, 0); +} diff --git a/libc/sys/socket/accept4.cpp b/libc/sys/socket/accept4.cpp new file mode 100644 index 00000000..a2a84063 --- /dev/null +++ b/libc/sys/socket/accept4.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/accept4.cpp + Accepts a connection from a listening socket. + +*******************************************************************************/ + +#include +#include + +#include + +DEFN_SYSCALL4(int, sys_accept4, SYSCALL_ACCEPT4, int, void*, size_t*, int); + +extern "C" int accept4(int fd, struct sockaddr* restrict addr, + socklen_t* restrict addrlen, int flags) +{ + // Deal with that the kernel doesn't need to understand socklen_t. Since + // that type is designed to be size_t-sized anyway, the compiler should be + // able to optimize all this type safety away, but this function will work + // should the assumption sizeof(size_t) == sizeof(socklen_t) change. + size_t addrlen_size_t; + size_t* addrlen_size_t_ptr = addrlen ? &addrlen_size_t : NULL; + int retfd = sys_accept4(fd, addr, addrlen_size_t_ptr, flags); + if ( addrlen ) *addrlen = addrlen_size_t; + return retfd; +} diff --git a/libc/sys/socket/bind.cpp b/libc/sys/socket/bind.cpp new file mode 100644 index 00000000..8ecb7c51 --- /dev/null +++ b/libc/sys/socket/bind.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/bind.cpp + Binds a socket to an address. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL3(int, sys_bind, SYSCALL_BIND, int, const void*, size_t); + +extern "C" int bind(int fd, const struct sockaddr* addr, socklen_t addrlen) +{ + return sys_bind(fd, addr, addrlen); +} diff --git a/libc/sys/socket/connect.cpp b/libc/sys/socket/connect.cpp new file mode 100644 index 00000000..bad21550 --- /dev/null +++ b/libc/sys/socket/connect.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/connect.cpp + Connects a socket to an address. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL3(int, sys_connect, SYSCALL_CONNECT, int, const void*, size_t); + +extern "C" int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) +{ + return sys_connect(fd, addr, addrlen); +} diff --git a/libc/sys/socket/getpeername.cpp b/libc/sys/socket/getpeername.cpp new file mode 100644 index 00000000..e4433e53 --- /dev/null +++ b/libc/sys/socket/getpeername.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/getpeername.cpp + Get name of connected peer socket. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int getpeername(int, struct sockaddr* restrict, socklen_t* restrict) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/getsockname.cpp b/libc/sys/socket/getsockname.cpp new file mode 100644 index 00000000..fd90db23 --- /dev/null +++ b/libc/sys/socket/getsockname.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/getsockname.cpp + Get socket name. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int getsockname(int, struct sockaddr* restrict, socklen_t* restrict) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/getsockopt.cpp b/libc/sys/socket/getsockopt.cpp new file mode 100644 index 00000000..a0a48aee --- /dev/null +++ b/libc/sys/socket/getsockopt.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/getsockopt.cpp + Get socket options. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int getsockopt(int, int, int, void* restrict, socklen_t* restrict) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/listen.cpp b/libc/sys/socket/listen.cpp new file mode 100644 index 00000000..33f5a3a5 --- /dev/null +++ b/libc/sys/socket/listen.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/listen.cpp + Listens for connections on a socket. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL2(int, sys_listen, SYSCALL_LISTEN, int, int); + +extern "C" int listen(int fd, int backlog) +{ + return sys_listen(fd, backlog); +} diff --git a/libc/sys/socket/recv.cpp b/libc/sys/socket/recv.cpp new file mode 100644 index 00000000..1d0d9f27 --- /dev/null +++ b/libc/sys/socket/recv.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/recv.cpp + Receive data on a socket. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL4(ssize_t, sys_recv, SYSCALL_RECV, int, void*, size_t, int); + +extern "C" ssize_t recv(int fd, void* buf, size_t count, int flags) +{ + return sys_recv(fd, buf, count, flags); +} diff --git a/libc/sys/socket/recvfrom.cpp b/libc/sys/socket/recvfrom.cpp new file mode 100644 index 00000000..8772967e --- /dev/null +++ b/libc/sys/socket/recvfrom.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/recvfrom.cpp + Receive a message from a socket. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" ssize_t recvfrom(int, void* restrict, size_t, int, + struct sockaddr* restrict, socklen_t* restrict) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/recvmsg.cpp b/libc/sys/socket/recvmsg.cpp new file mode 100644 index 00000000..08acefd9 --- /dev/null +++ b/libc/sys/socket/recvmsg.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/recvmsg.cpp + Receive a message from a socket. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" ssize_t recvmsg(int, struct msghdr*, int) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/send.cpp b/libc/sys/socket/send.cpp new file mode 100644 index 00000000..c29c2be8 --- /dev/null +++ b/libc/sys/socket/send.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/send.cpp + Receive data on a socket. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL4(ssize_t, sys_send, SYSCALL_RECV, int, const void*, size_t, int); + +extern "C" ssize_t send(int fd, const void* buf, size_t count, int flags) +{ + return sys_send(fd, buf, count, flags); +} diff --git a/libc/sys/socket/sendmsg.cpp b/libc/sys/socket/sendmsg.cpp new file mode 100644 index 00000000..2f9b7559 --- /dev/null +++ b/libc/sys/socket/sendmsg.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/sendmsg.cpp + Send a message on a socket. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" ssize_t sendmsg(int, const struct msghdr*, int) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/sendto.cpp b/libc/sys/socket/sendto.cpp new file mode 100644 index 00000000..fcbb264c --- /dev/null +++ b/libc/sys/socket/sendto.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/sendto.cpp + Send a message on a socket. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, + socklen_t) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/setsockopt.cpp b/libc/sys/socket/setsockopt.cpp new file mode 100644 index 00000000..12c4c630 --- /dev/null +++ b/libc/sys/socket/setsockopt.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/setsockopt.cpp + Set socket options. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int setsockopt(int, int, int, const void*, socklen_t) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/shutdown.cpp b/libc/sys/socket/shutdown.cpp new file mode 100644 index 00000000..50b45861 --- /dev/null +++ b/libc/sys/socket/shutdown.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/shutdown.cpp + Shut down part of a full-duplex connection. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int shutdown(int, int) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/sockatmark.cpp b/libc/sys/socket/sockatmark.cpp new file mode 100644 index 00000000..7b635f4a --- /dev/null +++ b/libc/sys/socket/sockatmark.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/sockatmark.cpp + Determine whether socket is at out-of-band mark. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int sockatmark(int) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/libc/sys/socket/socket.cpp b/libc/sys/socket/socket.cpp new file mode 100644 index 00000000..a6a99561 --- /dev/null +++ b/libc/sys/socket/socket.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/socket.cpp + Creates a new unconnected socket. + +*******************************************************************************/ + +#include + +#include +#include +#include + +static const char* get_socket_factory(int domain, int type, int protocol) +{ + if ( domain == AF_INET ) + { + if ( type == SOCK_DGRAM && !protocol ) + return "/dev/net/ipv4/udp"; + if ( type == SOCK_STREAM && !protocol ) + return "/dev/net/ipv4/tcp"; + return errno = EPROTONOSUPPORT, (const char*) NULL; + } + + if ( domain == AF_INET6 ) + { + if ( type == SOCK_DGRAM && !protocol ) + return "/dev/net/ipv6/udp"; + if ( type == SOCK_STREAM && !protocol ) + return "/dev/net/ipv6/tcp"; + return errno = EPROTONOSUPPORT, (const char*) NULL; + } + + if ( domain == AF_UNIX ) + { + if ( type == SOCK_DGRAM && !protocol ) + return "/dev/net/fs/datagram"; + if ( type == SOCK_STREAM && !protocol ) + return "/dev/net/fs/stream"; + return errno = EPROTONOSUPPORT, (const char*) NULL; + } + + return errno = EAFNOSUPPORT, (const char*) NULL; +} + +extern "C" int socket(int domain, int type, int protocol) +{ + int open_flags = O_RDWR; + // TODO: O_NONBLOCK is not supported! + //if ( type & SOCK_NONBLOCK ) open_flags |= O_NONBLOCK; + if ( type & SOCK_CLOEXEC ) open_flags |= O_CLOEXEC; + if ( type & SOCK_CLOFORK ) open_flags |= O_CLOFORK; + type &= SOCK_TYPE_MASK; + const char* factory = get_socket_factory(domain, type, protocol); + if ( !factory ) + return -1; + int ret = open(factory, open_flags); + if ( ret < 0 && errno == ENOENT ) + errno = EPROTONOSUPPORT; + return ret; +} diff --git a/libc/sys/socket/socketpair.cpp b/libc/sys/socket/socketpair.cpp new file mode 100644 index 00000000..80ca0c4f --- /dev/null +++ b/libc/sys/socket/socketpair.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix 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 3 of the License, or (at your + option) any later version. + + The Sortix 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 Sortix C Library. If not, see . + + sys/socket/socketpair.cpp + Create a pair of connected sockets. + +*******************************************************************************/ + +#include + +#include +#include + +extern "C" int socketpair(int, int, int, int[2]) +{ + fprintf(stderr, "%s is not implemented yet.\n", __func__); + return errno = ENOSYS, -1; +} diff --git a/sortix/descriptor.cpp b/sortix/descriptor.cpp index 9167f49d..aac0a154 100644 --- a/sortix/descriptor.cpp +++ b/sortix/descriptor.cpp @@ -550,4 +550,37 @@ int Descriptor::poll(ioctx_t* ctx, PollNode* node) return vnode->poll(ctx, node); } +Ref Descriptor::accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, int flags) +{ + Ref retvnode = vnode->accept(ctx, addr, addrlen, flags); + if ( !retvnode ) + return Ref(); + return Ref(new Descriptor(retvnode, O_READ | O_WRITE)); +} + +int Descriptor::bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) +{ + return vnode->bind(ctx, addr, addrlen); +} + +int Descriptor::connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) +{ + return vnode->connect(ctx, addr, addrlen); +} + +int Descriptor::listen(ioctx_t* ctx, int backlog) +{ + return vnode->listen(ctx, backlog); +} + +ssize_t Descriptor::recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags) +{ + return vnode->recv(ctx, buf, count, flags); +} + +ssize_t Descriptor::send(ioctx_t* ctx, const uint8_t* buf, size_t count, int flags) +{ + return vnode->send(ctx, buf, count, flags); +} + } // namespace Sortix diff --git a/sortix/fs/user.cpp b/sortix/fs/user.cpp index bb683fff..b3048826 100644 --- a/sortix/fs/user.cpp +++ b/sortix/fs/user.cpp @@ -216,6 +216,14 @@ public: virtual int poll(ioctx_t* ctx, PollNode* node); virtual int rename_here(ioctx_t* ctx, Ref from, const char* oldname, const char* newname); + virtual Ref accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, + int flags); + virtual int bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + virtual int connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + virtual int listen(ioctx_t* ctx, int backlog); + virtual ssize_t recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags); + virtual ssize_t send(ioctx_t* ctx, const uint8_t* buf, size_t count, + int flags); private: bool SendMessage(Channel* channel, size_t type, void* ptr, size_t size, @@ -1145,6 +1153,39 @@ int Unode::rename_here(ioctx_t* /*ctx*/, Ref from, const char* oldname, return ret; } +Ref Unode::accept(ioctx_t* /*ctx*/, uint8_t* /*addr*/, + size_t* /*addrlen*/, int /*flags*/) +{ + return errno = ENOTSOCK, Ref(); +} + +int Unode::bind(ioctx_t* /*ctx*/, const uint8_t* /*addr*/, size_t /*addrlen*/) +{ + return errno = ENOTSOCK, -1; +} + +int Unode::connect(ioctx_t* /*ctx*/, const uint8_t* /*addr*/, size_t /*addrlen*/) +{ + return errno = ENOTSOCK, -1; +} + +int Unode::listen(ioctx_t* /*ctx*/, int /*backlog*/) +{ + return errno = ENOTSOCK, -1; +} + +ssize_t Unode::recv(ioctx_t* /*ctx*/, uint8_t* /*buf*/, size_t /*count*/, + int /*flags*/) +{ + return errno = ENOTSOCK, -1; +} + +ssize_t Unode::send(ioctx_t* /*ctx*/, const uint8_t* /*buf*/, size_t /*count*/, + int /*flags*/) +{ + return errno = ENOTSOCK, -1; +} + // // Initialization. // diff --git a/sortix/include/sortix/__/types.h b/sortix/include/sortix/__/types.h index 1aada414..c0d6981f 100644 --- a/sortix/include/sortix/__/types.h +++ b/sortix/include/sortix/__/types.h @@ -55,6 +55,7 @@ typedef long int __ssize_t; typedef int __ssize_t; #endif typedef void* __timer_t; +typedef __SIZE_TYPE__ __socklen_t; #if defined(SORTIX_KERNEL) || defined(LIBC_LIBRARY) #define OFF_MIN __OFF_MIN diff --git a/sortix/include/sortix/kernel/descriptor.h b/sortix/include/sortix/kernel/descriptor.h index deca9ec0..1bf49a3a 100644 --- a/sortix/include/sortix/kernel/descriptor.h +++ b/sortix/include/sortix/kernel/descriptor.h @@ -82,6 +82,13 @@ public: int poll(ioctx_t* ctx, PollNode* node); int rename_here(ioctx_t* ctx, Ref from, const char* oldpath, const char* newpath); + Ref accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, + int flags); + int bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + int connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + int listen(ioctx_t* ctx, int backlog); + ssize_t recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags); + ssize_t send(ioctx_t* ctx, const uint8_t* buf, size_t count, int flags); private: Ref open_elem(ioctx_t* ctx, const char* filename, int flags, diff --git a/sortix/include/sortix/kernel/inode.h b/sortix/include/sortix/kernel/inode.h index 00b08cad..519c287c 100644 --- a/sortix/include/sortix/kernel/inode.h +++ b/sortix/include/sortix/kernel/inode.h @@ -90,6 +90,14 @@ public: virtual int poll(ioctx_t* ctx, PollNode* node) = 0; virtual int rename_here(ioctx_t* ctx, Ref from, const char* oldname, const char* newname) = 0; + virtual Ref accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, + int flags) = 0; + virtual int bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) = 0; + virtual int connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) = 0; + virtual int listen(ioctx_t* ctx, int backlog) = 0; + virtual ssize_t recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags) = 0; + virtual ssize_t send(ioctx_t* ctx, const uint8_t* buf, size_t count, + int flags) = 0; }; @@ -156,6 +164,14 @@ public: virtual int poll(ioctx_t* ctx, PollNode* node); virtual int rename_here(ioctx_t* ctx, Ref from, const char* oldname, const char* newname); + virtual Ref accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, + int flags); + virtual int bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + virtual int connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + virtual int listen(ioctx_t* ctx, int backlog); + virtual ssize_t recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags); + virtual ssize_t send(ioctx_t* ctx, const uint8_t* buf, size_t count, + int flags); }; diff --git a/sortix/include/sortix/kernel/vnode.h b/sortix/include/sortix/kernel/vnode.h index ace01ce1..ceb5cd8e 100644 --- a/sortix/include/sortix/kernel/vnode.h +++ b/sortix/include/sortix/kernel/vnode.h @@ -79,6 +79,12 @@ public: int poll(ioctx_t* ctx, PollNode* node); int rename_here(ioctx_t* ctx, Ref from, const char* oldname, const char* newname); + Ref accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, int flags); + int bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + int connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen); + int listen(ioctx_t* ctx, int backlog); + ssize_t recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags); + ssize_t send(ioctx_t* ctx, const uint8_t* buf, size_t count, int flags); public /*TODO: private*/: Ref inode; diff --git a/sortix/include/sortix/socket.h b/sortix/include/sortix/socket.h new file mode 100644 index 00000000..b6c68a06 --- /dev/null +++ b/sortix/include/sortix/socket.h @@ -0,0 +1,45 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix 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 General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + sortix/socket.h + Declarations for socket types and other flags. + +*******************************************************************************/ + +#ifndef SORTIX_INCLUDE_SOCKET_H +#define SORTIX_INCLUDE_SOCKET_H + +#include + +__BEGIN_DECLS + +/* TODO: Nicely wrap this in an enum, as in glibc's header? */ +#define SOCK_TYPE_MASK ((1<<20)-1) +#define SOCK_RAW 0 /* Will Sortix support this? */ +#define SOCK_DGRAM 1 +#define SOCK_SEQPACKET 2 +#define SOCK_STREAM 3 + +#define SOCK_NONBLOCK (1<<20) +#define SOCK_CLOEXEC (1<<21) +#define SOCK_CLOFORK (1<<22) + +__END_DECLS + +#endif diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 9274885d..64a2cf46 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -108,6 +108,12 @@ #define SYSCALL_IOCTL 84 #define SYSCALL_UTIMENSAT 85 #define SYSCALL_FUTIMENS 86 -#define SYSCALL_MAX_NUM 87 /* index of highest constant + 1 */ +#define SYSCALL_RECV 87 +#define SYSCALL_SEND 88 +#define SYSCALL_ACCEPT4 89 +#define SYSCALL_BIND 90 +#define SYSCALL_CONNECT 91 +#define SYSCALL_LISTEN 92 +#define SYSCALL_MAX_NUM 93 /* index of highest constant + 1 */ #endif diff --git a/sortix/include/sortix/x64/bits.h b/sortix/include/sortix/x64/bits.h index dc6b6735..358d548a 100644 --- a/sortix/include/sortix/x64/bits.h +++ b/sortix/include/sortix/x64/bits.h @@ -152,5 +152,6 @@ typedef int __clockid_t; typedef long __time_t; typedef long __suseconds_t; typedef void* __timer_t; +typedef __SIZE_TYPE__ __socklen_t; #endif diff --git a/sortix/include/sortix/x86/bits.h b/sortix/include/sortix/x86/bits.h index 6f0692fb..04017870 100644 --- a/sortix/include/sortix/x86/bits.h +++ b/sortix/include/sortix/x86/bits.h @@ -152,5 +152,6 @@ typedef int __clockid_t; typedef long __time_t; typedef long __suseconds_t; typedef void* __timer_t; +typedef __SIZE_TYPE__ __socklen_t; #endif diff --git a/sortix/inode.cpp b/sortix/inode.cpp index 13f4a600..92cf52ab 100644 --- a/sortix/inode.cpp +++ b/sortix/inode.cpp @@ -293,4 +293,39 @@ int AbstractInode::rename_here(ioctx_t* /*ctx*/, Ref /*from*/, return errno = ENOTDIR, -1; } +Ref AbstractInode::accept(ioctx_t* /*ctx*/, uint8_t* /*addr*/, + size_t* /*addrlen*/, int /*flags*/) +{ + return errno = ENOTSOCK, Ref(); +} + +int AbstractInode::bind(ioctx_t* /*ctx*/, const uint8_t* /*addr*/, + size_t /*addrlen*/) +{ + return errno = ENOTSOCK, -1; +} + +int AbstractInode::connect(ioctx_t* /*ctx*/, const uint8_t* /*addr*/, + size_t /*addrlen*/) +{ + return errno = ENOTSOCK, -1; +} + +int AbstractInode::listen(ioctx_t* /*ctx*/, int /*backlog*/) +{ + return errno = ENOTSOCK, -1; +} + +ssize_t AbstractInode::recv(ioctx_t* /*ctx*/, uint8_t* /*buf*/, + size_t /*count*/, int /*flags*/) +{ + return errno = ENOTSOCK, -1; +} + +ssize_t AbstractInode::send(ioctx_t* /*ctx*/, const uint8_t* /*buf*/, + size_t /*count*/, int /*flags*/) +{ + return errno = ENOTSOCK, -1; +} + } // namespace Sortix diff --git a/sortix/io.cpp b/sortix/io.cpp index 5e576e7d..4e58417f 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -623,13 +624,78 @@ static int sys_fsync(int fd) return desc->sync(&ctx); } +static int sys_accept4(int fd, void* addr, size_t* addrlen, int flags) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + int fdflags = 0; + // TODO: Support SOCK_NONBLOCK + if ( flags & SOCK_CLOEXEC ) fdflags |= FD_CLOEXEC; + if ( flags & SOCK_CLOFORK ) fdflags |= FD_CLOFORK; + flags &= ~(SOCK_CLOEXEC | SOCK_CLOFORK); + ioctx_t ctx; SetupUserIOCtx(&ctx); + Ref conn = desc->accept(&ctx, (uint8_t*) addr, addrlen, flags); + if ( !conn ) + return -1; + return CurrentProcess()->GetDTable()->Allocate(conn, fdflags); +} + +static int sys_bind(int fd, const void* addr, size_t addrlen) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->bind(&ctx, (const uint8_t*) addr, addrlen); +} + +static int sys_connect(int fd, const void* addr, size_t addrlen) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->connect(&ctx, (const uint8_t*) addr, addrlen); +} + +static int sys_listen(int fd, int backlog) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->listen(&ctx, backlog); +} + +static ssize_t sys_recv(int fd, void* buffer, size_t count, int flags) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->recv(&ctx, (uint8_t*) buffer, count, flags); +} + +static ssize_t sys_send(int fd, const void* buffer, size_t count, int flags) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->send(&ctx, (const uint8_t*) buffer, count, flags); +} + void Init() { + Syscall::Register(SYSCALL_ACCEPT4, (void*) sys_accept4); Syscall::Register(SYSCALL_ACCESS, (void*) sys_access); + Syscall::Register(SYSCALL_BIND, (void*) sys_bind); Syscall::Register(SYSCALL_CHDIR, (void*) sys_chdir); Syscall::Register(SYSCALL_CHMOD, (void*) sys_chmod); Syscall::Register(SYSCALL_CHOWN, (void*) sys_chown); Syscall::Register(SYSCALL_CLOSE, (void*) sys_close); + Syscall::Register(SYSCALL_CONNECT, (void*) sys_connect); Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2); Syscall::Register(SYSCALL_DUP, (void*) sys_dup); Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat); @@ -649,6 +715,7 @@ void Init() Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty); Syscall::Register(SYSCALL_LINKAT, (void*) sys_linkat); Syscall::Register(SYSCALL_LINK, (void*) sys_link); + Syscall::Register(SYSCALL_LISTEN, (void*) sys_listen); Syscall::Register(SYSCALL_MKDIRAT, (void*) sys_mkdirat); Syscall::Register(SYSCALL_MKDIR, (void*) sys_mkdir); Syscall::Register(SYSCALL_OPENAT, (void*) sys_openat); @@ -658,9 +725,11 @@ void Init() Syscall::Register(SYSCALL_READDIRENTS, (void*) sys_readdirents); Syscall::Register(SYSCALL_READLINKAT, (void*) sys_readlinkat); Syscall::Register(SYSCALL_READ, (void*) sys_read); + Syscall::Register(SYSCALL_RECV, (void*) sys_recv); Syscall::Register(SYSCALL_RENAMEAT, (void*) sys_renameat); Syscall::Register(SYSCALL_RMDIR, (void*) sys_rmdir); Syscall::Register(SYSCALL_SEEK, (void*) sys_seek); + Syscall::Register(SYSCALL_SEND, (void*) sys_send); Syscall::Register(SYSCALL_SETTERMMODE, (void*) sys_settermmode); Syscall::Register(SYSCALL_STAT, (void*) sys_stat); Syscall::Register(SYSCALL_TCGETWINSIZE, (void*) sys_tcgetwinsize); diff --git a/sortix/vnode.cpp b/sortix/vnode.cpp index c5826d27..22a14a16 100644 --- a/sortix/vnode.cpp +++ b/sortix/vnode.cpp @@ -227,4 +227,37 @@ int Vnode::poll(ioctx_t* ctx, PollNode* node) return inode->poll(ctx, node); } +Ref Vnode::accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, int flags) +{ + Ref retinode = inode->accept(ctx, addr, addrlen, flags); + if ( !retinode ) + return Ref(); + return Ref(new Vnode(retinode, Ref(), retinode->ino, retinode->dev)); +} + +int Vnode::bind(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) +{ + return inode->bind(ctx, addr, addrlen); +} + +int Vnode::connect(ioctx_t* ctx, const uint8_t* addr, size_t addrlen) +{ + return inode->connect(ctx, addr, addrlen); +} + +int Vnode::listen(ioctx_t* ctx, int backlog) +{ + return inode->listen(ctx, backlog); +} + +ssize_t Vnode::recv(ioctx_t* ctx, uint8_t* buf, size_t count, int flags) +{ + return inode->recv(ctx, buf, count, flags); +} + +ssize_t Vnode::send(ioctx_t* ctx, const uint8_t* buf, size_t count, int flags) +{ + return inode->send(ctx, buf, count, flags); +} + } // namespace Sortix