4 #define CAPTURE_DEVICE "nosuchdevice"
9 * When trying to use libpcap on a device that does not exist, the
10 * expected behaviour is that pcap_create() does not return an error,
11 * and pcap_activate() does return an error, and the error code
12 * specifically tells that the interface does not exist. tcpdump
13 * depends on this semantics to accept integer indices instead of
14 * device names. This test provides means to verify the actual
15 * behaviour, which is specific to each libpcap module.
17 char errbuf
[PCAP_ERRBUF_SIZE
];
18 printf("Trying to use capture device \"%s\"...\n", CAPTURE_DEVICE
);
19 pcap_t
*p
= pcap_create(CAPTURE_DEVICE
, errbuf
);
22 "FAIL: Unexpected error from pcap_create() (%s).\n",
26 int ret
= 1, err
= pcap_activate(p
);
29 fprintf(stderr
, "FAIL: No error from pcap_activate().\n");
32 fprintf(stderr
, "FAIL: Generic error from pcap_activate().\n");
34 case PCAP_ERROR_PERM_DENIED
:
35 fprintf(stderr
, "FAIL: Permission denied from pcap_activate(), "
36 "retry with higher privileges.\n");
38 case PCAP_ERROR_NO_SUCH_DEVICE
:
39 printf("PASS: Correct specific error from pcap_activate().\n");
44 "FAIL: Unexpected error %d from pcap_activate().\n",