<commit_before>/*
 * $Id: arpscan.c,v 1.13 2009/07/07 20:59:48 jason Exp $
 *
 * Copyright (c) 2002-2005 <NAME> <<EMAIL>>
 * All rights reserved.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>

#include <pcap.h>
#ifdef DUMBNET
#include <dumbnet.h>
#else
#include <dnet.h>
#endif /* DUMBNET */

/* A concatenation of dnet's arp_hdr and arp_ethip. */
struct ether_arp {
	struct arp_hdr arp_hdr;
	struct arp_ethip arp_ethip;
};

extern char *__progname;
struct eth_hdr eth_header;
char pcap_errbuf[PCAP_ERRBUF_SIZE];
uint32_t my_ipaddr;
uint8_t my_ethaddr[6];

uint32_t ip_lo;
uint32_t ip_hi;

void
usage()
{
	fprintf(stderr, "USAGE: %s [-i interface] <ip-address>\n\n", 
	    __progname);
	fprintf(stderr, "\teg)\n");
	fprintf(stderr, "\t    %s 172.16.1.11\n", __progname);
	fprintf(stderr, "\t    %s 192.168.1.100-192.168.1.200\n", __progname);
	fprintf(stderr, "\t    %s 172.16.1.41/29\n");
	fprintf(stderr, "\n");
	exit(1);
}

/**
 * The libpcap callback when a packet has been received.  If its an
 * ARP reply, display it to stdout.
 */
void
pcap_cb(u_char *u, struct pcap_pkthdr *hdr, u_char *pkt)
{
	struct ether_arp *ether_arp;
	u_char eth_str[19];
	u_char ip_str[17];
	uint32_t ip;

	ether_arp = (struct ether_arp *)(pkt + sizeof(struct eth_hdr));

	/* We are only interested ARP replies. */
	if (ether_arp->arp_hdr.ar_op != ntohs(ARP_OP_REPLY))
		return;

	/* Don't display ARP replies that may have been caught that
	 * are out of our scan range. */
	ip = *(uint32_t *)ether_arp->arp_ethip.ar_spa;
	if (ip < ip_lo || ip > ip_hi)
		return;
<commit_msg>Fix crash on usage.  Noticed while reviewing the freshports commit log.<commit_after>/*
 * $Id: arpscan.c,v 1.13 2009/07/07 20:59:48 jason Exp $
 *
 * Copyright (c) 2002-2005 <NAME> <<EMAIL>>
 * All rights reserved.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>

#include <pcap.h>
#ifdef DUMBNET
#include <dumbnet.h>
#else
#include <dnet.h>
#endif /* DUMBNET */

/* A concatenation of dnet's arp_hdr and arp_ethip. */
struct ether_arp {
	struct arp_hdr arp_hdr;
	struct arp_ethip arp_ethip;
};

extern char *__progname;
struct eth_hdr eth_header;
char pcap_errbuf[PCAP_ERRBUF_SIZE];
uint32_t my_ipaddr;
uint8_t my_ethaddr[6];

uint32_t ip_lo;
uint32_t ip_hi;

void
usage()
{
	fprintf(stderr, "USAGE: %s [-i interface] <ip-address>\n\n", 
	    __progname);
	fprintf(stderr, "\teg)\n");
	fprintf(stderr, "\t    %s 172.16.1.11\n", __progname);
	fprintf(stderr, "\t    %s 192.168.1.100-192.168.1.200\n", __progname);
	fprintf(stderr, "\t    %s 172.16.1.41/29\n", __progname);
	fprintf(stderr, "\n");
	exit(1);
}

/**
 * The libpcap callback when a packet has been received.  If its an
 * ARP reply, display it to stdout.
 */
void
pcap_cb(u_char *u, struct pcap_pkthdr *hdr, u_char *pkt)
{
	struct ether_arp *ether_arp;
	u_char eth_str[19];
	u_char ip_str[17];
	uint32_t ip;

	ether_arp = (struct ether_arp *)(pkt + sizeof(struct eth_hdr));

	/* We are only interested ARP replies. */
	if (ether_arp->arp_hdr.ar_op != ntohs(ARP_OP_REPLY))
		return;

	/* Don't display ARP replies that may have been caught that
	 * are out of our scan range. */
	ip = *(uint32_t *)ether_arp->arp_ethip.ar_spa;
	if (ip < ip_lo || ip > ip_hi)
		return;

{'fraction_non_alphanumeric': 0.1569239500567537, 'fraction_numerical': 0.04540295119182747, 'mean_word_length': 4.028530670470756, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '3124371', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1496, 'n_words': 375}