If an adapter index that's greater than the number of adapters is
specified by the user, mention the incorrect adapter index, and the
total number of adapters (the former being greater than the latter), in
the error message.
Free the adapter list before reporting the error and exiting, to
suppress complaints from leak detectots (not that the memory spends much
time leaked, as exiting destroys the entire address space, but...).
Fixes issue #1208.
for (i = 0, dev = devlist; i < devnum-1 && dev != NULL;
i++, dev = dev->next)
;
- if (dev == NULL)
- error("Invalid adapter index");
+ if (dev == NULL) {
+ pcap_freealldevs(devlist);
+ error("Invalid adapter index %ld: only %ld interfaces found",
+ devnum, i);
+ }
device = strdup(dev->name);
pcap_freealldevs(devlist);
return (device);