diff --git a/sys/posix/pnet/include/arpa/inet.h b/sys/posix/pnet/include/arpa/inet.h new file mode 100644 index 0000000000..192cecaccf --- /dev/null +++ b/sys/posix/pnet/include/arpa/inet.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @addtogroup pnet + * @{ + */ + +/** + * @file arpa/inet.h + * @brief Definitions for internet operations + * @see + * The Open Group Base Specifications Issue 7, + * + * + * @author Freie Universität Berlin + * @author Martin Lenders + */ +#ifndef ARPA_INET_H +#define ARPA_INET_H + +#include + +#include "net_help.h" +#include "inet_ntop.h" +#include "inet_pton.h" + +typedef uint16_t in_port_t; ///< Internet port type +typedef uint32_t in_addr_t; ///< IPv4 address type + +#define INET_ADDRSTRLEN 16 ///< Length of the string form for IPv4. +#define INET6_ADDRSTRLEN 46 ///< Length of the string form for IPv6. + +/** + * IPv4 address structure type. + */ +struct in_addr { + in_addr_t s_addr; ///< an IPv4 address +}; + +/** + * @brief Convert values between host and network byte order. + * + * @see + * The Open Group Base Specification Issue 7, htonl + * + * + * @param[in] hostlong A 32 bit number. + * @return The argument value converted from host to network byte + * order. + */ +#define htonl(hostlong) HTONL(hostlong) + +/** + * @brief Convert values between host and network byte order. + * + * @see + * The Open Group Base Specification Issue 7, htons + * + * + * @param[in] hostlong A 16 bit number. + * @return The argument value converted from host to network byte + * order. + */ +#define htons(hostshort) HTONS(hostshort) + +/** + * @brief Convert values between host and network byte order. + * + * @see + * The Open Group Base Specification Issue 7, ntohl + * + * + * @param[in] hostlong A 32-bit integer number. + * @return The argument value converted from network to host byte + * order. + */ +#define ntohl(netlong) NTOHL(netlong) + +/** + * @brief Convert values between host and network byte order. + * + * @see + * The Open Group Base Specification Issue 7, ntohs + * + * + * @param[in] hostlong A 16-bit integer number. + * @return The argument value converted from network to host byte + * order. + */ +#define ntohs(netshort) NTOHS(netshort) + +/** + * @} + */ +#endif /* ARPA_INET_H */ diff --git a/sys/posix/pnet/include/netinet/in.h b/sys/posix/pnet/include/netinet/in.h new file mode 100644 index 0000000000..d4244a90bf --- /dev/null +++ b/sys/posix/pnet/include/netinet/in.h @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @addtogroup pnet + * @{ + */ + +/** + * @file netinet/in.h + * @brief Main socket header + * @see + * The Open Group Base Specifications Issue 7, + * + * + * @author Freie Universität Berlin + * @author Martin Lenders + */ +#ifndef _NETINET_IN_H +#define _NETINET_IN_H + +#include +#include +#include +#include "ipv6.h" +#include "destiny/socket.h" + +/** + * IPv4 socket address type. + */ +struct sockaddr_in { + sa_family_t sin_family; ///< Protocol family, always AF_INET. + in_port_t sin_port; ///< Port number + struct in_addr sin_addr; ///< IPv4 address +}; + +/** + * IPv6 address structure type. + */ +struct in6_addr { + /** + * Private RIOT-internal data, needs not to be touched by the user. + */ + ipv6_addr_t __in6_u; + + /** + * IPv6 Address represented as sequence of 8-bit numbers. Member of + * struct in6_addr. + */ +#define s6_addr __in6_u.uint8 + + /** + * IPv6 Address represented as sequence of 16-bit numbers. Member of + * struct in6_addr. + */ +#define s6_addr16 __in6_u.uint16 + + /** + * IPv6 Address represented as sequence of 32-bit numbers. Member of + * struct in6_addr. + */ +#define s6_addr32 __in6_u.uint32 +}; + +/** + * IPv6 socket address type. + */ +struct sockaddr_in6 { + /** + * Private RIOT-internal data, needs not to be touched by the user. + */ + sockaddr6_t __in6_a; + + /** + * Protocol family, always AF_INET6. Member of struct sockaddr_in6 + */ +#define sin6_family __in6_a.sin6_family + + /** + * Port number. Member of struct sockaddr_in6 + */ +#define sin6_port __in6_a.sin6_port + + /** + * IPv6 traffic class and flow information. Member of struct sockaddr_in6 + */ +#define sin6_flowinfo __in6_a.sin6_flowinfo + + /** + * IPv6 address. Member of struct sockaddr_in6 + */ +#define sin6_addr __in6_a.sin6_addr + + /** + * Set of interfaces for a scope. + */ + uint32_t sin6_scope_id; +}; + +/** + * IPv6 wildcard address. + */ +#define IN6ADDR_ANY_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} + +/** + * IPv6 loopback address. + */ +#define IN6ADDR_LOOPBACK_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}} + +/** + * IPv6 socket address for the wildcard address. + */ +extern const struct sockaddr_in6 in6addr_any; + +/** + * IPv6 socket address for the loopback address. + */ +extern const struct sockaddr_in6 in6addr_loopback; + +/** + * IPv4 local host address. + */ +#define INADDR_ANY {(in_addr_t)0x00000000} + +/** + * IPv4 broadcast address. + */ +#define INADDR_BROADCAST {(in_addr_t)0xffffffff} + +/** + * Multicast hop limit option name for getsockopt() or setsockopt() + * + * @see + * The Open Group Base Specification Issue 7, getsockopt + * + * @see + * The Open Group Base Specification Issue 7, setsockopt + * + */ +#define IPV6_MULTICAST_HOPS 0x12 + +/** + * Test for IPv6 multicast address. + * + * @param[in] a An IPv6 address. + * @return 1 if *a* is an multicast address, 0 if not. + */ +#define IN6_IS_ADDR_MULTICAST(a) (((const uint8_t *) (a))[0] == 0xff) + +/** + * @} + */ +#endif /* _NETINET_IN_H */ diff --git a/sys/posix/pnet/netinet_in.c b/sys/posix/pnet/netinet_in.c new file mode 100644 index 0000000000..27e3340de7 --- /dev/null +++ b/sys/posix/pnet/netinet_in.c @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ +#include + +const struct sockaddr_in6 in6addr_any = {{AF_INET6, 0, 0, IN6ADDR_ANY_INIT}, 0}; +const struct sockaddr_in6 in6addr_loopback = {{ + AF_INET6, 0, 0, IN6ADDR_LOOPBACK_INIT + }, 0 +};