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