Add socket interface.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-19 22:40:37 +01:00
parent ee106231c4
commit 79a49b2015
68 changed files with 2457 additions and 1 deletions

View File

@ -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 \

View File

@ -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 <http://www.gnu.org/licenses/>.
arpa/inet/inet_addr.cpp
Internet address manipulation routines.
*******************************************************************************/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" in_addr_t inet_addr(const char*)
{
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
arpa/inet/inet_ntoa.cpp
Internet address manipulation routines.
*******************************************************************************/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" char* inet_ntoa(struct in_addr)
{
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
arpa/inet/inet_ntop.cpp
Internet address manipulation routines.
*******************************************************************************/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
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();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
arpa/inet/inet_pton.cpp
Internet address manipulation routines.
*******************************************************************************/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" int inet_pton(int, const char* restrict, void* restrict)
{
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}

4
libc/decl/in_addr_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _IN_ADDR_T_DECL
#define _IN_ADDR_T_DECL
typedef uint32_t in_addr_t;
#endif

4
libc/decl/in_port_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _IN_PORT_T_DECL
#define _IN_PORT_T_DECL
typedef uint16_t in_port_t;
#endif

4
libc/decl/sa_family_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _SA_FAMILY_T_DECL
#define _SA_FAMILY_T_DECL
typedef unsigned short int sa_family_t;
#endif

4
libc/decl/socklen_t.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _SOCKLEN_T_DECL
#define _SOCKLEN_T_DECL
typedef __socklen_t socklen_t;
#endif

42
libc/include/arpa/inet.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
arpa/inet.h
Definitions for internet operations.
*******************************************************************************/
#ifndef INCLUDE_ARPA_INET_H
#define INCLUDE_ARPA_INET_H
#include <features.h>
#include <netinet/in.h>
__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

142
libc/include/netdb.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb.h
Definitions for network database operations.
*******************************************************************************/
#ifndef _NETDB_H
#define _NETDB_H 1
#include <features.h>
#include <inttypes.h>
__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

126
libc/include/netinet/in.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netinet/in.h
Internet socket interface.
*******************************************************************************/
#ifndef INCLUDE_NETINET_IN_H
#define INCLUDE_NETINET_IN_H
#include <features.h>
#include <inttypes.h>
#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

158
libc/include/sys/socket.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket.h
Main sockets header.
*******************************************************************************/
#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H 1
#include <features.h>
/* TODO: #include <sys/uio.h> */
#include <sortix/socket.h>
__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 <sys/uio.h> */
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

42
libc/include/sys/un.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sys/un.h
Unix domain socket definitions.
*******************************************************************************/
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
#include <features.h>
__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

34
libc/netdb/endhostent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/endhostent.cpp
Get network host entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void endhostent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/endnetent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/endnetent.cpp
Get network entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void endnetent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/endprotoent.cpp
Get protocol entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void endprotoent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/endservent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/endservent.cpp
Get service entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void endservent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/freeaddrinfo.cpp
Free address data structure.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void freeaddrinfo(struct addrinfo*)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/gai_strerror.cpp
Error information for getaddrinfo.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" const char* gai_strerror(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getaddrinfo.cpp
Network address and service translation.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
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();
}

34
libc/netdb/gethostent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/gethostent.cpp
Get network host entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct hostent* gethostent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getnameinfo.cpp
Address-to-name translation in protocol-independent manner.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
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();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getnetbyaddr.cpp
Get network entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct netent* getnetbyaddr(uint32_t, int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getnetbyname.cpp
Get network entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct netent* getnetbyname(const char*)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/getnetent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getnetent.cpp
Get network entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct netent* getnetent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getprotobyname.cpp
Get protocol entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct protoent* getprotobyname(const char*)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getprotobynumber.cpp
Get protocol entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct protoent* getprotobynumber(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getprotoent.cpp
Get protocol entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct protoent* getprotoent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getservbyname.cpp
Get service entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct servent* getservbyname(const char*, const char*)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getservbyport.cpp
Get service entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct servent* getservbyport(int, const char*)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/getservent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/getservent.cpp
Get service entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" struct servent* getservent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/sethostent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/sethostent.cpp
Get network host entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void sethostent(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/setnetent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/setnetent.cpp
Get network entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void setnetent(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/setprotoent.cpp
Get protocol entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void setprotoent(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

34
libc/netdb/setservent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
netdb/setservent.cpp
Get service entry.
*******************************************************************************/
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
extern "C" void setservent(int)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/accept.cpp
Accepts a connection from a listening socket.
*******************************************************************************/
#include <sys/socket.h>
extern "C" int accept(int fd, struct sockaddr* restrict addr,
socklen_t* restrict addrlen)
{
return accept4(fd, addr, addrlen, 0);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/accept4.cpp
Accepts a connection from a listening socket.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
#include <stddef.h>
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;
}

33
libc/sys/socket/bind.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/bind.cpp
Binds a socket to an address.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/connect.cpp
Connects a socket to an address.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/getpeername.cpp
Get name of connected peer socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int getpeername(int, struct sockaddr* restrict, socklen_t* restrict)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/getsockname.cpp
Get socket name.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int getsockname(int, struct sockaddr* restrict, socklen_t* restrict)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/getsockopt.cpp
Get socket options.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/listen.cpp
Listens for connections on a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
DEFN_SYSCALL2(int, sys_listen, SYSCALL_LISTEN, int, int);
extern "C" int listen(int fd, int backlog)
{
return sys_listen(fd, backlog);
}

33
libc/sys/socket/recv.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/recv.cpp
Receive data on a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/recvfrom.cpp
Receive a message from a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/recvmsg.cpp
Receive a message from a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" ssize_t recvmsg(int, struct msghdr*, int)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

33
libc/sys/socket/send.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/send.cpp
Receive data on a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <sys/syscall.h>
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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/sendmsg.cpp
Send a message on a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" ssize_t sendmsg(int, const struct msghdr*, int)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/sendto.cpp
Send a message on a socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/setsockopt.cpp
Set socket options.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int setsockopt(int, int, int, const void*, socklen_t)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/shutdown.cpp
Shut down part of a full-duplex connection.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int shutdown(int, int)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/sockatmark.cpp
Determine whether socket is at out-of-band mark.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int sockatmark(int)
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/socket.cpp
Creates a new unconnected socket.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
sys/socket/socketpair.cpp
Create a pair of connected sockets.
*******************************************************************************/
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
extern "C" int socketpair(int, int, int, int[2])
{
fprintf(stderr, "%s is not implemented yet.\n", __func__);
return errno = ENOSYS, -1;
}

View File

@ -550,4 +550,37 @@ int Descriptor::poll(ioctx_t* ctx, PollNode* node)
return vnode->poll(ctx, node);
}
Ref<Descriptor> Descriptor::accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, int flags)
{
Ref<Vnode> retvnode = vnode->accept(ctx, addr, addrlen, flags);
if ( !retvnode )
return Ref<Descriptor>();
return Ref<Descriptor>(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

View File

@ -216,6 +216,14 @@ public:
virtual int poll(ioctx_t* ctx, PollNode* node);
virtual int rename_here(ioctx_t* ctx, Ref<Inode> from, const char* oldname,
const char* newname);
virtual Ref<Inode> 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<Inode> from, const char* oldname,
return ret;
}
Ref<Inode> Unode::accept(ioctx_t* /*ctx*/, uint8_t* /*addr*/,
size_t* /*addrlen*/, int /*flags*/)
{
return errno = ENOTSOCK, Ref<Inode>();
}
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.
//

View File

@ -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

View File

@ -82,6 +82,13 @@ public:
int poll(ioctx_t* ctx, PollNode* node);
int rename_here(ioctx_t* ctx, Ref<Descriptor> from, const char* oldpath,
const char* newpath);
Ref<Descriptor> 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<Descriptor> open_elem(ioctx_t* ctx, const char* filename, int flags,

View File

@ -90,6 +90,14 @@ public:
virtual int poll(ioctx_t* ctx, PollNode* node) = 0;
virtual int rename_here(ioctx_t* ctx, Ref<Inode> from, const char* oldname,
const char* newname) = 0;
virtual Ref<Inode> 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<Inode> from, const char* oldname,
const char* newname);
virtual Ref<Inode> 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);
};

View File

@ -79,6 +79,12 @@ public:
int poll(ioctx_t* ctx, PollNode* node);
int rename_here(ioctx_t* ctx, Ref<Vnode> from, const char* oldname,
const char* newname);
Ref<Vnode> 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> inode;

View File

@ -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 <http://www.gnu.org/licenses/>.
sortix/socket.h
Declarations for socket types and other flags.
*******************************************************************************/
#ifndef SORTIX_INCLUDE_SOCKET_H
#define SORTIX_INCLUDE_SOCKET_H
#include <features.h>
__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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -293,4 +293,39 @@ int AbstractInode::rename_here(ioctx_t* /*ctx*/, Ref<Inode> /*from*/,
return errno = ENOTDIR, -1;
}
Ref<Inode> AbstractInode::accept(ioctx_t* /*ctx*/, uint8_t* /*addr*/,
size_t* /*addrlen*/, int /*flags*/)
{
return errno = ENOTSOCK, Ref<Inode>();
}
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

View File

@ -36,6 +36,7 @@
#include <sortix/dirent.h>
#include <sortix/fcntl.h>
#include <sortix/stat.h>
#include <sortix/socket.h>
#include <assert.h>
#include <errno.h>
@ -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<Descriptor> 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<Descriptor> 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<Descriptor> 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<Descriptor> 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<Descriptor> 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<Descriptor> 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<Descriptor> 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);

View File

@ -227,4 +227,37 @@ int Vnode::poll(ioctx_t* ctx, PollNode* node)
return inode->poll(ctx, node);
}
Ref<Vnode> Vnode::accept(ioctx_t* ctx, uint8_t* addr, size_t* addrlen, int flags)
{
Ref<Inode> retinode = inode->accept(ctx, addr, addrlen, flags);
if ( !retinode )
return Ref<Vnode>();
return Ref<Vnode>(new Vnode(retinode, Ref<Vnode>(), 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