1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/posix/inet/inet.c
Juan Carrano 6b766c3cd3 sys/posix: make posix module provide only headers.
The build system contains several instances of
 INCLUDES += -I$(RIOTBASE)/sys/posix/include

This is bypassing the module management system, by directly accesing
headers without depending on a module. The module is the posix module.

That line is also added when one of the posix_* modules is requested.

According to the docs, the posix module provides headers only, but in
reality there is also inet.c.

This patch:

- Moves `inet.c` into `posix_inet`, leaving `posix` as a headers-only
  module.
- Rename `posix` as `posix_headers` to make it clear the module only
  includes headers.
- Makes `posix_*` modules depend on `posix_headers`, thus removing the
  explicit `INCLUDES+=...` in `sys/Makefile.include`.
- Ocurrences of `INCLUDES+=...` are replaced by an explicit dependency
  on `posix_headers`.
2019-03-20 12:57:13 +01:00

70 lines
1.6 KiB
C

/*
* Copyright (C) 2013-15 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include <arpa/inet.h>
#include <errno.h>
#include "net/ipv4/addr.h"
#include "net/ipv6/addr.h"
const char *inet_ntop(int af, const void *restrict src, char *restrict dst,
socklen_t size)
{
switch (af) {
#ifdef MODULE_IPV4_ADDR
case AF_INET:
if (ipv4_addr_to_str(dst, src, (size_t)size) == NULL) {
errno = ENOSPC;
return NULL;
}
break;
#endif
#ifdef MODULE_IPV6_ADDR
case AF_INET6:
if (ipv6_addr_to_str(dst, src, (size_t)size) == NULL) {
errno = ENOSPC;
return NULL;
}
break;
#endif
default:
(void)src;
(void)dst;
(void)size;
errno = EAFNOSUPPORT;
return NULL;
}
return dst;
}
int inet_pton(int af, const char *src, void *dst)
{
switch (af) {
#ifdef MODULE_IPV4_ADDR
case AF_INET:
if (ipv4_addr_from_str(dst, src) == NULL) {
return 0;
}
break;
#endif
#ifdef MODULE_IPV6_ADDR
case AF_INET6:
if (ipv6_addr_from_str(dst, src) == NULL) {
return 0;
}
break;
#endif
default:
(void)src;
(void)dst;
errno = EAFNOSUPPORT;
return -1;
}
return 1;
}