From cc0c50a8d5542f3717cb14b6eb8ba331328be766 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 24 Jul 2016 15:13:06 -0700 Subject: [PATCH] Add nsysnet RPL imports --- include/nsysnet/socket.h | 170 +++++++++++++++++++++++++++++++++++++++ include/sys/select.h | 3 + include/sys/socket.h | 3 + rpl/Makefile | 2 +- rpl/libnsysnet/Makefile | 2 + rpl/libnsysnet/config.h | 1 + rpl/libnsysnet/exports.h | 39 +++++++++ 7 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 include/nsysnet/socket.h create mode 100644 include/sys/select.h create mode 100644 include/sys/socket.h create mode 100644 rpl/libnsysnet/Makefile create mode 100644 rpl/libnsysnet/config.h create mode 100644 rpl/libnsysnet/exports.h diff --git a/include/nsysnet/socket.h b/include/nsysnet/socket.h new file mode 100644 index 0000000..533d903 --- /dev/null +++ b/include/nsysnet/socket.h @@ -0,0 +1,170 @@ +#pragma once +#include +#include +#include +#include + +/** + * \defgroup nsysnet_socket Socket + * \ingroup nsysnet + * @{ + */ + +#define SOL_SOCKET 0xFFFF + +#define PF_UNSPEC 0 +#define PF_INET 2 +#define PF_INET6 23 + +#define AF_UNSPEC PF_UNSPEC +#define AF_INET PF_INET +#define AF_INET6 PF_INET6 + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 + +#define MSG_OOB 0x0001 +#define MSG_PEEK 0x0002 +#define MSG_DONTWAIT 0x0004 +#define MSG_DONTROUTE 0x0000 // ??? +#define MSG_WAITALL 0x0000 // ??? +#define MSG_MORE 0x0000 // ??? +#define MSG_NOSIGNAL 0x0000 // there are no signals + +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 + +/* + * SOL_SOCKET options + */ +#define SO_REUSEADDR 0x0004 // reuse address +#define SO_LINGER 0x0080 // linger (no effect?) +#define SO_OOBINLINE 0x0100 // out-of-band data inline (no effect?) +#define SO_SNDBUF 0x1001 // send buffer size +#define SO_RCVBUF 0x1002 // receive buffer size +#define SO_SNDLOWAT 0x1003 // send low-water mark (no effect?) +#define SO_RCVLOWAT 0x1004 // receive low-water mark +#define SO_TYPE 0x1008 // get socket type +#define SO_ERROR 0x1009 // get socket error + +typedef uint32_t socklen_t; +typedef uint16_t sa_family_t; + +struct sockaddr { + sa_family_t sa_family; + char sa_data[]; +}; + +struct sockaddr_storage { + sa_family_t ss_family; + char __ss_padding[26]; +}; + +struct linger { + int l_onoff; + int l_linger; +}; + +#ifdef __cplusplus +"C" { +#endif + +void +socket_lib_init(); + +int +accept(int sockfd, + struct sockaddr *addr, + socklen_t *addrlen); + +int +bind(int sockfd, + const struct sockaddr *addr, + socklen_t addrlen); + +int +closesocket(int sockfd); + +int +connect(int sockfd, + const struct sockaddr *addr, + socklen_t addrlen); + +int +getpeername(int sockfd, + struct sockaddr *addr, + socklen_t *addrlen); + +int +getsockname(int sockfd, + struct sockaddr *addr, + socklen_t *addrlen); + +int +getsockopt(int sockfd, + int level, + int optname, + void *optval, + socklen_t *optlen); + +int +listen(int sockfd, + int backlog); + +ssize_t +recv(int sockfd, + void *buf, + size_t len, + int flags); + +ssize_t +recvfrom(int sockfd, + void *buf, + size_t len, + int flags, + struct sockaddr *src_addr, + socklen_t *addrlen); + +ssize_t +send(int sockfd, + const void *buf, + size_t len, + int flags); + +ssize_t +sendto(int sockfd, + const void *buf, + size_t len, + int flags, + const struct sockaddr *dest_addr, + socklen_t addrlen); + +int +setsockopt(int sockfd, + int level, + int optname, + const void *optval, + socklen_t optlen); + +int +shutdown(int sockfd, + int how); + +int +socket(int domain, + int type, + int protocol); + +int +select(int nfds, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout); + +#ifdef __cplusplus +} +#endif + +/** @} */ diff --git a/include/sys/select.h b/include/sys/select.h new file mode 100644 index 0000000..5d49dd8 --- /dev/null +++ b/include/sys/select.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/include/sys/socket.h b/include/sys/socket.h new file mode 100644 index 0000000..5d49dd8 --- /dev/null +++ b/include/sys/socket.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/rpl/Makefile b/rpl/Makefile index b4f0500..d3d1977 100644 --- a/rpl/Makefile +++ b/rpl/Makefile @@ -1,5 +1,5 @@ WUT_ROOT := $(CURDIR)/.. -TARGETS := libcoreinit libgx2 +TARGETS := libcoreinit libgx2 libnsysnet all: @for dir in $(TARGETS); do \ diff --git a/rpl/libnsysnet/Makefile b/rpl/libnsysnet/Makefile new file mode 100644 index 0000000..0db6a68 --- /dev/null +++ b/rpl/libnsysnet/Makefile @@ -0,0 +1,2 @@ +-include ../common/rules.mk +-include ../../common/rules.mk diff --git a/rpl/libnsysnet/config.h b/rpl/libnsysnet/config.h new file mode 100644 index 0000000..3483aa4 --- /dev/null +++ b/rpl/libnsysnet/config.h @@ -0,0 +1 @@ +#define LIBRARY_NAME "nsysnet" diff --git a/rpl/libnsysnet/exports.h b/rpl/libnsysnet/exports.h new file mode 100644 index 0000000..ed4743b --- /dev/null +++ b/rpl/libnsysnet/exports.h @@ -0,0 +1,39 @@ +// nsysnet/socket.h +EXPORT(socket_lib_init); +EXPORT(socket); +EXPORT(socketclose); +EXPORT(connect); +EXPORT(bind); +EXPORT(listen); +EXPORT(accept); +EXPORT(send); +EXPORT(recv); +EXPORT(sendto); +EXPORT(setsockopt); +EXPORT(recvfrom); +EXPORT(recvfrom_ex); +EXPORT(recvfrom_multi); +EXPORT(sendto_multi); +EXPORT(sendto_multi_ex); +EXPORT(shutdown); +EXPORT(inet_aton); +EXPORT(inet_ntoa_r); +EXPORT(inet_ntop); +EXPORT(inet_pton); +EXPORT(getpeername); +EXPORT(getsockname); +EXPORT(getsockopt); +EXPORT(setsocketlasterr); +EXPORT(select); +EXPORT(setsocklibopt); +EXPORT(getsocklibopt); +EXPORT(somemopt); +EXPORT(ntohl); +EXPORT(htonl); +EXPORT(ntohs); +EXPORT(htons); +EXPORT(icmp_create_handle); +EXPORT(icmp_close_handle); +EXPORT(icmp_ping); +EXPORT(icmp_cancel); +EXPORT(icmp_last_code_type);