Blame testprogs/can_set_rfmon_test.c

Packit 209cc3
/*
Packit 209cc3
 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
Packit 209cc3
 *	The Regents of the University of California.  All rights reserved.
Packit 209cc3
 *
Packit 209cc3
 * Redistribution and use in source and binary forms, with or without
Packit 209cc3
 * modification, are permitted provided that: (1) source code distributions
Packit 209cc3
 * retain the above copyright notice and this paragraph in its entirety, (2)
Packit 209cc3
 * distributions including binary code include the above copyright notice and
Packit 209cc3
 * this paragraph in its entirety in the documentation or other materials
Packit 209cc3
 * provided with the distribution, and (3) all advertising materials mentioning
Packit 209cc3
 * features or use of this software display the following acknowledgement:
Packit 209cc3
 * ``This product includes software developed by the University of California,
Packit 209cc3
 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
Packit 209cc3
 * the University nor the names of its contributors may be used to endorse
Packit 209cc3
 * or promote products derived from this software without specific prior
Packit 209cc3
 * written permission.
Packit 209cc3
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
Packit 209cc3
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
Packit 209cc3
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit 209cc3
 */
Packit 209cc3
Packit 209cc3
#include "varattrs.h"
Packit 209cc3
Packit 209cc3
#ifndef lint
Packit 209cc3
static const char copyright[] _U_ =
Packit 209cc3
    "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
Packit 209cc3
The Regents of the University of California.  All rights reserved.\n";
Packit 209cc3
#endif
Packit 209cc3
Packit 209cc3
#include <stdio.h>
Packit 209cc3
#include <stdlib.h>
Packit 209cc3
#include <string.h>
Packit 209cc3
#include <stdarg.h>
Packit 209cc3
Packit 209cc3
#include <pcap.h>
Packit 209cc3
Packit 209cc3
#include "pcap/funcattrs.h"
Packit 209cc3
Packit 209cc3
static const char *program_name;
Packit 209cc3
Packit 209cc3
/* Forwards */
Packit 209cc3
static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
Packit 209cc3
Packit 209cc3
int
Packit 209cc3
main(int argc, char **argv)
Packit 209cc3
{
Packit 209cc3
	const char *cp;
Packit 209cc3
	pcap_t *pd;
Packit 209cc3
	char ebuf[PCAP_ERRBUF_SIZE];
Packit 209cc3
	int status;
Packit 209cc3
Packit 209cc3
	if ((cp = strrchr(argv[0], '/')) != NULL)
Packit 209cc3
		program_name = cp + 1;
Packit 209cc3
	else
Packit 209cc3
		program_name = argv[0];
Packit 209cc3
Packit 209cc3
	if (argc != 2) {
Packit 209cc3
		fprintf(stderr, "Usage: %s <device>\n", program_name);
Packit 209cc3
		return 2;
Packit 209cc3
	}
Packit 209cc3
Packit 209cc3
	pd = pcap_create(argv[1], ebuf);
Packit 209cc3
	if (pd == NULL)
Packit 209cc3
		error("%s", ebuf);
Packit 209cc3
	status = pcap_can_set_rfmon(pd);
Packit 209cc3
	if (status < 0) {
Packit 209cc3
		if (status == PCAP_ERROR)
Packit 209cc3
			error("%s: pcap_can_set_rfmon failed: %s", argv[1],
Packit 209cc3
			    pcap_geterr(pd));
Packit 209cc3
		else
Packit 209cc3
			error("%s: pcap_can_set_rfmon failed: %s", argv[1],
Packit 209cc3
			    pcap_statustostr(status));
Packit 209cc3
		return 1;
Packit 209cc3
	}
Packit 209cc3
	printf("%s: Monitor mode %s be set\n", argv[1], status ? "can" : "cannot");
Packit 209cc3
	return 0;
Packit 209cc3
}
Packit 209cc3
Packit 209cc3
/* VARARGS */
Packit 209cc3
static void
Packit 209cc3
error(const char *fmt, ...)
Packit 209cc3
{
Packit 209cc3
	va_list ap;
Packit 209cc3
Packit 209cc3
	(void)fprintf(stderr, "%s: ", program_name);
Packit 209cc3
	va_start(ap, fmt);
Packit 209cc3
	(void)vfprintf(stderr, fmt, ap);
Packit 209cc3
	va_end(ap);
Packit 209cc3
	if (*fmt) {
Packit 209cc3
		fmt += strlen(fmt);
Packit 209cc3
		if (fmt[-1] != '\n')
Packit 209cc3
			(void)fputc('\n', stderr);
Packit 209cc3
	}
Packit 209cc3
	exit(1);
Packit 209cc3
	/* NOTREACHED */
Packit 209cc3
}