1230832Sgnn/* 2230832Sgnn * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000 3230832Sgnn * The Regents of the University of California. All rights reserved. 4230832Sgnn * 5230832Sgnn * Redistribution and use in source and binary forms, with or without 6230832Sgnn * modification, are permitted provided that: (1) source code distributions 7230832Sgnn * retain the above copyright notice and this paragraph in its entirety, (2) 8230832Sgnn * distributions including binary code include the above copyright notice and 9230832Sgnn * this paragraph in its entirety in the documentation or other materials 10230832Sgnn * provided with the distribution, and (3) all advertising materials mentioning 11230832Sgnn * features or use of this software display the following acknowledgement: 12230832Sgnn * ``This product includes software developed by the University of California, 13230832Sgnn * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14230832Sgnn * the University nor the names of its contributors may be used to endorse 15230832Sgnn * or promote products derived from this software without specific prior 16230832Sgnn * written permission. 17230832Sgnn * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18230832Sgnn * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19230832Sgnn * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20230832Sgnn */ 21230832Sgnn 22230832Sgnn#ifndef lint 23230832Sgnnstatic const char copyright[] = 24230832Sgnn "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\ 25230832SgnnThe Regents of the University of California. All rights reserved.\n"; 26230832Sgnn#endif 27230832Sgnn 28230832Sgnn#include <pcap.h> 29230832Sgnn#include <stdio.h> 30230832Sgnn#include <stdlib.h> 31230832Sgnn#include <string.h> 32230832Sgnn#include <stdarg.h> 33230832Sgnn 34230832Sgnn/* Forwards */ 35230832Sgnnstatic void error(const char *, ...); 36230832Sgnn 37230832Sgnnint 38230832Sgnnmain(void) 39230832Sgnn{ 40230832Sgnn char ebuf[PCAP_ERRBUF_SIZE]; 41230832Sgnn pcap_t *pd; 42230832Sgnn int status = 0; 43230832Sgnn 44230832Sgnn pd = pcap_open_live("lo0", 65535, 0, 1000, ebuf); 45230832Sgnn if (pd == NULL) { 46230832Sgnn pd = pcap_open_live("lo", 65535, 0, 1000, ebuf); 47230832Sgnn if (pd == NULL) { 48230832Sgnn error("Neither lo0 nor lo could be opened: %s", 49230832Sgnn ebuf); 50230832Sgnn return 2; 51230832Sgnn } 52230832Sgnn } 53230832Sgnn status = pcap_activate(pd); 54230832Sgnn if (status != PCAP_ERROR_ACTIVATED) { 55230832Sgnn if (status == 0) 56230832Sgnn error("pcap_activate() of opened pcap_t succeeded"); 57230832Sgnn else if (status == PCAP_ERROR) 58230832Sgnn error("pcap_activate() of opened pcap_t failed with %s, not PCAP_ERROR_ACTIVATED", 59230832Sgnn pcap_geterr(pd)); 60230832Sgnn else 61230832Sgnn error("pcap_activate() of opened pcap_t failed with %s, not PCAP_ERROR_ACTIVATED", 62230832Sgnn pcap_statustostr(status)); 63230832Sgnn } 64230832Sgnn return 0; 65230832Sgnn} 66230832Sgnn 67230832Sgnn/* VARARGS */ 68230832Sgnnstatic void 69230832Sgnnerror(const char *fmt, ...) 70230832Sgnn{ 71230832Sgnn va_list ap; 72230832Sgnn 73230832Sgnn (void)fprintf(stderr, "reactivatetest: "); 74230832Sgnn va_start(ap, fmt); 75230832Sgnn (void)vfprintf(stderr, fmt, ap); 76230832Sgnn va_end(ap); 77230832Sgnn if (*fmt) { 78230832Sgnn fmt += strlen(fmt); 79230832Sgnn if (fmt[-1] != '\n') 80230832Sgnn (void)fputc('\n', stderr); 81230832Sgnn } 82230832Sgnn exit(1); 83230832Sgnn /* NOTREACHED */ 84230832Sgnn} 85