<commit_before>/** @file
 @brief Network stack private header

 This is not to be included by the application.
 */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <errno.h>

extern void net_nbuf_init(void);
extern int net_if_init(void);
extern void net_context_init(void);

extern char *net_byte_to_hex(uint8_t *ptr, uint8_t byte, char base, bool pad);
extern char *net_sprint_ll_addr_buf(uint8_t *ll, uint8_t ll_len,
				    char *buf, int buflen);
extern char *net_sprint_ip_addr_buf(uint8_t *ip, int ip_len,
				    char *buf, int buflen);

#if NET_DEBUG > 0
static inline char *net_sprint_ll_addr(uint8_t *ll, uint8_t ll_len)
{
	static char buf[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")];

	return net_sprint_ll_addr_buf(ll, ll_len, (char *)buf, sizeof(buf));
}

static inline char *net_sprint_ip_addr_ptr(uint8_t *ptr, uint8_t len)
{
	static char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];

	return net_sprint_ip_addr_buf(ptr, len, (char *)buf, sizeof(buf));
}

static inline char *net_sprint_ipv6_addr(struct in6_addr *addr)
{
#if defined(CONFIG_NET_IPV6)
	return net_sprint_ip_addr_ptr(addr->s6_addr, 16);
#else
	return NULL;
#endif
}

static inline char *net_sprint_ipv4_addr(struct in_addr *addr)
{
#if defined(CONFIG_NET_IPV4)
	return net_sprint_ip_addr_ptr(addr->s4_addr, 4);
#else
	return NULL;
#endif
}

static inline char *net_sprint_ip_addr(struct net_addr *addr)
{
	switch (addr->family) {
	case AF_INET6:
#if defined(CONFIG_NET_IPV6)
		return net_sprint_ipv6_addr(&addr->in6_addr);
#else
		break;
#endif
	case AF_INET:
#if defined(CONFIG_NET_IPV4)
		return net_sprint_ipv4_addr(&addr->in_addr);
#else
		break;
#endif
	default:
		break;
	}

	return NULL;
}

#else /* NET_DEBUG */

static inline char *net_sprint_ll_addr(uint8_t *ll, uint8_t ll_len)
{
	return NULL;
}

static inline char *net_sprint_ip_addr_ptr(uint8_t *ptr, uint8_t len)
{
	return NULL;
}

static inline char *net_sprint_ipv6_addr(struct in6_addr *addr)
{
	return NULL;
}

static inline char *net_sprint_ipv4_addr(struct in_addr *addr)
{
	return NULL;
}

static inline char *net_sprint_ip_addr(struct net_addr *addr)
{
	return NULL;
}
#endif /* NET_DEBUG */<commit_msg>net: yaip: Add net_hexdump() utility to print network data<commit_after>/** @file
 @brief Network stack private header

 This is not to be included by the application.
 */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <errno.h>

extern void net_nbuf_init(void);
extern int net_if_init(void);
extern void net_context_init(void);

extern char *net_byte_to_hex(uint8_t *ptr, uint8_t byte, char base, bool pad);
extern char *net_sprint_ll_addr_buf(uint8_t *ll, uint8_t ll_len,
				    char *buf, int buflen);
extern char *net_sprint_ip_addr_buf(uint8_t *ip, int ip_len,
				    char *buf, int buflen);

#if NET_DEBUG > 0
static inline char *net_sprint_ll_addr(uint8_t *ll, uint8_t ll_len)
{
	static char buf[sizeof("xx:xx:xx:xx:xx:xx:xx:xx")];

	return net_sprint_ll_addr_buf(ll, ll_len, (char *)buf, sizeof(buf));
}

static inline char *net_sprint_ip_addr_ptr(uint8_t *ptr, uint8_t len)
{
	static char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];

	return net_sprint_ip_addr_buf(ptr, len, (char *)buf, sizeof(buf));
}

static inline char *net_sprint_ipv6_addr(struct in6_addr *addr)
{
#if defined(CONFIG_NET_IPV6)
	return net_sprint_ip_addr_ptr(addr->s6_addr, 16);
#else
	return NULL;
#endif
}

static inline char *net_sprint_ipv4_addr(struct in_addr *addr)
{
#if defined(CONFIG_NET_IPV4)
	return net_sprint_ip_addr_ptr(addr->s4_addr, 4);
#else
	return NULL;
#endif
}

static inline char *net_sprint_ip_addr(struct net_addr *addr)
{
	switch (addr->family) {
	case AF_INET6:
#if defined(CONFIG_NET_IPV6)
		return net_sprint_ipv6_addr(&addr->in6_addr);
#else
		break;
#endif
	case AF_INET:
#if defined(CONFIG_NET_IPV4)
		return net_sprint_ipv4_addr(&addr->in_addr);
#else
		break;
#endif
	default:
		break;
	}

	return NULL;
}

static inline void net_hexdump(const char *str, const uint8_t *packet, size_t length)
{
	int n = 0;

	if (!length) {
		SYS_LOG_DBG("%s zero-length packet", str);
		return;
	}

	while (length--) {
		if (n % 16 == 0) {
			printf("%s %08X ", str, n);
		}

		printf("%02X ", *packet++);

		n++;
		if (n % 8 == 0) {
			if (n % 16 == 0) {
				printf("\n");
			} else {
				printf(" ");
			}
		}
	}

	if (n % 16) {
		printf("\n");
	}
}

#else /* NET_DEBUG */

static inline char *net_sprint_ll_addr(uint8_t *ll, uint8_t ll_len)
{
	return NULL;
}

static inline char *net_sprint_ip_addr_ptr(uint8_t *ptr, uint8_t len)
{
	return NULL;
}

static inline char *net_sprint_ipv6_addr(struct in6_addr *addr)
{
	return NULL;
}

static inline char *net_sprint_ipv4_addr(struct in_addr *addr)
{
	return NULL;
}

static inline char *net_sprint_ip_addr(struct net_addr *addr)
{
	return NULL;
}

#define net_hexdump(str, packet, length)

#endif /* NET_DEBUG */
{'fraction_non_alphanumeric': 0.11230665770006724, 'fraction_numerical': 0.01647612642905178, 'mean_word_length': 4.849557522123894, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2721680', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2223, 'n_words': 623}