<commit_before>/*
 * intf.c
 *
 * Copyright (c) 2001 <NAME> <<EMAIL>>
 *
 * $Id$
 */

#include "config.h"

#include <sys/types.h>

#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "dnet.h"
#include "mod.h"

static intf_t	*intf;

static void
usage(void)
{
	fprintf(stderr, "Usage: dnet intf show\n"
	    "       dnet intf get <name>\n"
	    "       dnet intf set <name> "
	    "[alias|dst|inet|link <addr> ...] [up|down|arp|noarp ...]\n"
	    "       dnet intf src <ip>\n"
	    "       dnet intf dst <ip>\n"
);
	exit(1);
}

static char *
flags2string(u_short flags)
{
	static char buf[256];

	buf[0] = '\0';
	
	if (flags & INTF_FLAG_UP)
		strlcat(buf, ",UP", sizeof(buf));
	if (flags & INTF_FLAG_LOOPBACK)
		strlcat(buf, ",LOOPBACK", sizeof(buf));
	if (flags & INTF_FLAG_POINTOPOINT)
		strlcat(buf, ",POINTOPOINT", sizeof(buf));
	if (flags & INTF_FLAG_NOARP)
		strlcat(buf, ",NOARP", sizeof(buf));
	if (flags & INTF_FLAG_BROADCAST)
		strlcat(buf, ",BROADCAST", sizeof(buf));
	if (flags & INTF_FLAG_MULTICAST)
		strlcat(buf, ",MULTICAST", sizeof(buf));
	
	if (buf[0] != '\0')
		return (buf + 1);

	return (buf);
}

static int
print_intf(const struct intf_entry *entry, void *arg)
{
	struct addr bcast;
	uint32_t mask;
	int i;
	
	printf("%s:", entry->intf_name);
	
	printf(" flags=0x%x<%s>", entry->intf_flags,
	    flags2string(entry->intf_flags));
	
	if (entry->intf_mtu != 0)
		printf(" mtu %d", entry->intf_mtu);

	printf("\n");
	
	if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
		addr_btom(entry->intf_addr.addr_bits, &mask, IP_ADDR_LEN);
		mask = ntohl(mask);
		addr_bcast(&entry->intf_addr, &bcast);

		if (entry->intf_dst_addr.addr_type == ADDR_TYPE_IP) {
			printf("\tinet %s --> %s netmask 0x%x broadcast %s\n",
			    ip_ntoa(&entry->intf_addr.addr_ip),
			    addr_ntoa(&entry->intf_dst_addr),
			    mask, addr_ntoa(&bcast));
		} else {
			printf("\tinet %s netmask 0x%x broadcast %s\n",
			    ip_ntoa(&entry->intf_addr.addr_ip),
			    mask, addr_ntoa(&bcast));
		}
	}
	if (entry->intf_link_addr.addr_type == ADDR_TYPE_ETH)
		printf("\tlink %s\n", addr_ntoa(&entry->intf_link_addr));

	for (i = 0; i < entry->intf_alias_num; i++)
		printf("\talias %s\n", addr_ntoa(&entry->intf_alias_addrs[i]));
	
	return (0);
}

int
intf_main(int argc, char *argv[])
{<commit_msg>consistent address output<commit_after>/*
 * intf.c
 *
 * Copyright (c) 2001 <NAME> <<EMAIL>>
 *
 * $Id$
 */

#include "config.h"

#include <sys/types.h>

#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "dnet.h"
#include "mod.h"

static intf_t	*intf;

static void
usage(void)
{
	fprintf(stderr, "Usage: dnet intf show\n"
	    "       dnet intf get <name>\n"
	    "       dnet intf set <name> "
	    "[alias|dst|inet|link <addr> ...] [up|down|arp|noarp ...]\n"
	    "       dnet intf src <ip>\n"
	    "       dnet intf dst <ip>\n"
);
	exit(1);
}

static char *
flags2string(u_short flags)
{
	static char buf[256];

	buf[0] = '\0';
	
	if (flags & INTF_FLAG_UP)
		strlcat(buf, ",UP", sizeof(buf));
	if (flags & INTF_FLAG_LOOPBACK)
		strlcat(buf, ",LOOPBACK", sizeof(buf));
	if (flags & INTF_FLAG_POINTOPOINT)
		strlcat(buf, ",POINTOPOINT", sizeof(buf));
	if (flags & INTF_FLAG_NOARP)
		strlcat(buf, ",NOARP", sizeof(buf));
	if (flags & INTF_FLAG_BROADCAST)
		strlcat(buf, ",BROADCAST", sizeof(buf));
	if (flags & INTF_FLAG_MULTICAST)
		strlcat(buf, ",MULTICAST", sizeof(buf));
	
	if (buf[0] != '\0')
		return (buf + 1);

	return (buf);
}

static int
print_intf(const struct intf_entry *entry, void *arg)
{
	int i;
	
	printf("%s:", entry->intf_name);
	
	printf(" flags=0x%x<%s>", entry->intf_flags,
	    flags2string(entry->intf_flags));
	
	if (entry->intf_mtu != 0)
		printf(" mtu %d", entry->intf_mtu);

	printf("\n");
	
	if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
		if (entry->intf_dst_addr.addr_type == ADDR_TYPE_IP) {
			printf("\tinet %s --> %s\n",
			    addr_ntoa(&entry->intf_addr),
			    addr_ntoa(&entry->intf_dst_addr));
		} else
			printf("\tinet %s\n", addr_ntoa(&entry->intf_addr));
	}
	if (entry->intf_link_addr.addr_type == ADDR_TYPE_ETH)
		printf("\tlink %s\n", addr_ntoa(&entry->intf_link_addr));

	for (i = 0; i < entry->intf_alias_num; i++)
		printf("\talias %s\n", addr_ntoa(&entry->intf_alias_addrs[i]));
	
	return (0);
}

int
intf_main(int argc, char *argv[])
{
{'fraction_non_alphanumeric': 0.19018543645409317, 'fraction_numerical': 0.009497964721845319, 'mean_word_length': 3.8551042810098792, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4898342', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1854, 'n_words': 374}