1*8b26181fSAndroid Build Coastguard Worker /*
2*8b26181fSAndroid Build Coastguard Worker * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3*8b26181fSAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved.
4*8b26181fSAndroid Build Coastguard Worker *
5*8b26181fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
6*8b26181fSAndroid Build Coastguard Worker * modification, are permitted provided that: (1) source code distributions
7*8b26181fSAndroid Build Coastguard Worker * retain the above copyright notice and this paragraph in its entirety, (2)
8*8b26181fSAndroid Build Coastguard Worker * distributions including binary code include the above copyright notice and
9*8b26181fSAndroid Build Coastguard Worker * this paragraph in its entirety in the documentation or other materials
10*8b26181fSAndroid Build Coastguard Worker * provided with the distribution, and (3) all advertising materials mentioning
11*8b26181fSAndroid Build Coastguard Worker * features or use of this software display the following acknowledgement:
12*8b26181fSAndroid Build Coastguard Worker * ``This product includes software developed by the University of California,
13*8b26181fSAndroid Build Coastguard Worker * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*8b26181fSAndroid Build Coastguard Worker * the University nor the names of its contributors may be used to endorse
15*8b26181fSAndroid Build Coastguard Worker * or promote products derived from this software without specific prior
16*8b26181fSAndroid Build Coastguard Worker * written permission.
17*8b26181fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*8b26181fSAndroid Build Coastguard Worker * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*8b26181fSAndroid Build Coastguard Worker * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*8b26181fSAndroid Build Coastguard Worker */
21*8b26181fSAndroid Build Coastguard Worker
22*8b26181fSAndroid Build Coastguard Worker #include "varattrs.h"
23*8b26181fSAndroid Build Coastguard Worker
24*8b26181fSAndroid Build Coastguard Worker #ifndef lint
25*8b26181fSAndroid Build Coastguard Worker static const char copyright[] _U_ =
26*8b26181fSAndroid Build Coastguard Worker "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
27*8b26181fSAndroid Build Coastguard Worker The Regents of the University of California. All rights reserved.\n";
28*8b26181fSAndroid Build Coastguard Worker #endif
29*8b26181fSAndroid Build Coastguard Worker
30*8b26181fSAndroid Build Coastguard Worker #include <pcap.h>
31*8b26181fSAndroid Build Coastguard Worker #include <stdio.h>
32*8b26181fSAndroid Build Coastguard Worker #include <stdlib.h>
33*8b26181fSAndroid Build Coastguard Worker #include <string.h>
34*8b26181fSAndroid Build Coastguard Worker #include <stdarg.h>
35*8b26181fSAndroid Build Coastguard Worker
36*8b26181fSAndroid Build Coastguard Worker #include "pcap/funcattrs.h"
37*8b26181fSAndroid Build Coastguard Worker
38*8b26181fSAndroid Build Coastguard Worker /* Forwards */
39*8b26181fSAndroid Build Coastguard Worker static void PCAP_NORETURN error(PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(1,2);
40*8b26181fSAndroid Build Coastguard Worker
41*8b26181fSAndroid Build Coastguard Worker int
main(void)42*8b26181fSAndroid Build Coastguard Worker main(void)
43*8b26181fSAndroid Build Coastguard Worker {
44*8b26181fSAndroid Build Coastguard Worker char ebuf[PCAP_ERRBUF_SIZE];
45*8b26181fSAndroid Build Coastguard Worker pcap_t *pd;
46*8b26181fSAndroid Build Coastguard Worker int status = 0;
47*8b26181fSAndroid Build Coastguard Worker
48*8b26181fSAndroid Build Coastguard Worker pd = pcap_open_live("lo0", 65535, 0, 1000, ebuf);
49*8b26181fSAndroid Build Coastguard Worker if (pd == NULL) {
50*8b26181fSAndroid Build Coastguard Worker pd = pcap_open_live("lo", 65535, 0, 1000, ebuf);
51*8b26181fSAndroid Build Coastguard Worker if (pd == NULL) {
52*8b26181fSAndroid Build Coastguard Worker error("Neither lo0 nor lo could be opened: %s",
53*8b26181fSAndroid Build Coastguard Worker ebuf);
54*8b26181fSAndroid Build Coastguard Worker }
55*8b26181fSAndroid Build Coastguard Worker }
56*8b26181fSAndroid Build Coastguard Worker status = pcap_activate(pd);
57*8b26181fSAndroid Build Coastguard Worker if (status != PCAP_ERROR_ACTIVATED) {
58*8b26181fSAndroid Build Coastguard Worker if (status == 0)
59*8b26181fSAndroid Build Coastguard Worker error("pcap_activate() of opened pcap_t succeeded");
60*8b26181fSAndroid Build Coastguard Worker else if (status == PCAP_ERROR)
61*8b26181fSAndroid Build Coastguard Worker error("pcap_activate() of opened pcap_t failed with %s, not PCAP_ERROR_ACTIVATED",
62*8b26181fSAndroid Build Coastguard Worker pcap_geterr(pd));
63*8b26181fSAndroid Build Coastguard Worker else
64*8b26181fSAndroid Build Coastguard Worker error("pcap_activate() of opened pcap_t failed with %s, not PCAP_ERROR_ACTIVATED",
65*8b26181fSAndroid Build Coastguard Worker pcap_statustostr(status));
66*8b26181fSAndroid Build Coastguard Worker }
67*8b26181fSAndroid Build Coastguard Worker return 0;
68*8b26181fSAndroid Build Coastguard Worker }
69*8b26181fSAndroid Build Coastguard Worker
70*8b26181fSAndroid Build Coastguard Worker /* VARARGS */
71*8b26181fSAndroid Build Coastguard Worker static void
error(const char * fmt,...)72*8b26181fSAndroid Build Coastguard Worker error(const char *fmt, ...)
73*8b26181fSAndroid Build Coastguard Worker {
74*8b26181fSAndroid Build Coastguard Worker va_list ap;
75*8b26181fSAndroid Build Coastguard Worker
76*8b26181fSAndroid Build Coastguard Worker (void)fprintf(stderr, "reactivatetest: ");
77*8b26181fSAndroid Build Coastguard Worker va_start(ap, fmt);
78*8b26181fSAndroid Build Coastguard Worker (void)vfprintf(stderr, fmt, ap);
79*8b26181fSAndroid Build Coastguard Worker va_end(ap);
80*8b26181fSAndroid Build Coastguard Worker if (*fmt) {
81*8b26181fSAndroid Build Coastguard Worker fmt += strlen(fmt);
82*8b26181fSAndroid Build Coastguard Worker if (fmt[-1] != '\n')
83*8b26181fSAndroid Build Coastguard Worker (void)fputc('\n', stderr);
84*8b26181fSAndroid Build Coastguard Worker }
85*8b26181fSAndroid Build Coastguard Worker exit(1);
86*8b26181fSAndroid Build Coastguard Worker /* NOTREACHED */
87*8b26181fSAndroid Build Coastguard Worker }
88