Merge pull request #7633 from kaspar030/refactor_posix_inet_header
sys/posix: factor inet_*to* from header into .c file
This commit is contained in:
commit
8bf59b80c2
@ -414,6 +414,8 @@ ifneq (,$(filter posix_sockets,$(USEMODULE)))
|
|||||||
USEMODULE += bitfield
|
USEMODULE += bitfield
|
||||||
USEMODULE += random
|
USEMODULE += random
|
||||||
USEMODULE += vfs
|
USEMODULE += vfs
|
||||||
|
USEMODULE += posix
|
||||||
|
USEMODULE += xtimer
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter rtt_stdio,$(USEMODULE)))
|
ifneq (,$(filter rtt_stdio,$(USEMODULE)))
|
||||||
@ -429,8 +431,10 @@ ifneq (,$(filter isrpipe,$(USEMODULE)))
|
|||||||
USEMODULE += tsrb
|
USEMODULE += tsrb
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter posix,$(USEMODULE)))
|
ifneq (,$(filter shell_commands,$(USEMODULE)))
|
||||||
USEMODULE += xtimer
|
ifneq (,$(filter fib,$(USEMODULE)))
|
||||||
|
USEMODULE += posix
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
|
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
|
||||||
|
|||||||
@ -57,7 +57,6 @@ PSEUDOMODULES += newlib_gnu_source
|
|||||||
PSEUDOMODULES += newlib_nano
|
PSEUDOMODULES += newlib_nano
|
||||||
PSEUDOMODULES += openthread
|
PSEUDOMODULES += openthread
|
||||||
PSEUDOMODULES += pktqueue
|
PSEUDOMODULES += pktqueue
|
||||||
PSEUDOMODULES += posix
|
|
||||||
PSEUDOMODULES += printf_float
|
PSEUDOMODULES += printf_float
|
||||||
PSEUDOMODULES += prng
|
PSEUDOMODULES += prng
|
||||||
PSEUDOMODULES += prng_%
|
PSEUDOMODULES += prng_%
|
||||||
|
|||||||
1
sys/posix/Makefile
Normal file
1
sys/posix/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include $(RIOTBASE)/Makefile.base
|
||||||
@ -23,14 +23,7 @@
|
|||||||
#ifndef ARPA_INET_H
|
#ifndef ARPA_INET_H
|
||||||
#define ARPA_INET_H
|
#define ARPA_INET_H
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "byteorder.h"
|
|
||||||
#include "net/af.h"
|
#include "net/af.h"
|
||||||
#include "net/ipv4/addr.h"
|
|
||||||
#include "net/ipv6/addr.h"
|
|
||||||
#include "sys/bytes.h"
|
#include "sys/bytes.h"
|
||||||
#include "netinet/in.h"
|
#include "netinet/in.h"
|
||||||
|
|
||||||
@ -42,14 +35,14 @@ extern "C" {
|
|||||||
* @brief Size in byte of an IPv4 address
|
* @brief Size in byte of an IPv4 address
|
||||||
*/
|
*/
|
||||||
#ifndef INADDRSZ
|
#ifndef INADDRSZ
|
||||||
#define INADDRSZ (sizeof(ipv4_addr_t))
|
#define INADDRSZ (4)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Size in byte of an IPv6 address
|
* @brief Size in byte of an IPv6 address
|
||||||
*/
|
*/
|
||||||
#ifndef IN6ADDRSZ
|
#ifndef IN6ADDRSZ
|
||||||
#define IN6ADDRSZ (sizeof(ipv6_addr_t))
|
#define IN6ADDRSZ (16)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,35 +59,8 @@ extern "C" {
|
|||||||
* @return NULL, if @p size was smaller than needed
|
* @return NULL, if @p size was smaller than needed
|
||||||
* @return NULL, if @p src or @p dst was NULL
|
* @return NULL, if @p src or @p dst was NULL
|
||||||
*/
|
*/
|
||||||
static inline const char *inet_ntop(int af, const void *restrict src, char *restrict dst,
|
const char *inet_ntop(int af, const void *restrict src, char *restrict dst,
|
||||||
socklen_t size)
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts an IP address string representation to a byte-represented
|
* @brief Converts an IP address string representation to a byte-represented
|
||||||
@ -110,31 +76,7 @@ static inline const char *inet_ntop(int af, const void *restrict src, char *rest
|
|||||||
* @return 0, if @p src was malformed or input pointers were NULL.
|
* @return 0, if @p src was malformed or input pointers were NULL.
|
||||||
* @return -1, if @p af is not supported.
|
* @return -1, if @p af is not supported.
|
||||||
*/
|
*/
|
||||||
static inline int inet_pton(int af, const char *src, void *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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,8 @@
|
|||||||
#ifndef SYS_BYTES_H
|
#ifndef SYS_BYTES_H
|
||||||
#define SYS_BYTES_H
|
#define SYS_BYTES_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
69
sys/posix/inet.c
Normal file
69
sys/posix/inet.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user