Toyomasa Watarai / simple-mbed-cloud-client

Dependents:  

Committer:
MACRUM
Date:
Mon Jul 02 06:30:39 2018 +0000
Revision:
0:276e7a263c35
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:276e7a263c35 1 /*
MACRUM 0:276e7a263c35 2 * Copyright (c) 2014-2015 ARM Limited. All rights reserved.
MACRUM 0:276e7a263c35 3 * SPDX-License-Identifier: Apache-2.0
MACRUM 0:276e7a263c35 4 * Licensed under the Apache License, Version 2.0 (the License); you may
MACRUM 0:276e7a263c35 5 * not use this file except in compliance with the License.
MACRUM 0:276e7a263c35 6 * You may obtain a copy of the License at
MACRUM 0:276e7a263c35 7 *
MACRUM 0:276e7a263c35 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:276e7a263c35 9 *
MACRUM 0:276e7a263c35 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:276e7a263c35 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
MACRUM 0:276e7a263c35 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:276e7a263c35 13 * See the License for the specific language governing permissions and
MACRUM 0:276e7a263c35 14 * limitations under the License.
MACRUM 0:276e7a263c35 15 */
MACRUM 0:276e7a263c35 16 #ifndef IP6STRING_H
MACRUM 0:276e7a263c35 17 #define IP6STRING_H
MACRUM 0:276e7a263c35 18 #ifdef __cplusplus
MACRUM 0:276e7a263c35 19 extern "C" {
MACRUM 0:276e7a263c35 20 #endif
MACRUM 0:276e7a263c35 21
MACRUM 0:276e7a263c35 22 #include "ns_types.h"
MACRUM 0:276e7a263c35 23
MACRUM 0:276e7a263c35 24 #define MAX_IPV6_STRING_LEN_WITH_TRAILING_NULL 40
MACRUM 0:276e7a263c35 25
MACRUM 0:276e7a263c35 26 /**
MACRUM 0:276e7a263c35 27 * Print binary IPv6 address to a string.
MACRUM 0:276e7a263c35 28 *
MACRUM 0:276e7a263c35 29 * String must contain enough room for full address, 40 bytes exact.
MACRUM 0:276e7a263c35 30 * IPv4 tunneling addresses are not covered.
MACRUM 0:276e7a263c35 31 *
MACRUM 0:276e7a263c35 32 * \param ip6addr IPv6 address.
MACRUM 0:276e7a263c35 33 * \param p buffer to write string to.
MACRUM 0:276e7a263c35 34 * \return length of generated string excluding the terminating null character
MACRUM 0:276e7a263c35 35 */
MACRUM 0:276e7a263c35 36 uint_fast8_t ip6tos(const void *ip6addr, char *p);
MACRUM 0:276e7a263c35 37
MACRUM 0:276e7a263c35 38 /**
MACRUM 0:276e7a263c35 39 * Print binary IPv6 prefix to a string.
MACRUM 0:276e7a263c35 40 *
MACRUM 0:276e7a263c35 41 * String buffer `p` must contain enough room for a full address and prefix length, 44 bytes exact.
MACRUM 0:276e7a263c35 42 * Bits in the `prefix` buffer beyond `prefix_len` bits are not shown and only the bytes containing the
MACRUM 0:276e7a263c35 43 * prefix bits are read. I.e. for a 20 bit prefix 3 bytes are read, and for a 0 bit prefix 0 bytes are
MACRUM 0:276e7a263c35 44 * read (thus if `prefix_len` is zero, `prefix` can be NULL).
MACRUM 0:276e7a263c35 45 * `prefix_len` must be 0 to 128.
MACRUM 0:276e7a263c35 46 *
MACRUM 0:276e7a263c35 47 * \param prefix IPv6 prefix.
MACRUM 0:276e7a263c35 48 * \param prefix_len length of `prefix` in bits.
MACRUM 0:276e7a263c35 49 * \param p buffer to write string to.
MACRUM 0:276e7a263c35 50 * \return length of generated string excluding the terminating null character, or 0 for an error, such as 'prefix_len' > 128
MACRUM 0:276e7a263c35 51 */
MACRUM 0:276e7a263c35 52 uint_fast8_t ip6_prefix_tos(const void *prefix, uint_fast8_t prefix_len, char *p);
MACRUM 0:276e7a263c35 53
MACRUM 0:276e7a263c35 54 /**
MACRUM 0:276e7a263c35 55 * Convert numeric IPv6 address string to a binary.
MACRUM 0:276e7a263c35 56 *
MACRUM 0:276e7a263c35 57 * IPv4 tunneling addresses are not covered.
MACRUM 0:276e7a263c35 58 *
MACRUM 0:276e7a263c35 59 * \param ip6addr IPv6 address in string format.
MACRUM 0:276e7a263c35 60 * \param len Lenght of ipv6 string, maximum of 41.
MACRUM 0:276e7a263c35 61 * \param dest buffer for address. MUST be 16 bytes.
MACRUM 0:276e7a263c35 62 */
MACRUM 0:276e7a263c35 63 void stoip6(const char *ip6addr, size_t len, void *dest);
MACRUM 0:276e7a263c35 64 /**
MACRUM 0:276e7a263c35 65 * Find out numeric IPv6 address prefix length.
MACRUM 0:276e7a263c35 66 *
MACRUM 0:276e7a263c35 67 * \param ip6addr IPv6 address in string format
MACRUM 0:276e7a263c35 68 * \return prefix length or 0 if it not given
MACRUM 0:276e7a263c35 69 */
MACRUM 0:276e7a263c35 70 unsigned char sipv6_prefixlength(const char *ip6addr);
MACRUM 0:276e7a263c35 71
MACRUM 0:276e7a263c35 72 #ifdef __cplusplus
MACRUM 0:276e7a263c35 73 }
MACRUM 0:276e7a263c35 74 #endif
MACRUM 0:276e7a263c35 75 #endif