/*
* Copyright (C) 2014 Luigi Rizzo. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __FreeBSD__
/*
* On FreeBSD we use IFF_PPROMISC which is in ifr_flagshigh.
* Remap to IFF_PROMISC on other platforms.
*
* XXX - DragonFly BSD?
*/
#define IFF_PPROMISC IFF_PROMISC
#endif /* __FreeBSD__ */
struct pcap_netmap {
struct nm_desc *d; /* pointer returned by nm_open() */
pcap_handler cb; /* callback and argument */
u_char *cb_arg;
int must_clear_promisc; /* flag */
uint64_t rx_pkts; /* # of pkts received before the filter */
};
#ifdef __linux__
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf(stderr, "Error: cannot get device control socket.\n");
return -1;
}
#endif /* __linux__ */
bzero(&ifr, sizeof(ifr));
strncpy(ifr.ifr_name, d->req.nr_name, sizeof(ifr.ifr_name));
switch (what) {
case SIOCSIFFLAGS:
/*
* The flags we pass in are 32-bit and unsigned.
*
* On most if not all UN*Xes, ifr_flags is 16-bit and
* signed, and the result of assigning a longer
* unsigned value to a shorter signed value is
* implementation-defined (even if, in practice, it'll
* do what's intended on all platforms we support
* result of assigning a 32-bit unsigned value).
* So we mask out the upper 16 bits.
*/
ifr.ifr_flags = *if_flags & 0xffff;
#ifdef __FreeBSD__
/*
* In FreeBSD, we need to set the high-order flags,
* as we're using IFF_PPROMISC, which is in those bits.
*
* XXX - DragonFly BSD?
*/
ifr.ifr_flagshigh = *if_flags >> 16;
#endif /* __FreeBSD__ */
break;
}
error = ioctl(fd, what, &ifr);
if (!error) {
switch (what) {
case SIOCGIFFLAGS:
/*
* The flags we return are 32-bit.
*
* On most if not all UN*Xes, ifr_flags is
* 16-bit and signed, and will get sign-
* extended, so that the upper 16 bits of
* those flags will be forced on. So we
* mask out the upper 16 bits of the
* sign-extended value.
*/
*if_flags = ifr.ifr_flags & 0xffff;
#ifdef __FreeBSD__
/*
* In FreeBSD, we need to return the
* high-order flags, as we're using
* IFF_PPROMISC, which is in those bits.
*
* XXX - DragonFly BSD?
*/
*if_flags |= (ifr.ifr_flagshigh << 16);
#endif /* __FreeBSD__ */
}
}
#ifdef __linux__
close(fd);
#endif /* __linux__ */
return error ? -1 : 0;
}
/*
* Turn a negative snapshot value (invalid), a snapshot value of
* 0 (unspecified), or a value bigger than the normal maximum
* value, into the maximum allowed value.
*
* If some application really *needs* a bigger snapshot
* length, we should just increase MAXIMUM_SNAPLEN.
*/
if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
p->snapshot = MAXIMUM_SNAPLEN;
/*
* The "device name" for netmap devices isn't a name for a device, it's
* an expression that indicates how the device should be set up, so
* there's no way to enumerate them.
*/
int
pcap_netmap_findalldevs(pcap_if_list_t *devlistp _U_, char *err_str _U_)
{
return 0;
}