Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/nanostack-libservice/mbed-client-libservice/ip6string.h@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | /* |
leothedragon | 0:8f0bb79ddd48 | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
leothedragon | 0:8f0bb79ddd48 | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:8f0bb79ddd48 | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | * You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | * |
leothedragon | 0:8f0bb79ddd48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | * |
leothedragon | 0:8f0bb79ddd48 | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:8f0bb79ddd48 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | * limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | */ |
leothedragon | 0:8f0bb79ddd48 | 16 | #ifndef IP6STRING_H |
leothedragon | 0:8f0bb79ddd48 | 17 | #define IP6STRING_H |
leothedragon | 0:8f0bb79ddd48 | 18 | #ifdef __cplusplus |
leothedragon | 0:8f0bb79ddd48 | 19 | extern "C" { |
leothedragon | 0:8f0bb79ddd48 | 20 | #endif |
leothedragon | 0:8f0bb79ddd48 | 21 | |
leothedragon | 0:8f0bb79ddd48 | 22 | #include "ns_types.h" |
leothedragon | 0:8f0bb79ddd48 | 23 | |
leothedragon | 0:8f0bb79ddd48 | 24 | #define MAX_IPV6_STRING_LEN_WITH_TRAILING_NULL 40 |
leothedragon | 0:8f0bb79ddd48 | 25 | |
leothedragon | 0:8f0bb79ddd48 | 26 | /** |
leothedragon | 0:8f0bb79ddd48 | 27 | * Print binary IPv6 address to a string. |
leothedragon | 0:8f0bb79ddd48 | 28 | * |
leothedragon | 0:8f0bb79ddd48 | 29 | * String must contain enough room for full address, 40 bytes exact. |
leothedragon | 0:8f0bb79ddd48 | 30 | * IPv4 tunneling addresses are not covered. |
leothedragon | 0:8f0bb79ddd48 | 31 | * |
leothedragon | 0:8f0bb79ddd48 | 32 | * \param ip6addr IPv6 address. |
leothedragon | 0:8f0bb79ddd48 | 33 | * \param p buffer to write string to. |
leothedragon | 0:8f0bb79ddd48 | 34 | * \return length of generated string excluding the terminating null character |
leothedragon | 0:8f0bb79ddd48 | 35 | */ |
leothedragon | 0:8f0bb79ddd48 | 36 | uint_fast8_t ip6tos(const void *ip6addr, char *p); |
leothedragon | 0:8f0bb79ddd48 | 37 | |
leothedragon | 0:8f0bb79ddd48 | 38 | /** |
leothedragon | 0:8f0bb79ddd48 | 39 | * Print binary IPv6 prefix to a string. |
leothedragon | 0:8f0bb79ddd48 | 40 | * |
leothedragon | 0:8f0bb79ddd48 | 41 | * String buffer `p` must contain enough room for a full address and prefix length, 44 bytes exact. |
leothedragon | 0:8f0bb79ddd48 | 42 | * Bits in the `prefix` buffer beyond `prefix_len` bits are not shown and only the bytes containing the |
leothedragon | 0:8f0bb79ddd48 | 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 |
leothedragon | 0:8f0bb79ddd48 | 44 | * read (thus if `prefix_len` is zero, `prefix` can be NULL). |
leothedragon | 0:8f0bb79ddd48 | 45 | * `prefix_len` must be 0 to 128. |
leothedragon | 0:8f0bb79ddd48 | 46 | * |
leothedragon | 0:8f0bb79ddd48 | 47 | * \param prefix IPv6 prefix. |
leothedragon | 0:8f0bb79ddd48 | 48 | * \param prefix_len length of `prefix` in bits. |
leothedragon | 0:8f0bb79ddd48 | 49 | * \param p buffer to write string to. |
leothedragon | 0:8f0bb79ddd48 | 50 | * \return length of generated string excluding the terminating null character, or 0 for an error, such as 'prefix_len' > 128 |
leothedragon | 0:8f0bb79ddd48 | 51 | */ |
leothedragon | 0:8f0bb79ddd48 | 52 | uint_fast8_t ip6_prefix_tos(const void *prefix, uint_fast8_t prefix_len, char *p); |
leothedragon | 0:8f0bb79ddd48 | 53 | |
leothedragon | 0:8f0bb79ddd48 | 54 | /** |
leothedragon | 0:8f0bb79ddd48 | 55 | * Convert numeric IPv6 address string to a binary. |
leothedragon | 0:8f0bb79ddd48 | 56 | * |
leothedragon | 0:8f0bb79ddd48 | 57 | * IPv4 tunneling addresses are not covered. |
leothedragon | 0:8f0bb79ddd48 | 58 | * |
leothedragon | 0:8f0bb79ddd48 | 59 | * \param ip6addr IPv6 address in string format. |
leothedragon | 0:8f0bb79ddd48 | 60 | * \param len Lenght of ipv6 string, maximum of 41. |
leothedragon | 0:8f0bb79ddd48 | 61 | * \param dest buffer for address. MUST be 16 bytes. Filled with 0 on error. |
leothedragon | 0:8f0bb79ddd48 | 62 | * \return boolean set to true if conversion succeed, false if it didn't |
leothedragon | 0:8f0bb79ddd48 | 63 | */ |
leothedragon | 0:8f0bb79ddd48 | 64 | bool stoip6(const char *ip6addr, size_t len, void *dest); |
leothedragon | 0:8f0bb79ddd48 | 65 | /** |
leothedragon | 0:8f0bb79ddd48 | 66 | * Find out numeric IPv6 address prefix length. |
leothedragon | 0:8f0bb79ddd48 | 67 | * |
leothedragon | 0:8f0bb79ddd48 | 68 | * \param ip6addr IPv6 address in string format |
leothedragon | 0:8f0bb79ddd48 | 69 | * \return prefix length or 0 if it not given |
leothedragon | 0:8f0bb79ddd48 | 70 | */ |
leothedragon | 0:8f0bb79ddd48 | 71 | unsigned char sipv6_prefixlength(const char *ip6addr); |
leothedragon | 0:8f0bb79ddd48 | 72 | |
leothedragon | 0:8f0bb79ddd48 | 73 | /** |
leothedragon | 0:8f0bb79ddd48 | 74 | * Convert numeric IPv6 address string with prefix to a binary. |
leothedragon | 0:8f0bb79ddd48 | 75 | * |
leothedragon | 0:8f0bb79ddd48 | 76 | * IPv4 tunneling addresses are not covered. |
leothedragon | 0:8f0bb79ddd48 | 77 | * |
leothedragon | 0:8f0bb79ddd48 | 78 | * \param ip6addr IPv6 address in string format. |
leothedragon | 0:8f0bb79ddd48 | 79 | * \param dest buffer for address. MUST be 16 bytes. |
leothedragon | 0:8f0bb79ddd48 | 80 | * \param prefix_len_out length of prefix, is set to -1 if no prefix given |
leothedragon | 0:8f0bb79ddd48 | 81 | * |
leothedragon | 0:8f0bb79ddd48 | 82 | * \return 0 on success, negative value otherwise. prefix_len_out contains prefix length. |
leothedragon | 0:8f0bb79ddd48 | 83 | */ |
leothedragon | 0:8f0bb79ddd48 | 84 | int stoip6_prefix(const char *ip6addr, void *dest, int_fast16_t *prefix_len_out); |
leothedragon | 0:8f0bb79ddd48 | 85 | |
leothedragon | 0:8f0bb79ddd48 | 86 | #ifdef __cplusplus |
leothedragon | 0:8f0bb79ddd48 | 87 | } |
leothedragon | 0:8f0bb79ddd48 | 88 | #endif |
leothedragon | 0:8f0bb79ddd48 | 89 | #endif |