Skip to content

Commit

Permalink
sys: net: pnet: turn into dummy implementation based on gnrc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Aug 5, 2015
1 parent 30f1eb6 commit fea8bae
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 101 deletions.
4 changes: 2 additions & 2 deletions sys/posix/pnet/include/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <inttypes.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "ipv6.h"
#include "net/ng_ipv6.h"
#include "socket_base/socket.h"

#ifdef __cplusplus
Expand All @@ -49,7 +49,7 @@ struct in6_addr {
/**
* Private RIOT-internal data, needs not to be touched by the user.
*/
ipv6_addr_t __in6_u;
ng_ipv6_addr_t __in6_u;

/**
* IPv6 Address represented as sequence of 8-bit numbers. Member of
Expand Down
152 changes: 53 additions & 99 deletions sys/posix/pnet/sys_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
* @file
* @brief Providing implementation for POSIX socket wrapper.
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @todo
*/
#include <errno.h>

#include "socket_base/socket.h"
#include "fd.h"

#include "sys/socket.h"

int flagless_send(int fd, const void *buf, size_t len)
{
return (int)socket_base_send(fd, buf, (uint32_t)len, 0);
(void)fd;
(void)buf;
(void)len;

return -1;
}

int flagless_recv(int fd, void *buf, size_t len)
Expand All @@ -31,66 +32,40 @@ int flagless_recv(int fd, void *buf, size_t len)

int socket(int domain, int type, int protocol)
{
int internal_socket = socket_base_socket(domain, type, protocol);
(void)domain;
(void)type;
(void)protocol;

if (internal_socket < 0) {
errno = ENFILE;
return -1;
}

return fd_new(internal_socket, flagless_recv, flagless_send,
socket_base_close);
return -1;
}


#define sock_func_wrapper(func, sockfd, ...) \
((fd_get(sockfd)) ? \
func(fd_get(sockfd)->internal_fd, __VA_ARGS__) : \
(errno = EBADF, -1))

int accept(int socket, struct sockaddr *restrict address,
socklen_t *restrict address_len)
{
int res = sock_func_wrapper(socket_base_accept, socket,
(sockaddr6_t *)address,
(socklen_t *)address_len);

if (res < 0) {
// transport_layer needs more granular error handling
errno = EOPNOTSUPP;
return -1;
}

return fd_new(res, flagless_recv, flagless_send,
socket_base_close);
(void)socket;
(void)address;
(void)address_len;

return -1;
}

int bind(int socket, const struct sockaddr *address, socklen_t address_len)
{
int res = sock_func_wrapper(socket_base_bind, socket,
(sockaddr6_t *)address, address_len);

if (res < 0) {
// transport_layer needs more granular error handling
errno = EOPNOTSUPP;
return -1;
}
(void)socket;
(void)address;
(void)address_len;

return res;
return -1;
}

int connect(int socket, const struct sockaddr *address, socklen_t address_len)
{
int res = sock_func_wrapper(socket_base_connect, socket,
(sockaddr6_t *)address, address_len);

if (res < 0) {
// transport_layer needs more granular error handling
errno = ECONNREFUSED;
return -1;
}
(void)socket;
(void)address;
(void)address_len;

return res;
return -1;
}

int getsockopt(int socket, int level, int option_name,
Expand All @@ -108,78 +83,57 @@ int getsockopt(int socket, int level, int option_name,

int listen(int socket, int backlog)
{
int res = sock_func_wrapper(socket_base_listen, socket, backlog);
(void)socket;
(void)backlog;

if (res < 0) {
// transport_layer needs more granular error handling
errno = ECONNREFUSED;
return -1;
}

return res;
return -1;
}

ssize_t recv(int socket, void *buffer, size_t length, int flags)
{
int32_t res = sock_func_wrapper(socket_base_recv, socket, buffer,
(uint32_t) length, flags);

if (res < 0) {
// transport_layer needs more granular error handling
errno = ENOTCONN;
return -1;
}
(void)socket;
(void)buffer;
(void)length;
(void)flags;

return (ssize_t)res;
return -1;
}

ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags,
struct sockaddr *restrict address,
socklen_t *restrict address_len)
{
int32_t res = sock_func_wrapper(socket_base_recvfrom, socket, buffer,
(uint32_t) length, flags,
(sockaddr6_t *)address,
(socklen_t *)address_len);

if (res < 0) {
// transport_layer needs more granular error handling
errno = ENOTCONN;
return -1;
}

return (ssize_t)res;
(void)socket;
(void)buffer;
(void)length;
(void)flags;
(void)address;
(void)address_len;

return -1;
}

ssize_t send(int socket, const void *buffer, size_t length, int flags)
{
int32_t res = sock_func_wrapper(socket_base_send, socket, buffer,
(uint32_t) length, flags);

if (res < 0) {
// transport_layer needs more granular error handling
errno = ENOTCONN;
return -1;
}

return (ssize_t)res;
(void)socket;
(void)buffer;
(void)length;
(void)flags;
return -1;
}

ssize_t sendto(int socket, const void *message, size_t length, int flags,
const struct sockaddr *dest_addr, socklen_t dest_len)
{
int32_t res = sock_func_wrapper(socket_base_sendto, socket, message,
(uint32_t) length, flags,
(sockaddr6_t *)dest_addr,
(socklen_t)dest_len);

if (res < 0) {
// transport_layer needs more granular error handling
errno = ENOTCONN;
return -1;
}

return (ssize_t)res;
// TODO
(void)socket;
(void)message;
(void)length;
(void)flags;
(void)dest_addr;
(void)dest_len;

return -1;
}

int setsockopt(int socket, int level, int option_name, const void *option_value,
Expand Down

0 comments on commit fea8bae

Please sign in to comment.