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