(cs)->is_geneve = 0; \
}
+/*
+ * Offset "not set" value.
+ */
+#define OFFSET_NOT_SET 0xffffffffU
+
/*
* Absolute offsets, which are offsets from the beginning of the raw
* packet data, are, in the general case, the sum of a variable value
*
* For Linux cooked sockets, it's the offset of the type field.
*
- * off_linktype.constant_part is set to -1 for no encapsulation,
- * in which case, IP is assumed.
+ * off_linktype.constant_part is set to OFFSET_NOT_SET for no
+ * encapsulation, in which case, IP is assumed.
*/
bpf_abs_offset off_linktype;
* SLIP doesn't have a link level type. The 16 byte
* header is hacked into our SLIP driver.
*/
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 16;
cstate->off_nl = 0;
cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
case DLT_SLIP_BSDOS:
/* XXX this may be the same as the DLT_PPP_BSDOS case */
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
/* XXX end */
cstate->off_linkpl.constant_part = 24;
cstate->off_nl = 0;
case DLT_RAW:
case DLT_IPV4:
case DLT_IPV6:
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 0;
cstate->off_nl = 0;
cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
* but really it just indicates whether there is a "short" or
* "long" DDP packet following.
*/
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 0;
cstate->off_nl = 0;
cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
* XXX - we should set this to handle SNAP-encapsulated
* frames (NLPID of 0x80).
*/
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 0;
cstate->off_nl = 0;
cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
* so lets start with offset 4 for now and increments later on (FIXME);
*/
case DLT_MFR:
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 0;
cstate->off_nl = 4;
cstate->off_nl_nosnap = 0; /* XXX - for now -> no 802.2 LLC */
case DLT_JUNIPER_ES:
cstate->off_linktype.constant_part = 6;
- cstate->off_linkpl.constant_part = -1; /* not really a network layer but raw IP addresses */
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* not really a network layer but raw IP addresses */
cstate->off_nl = -1; /* not really a network layer but raw IP addresses */
cstate->off_nl_nosnap = -1; /* no 802.2 LLC */
break;
break;
case DLT_BACNET_MS_TP:
- cstate->off_linktype.constant_part = -1;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
case DLT_JUNIPER_SERVICES:
cstate->off_linktype.constant_part = 12;
- cstate->off_linkpl.constant_part = -1; /* L3 proto location dep. on cookie type */
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET; /* L3 proto location dep. on cookie type */
cstate->off_nl = -1; /* L3 proto location dep. on cookie type */
cstate->off_nl_nosnap = -1; /* no 802.2 LLC */
break;
case DLT_JUNIPER_VP:
cstate->off_linktype.constant_part = 18;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
case DLT_JUNIPER_ST:
cstate->off_linktype.constant_part = 18;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
case DLT_JUNIPER_ISM:
cstate->off_linktype.constant_part = 8;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
case DLT_JUNIPER_FIBRECHANNEL:
case DLT_JUNIPER_ATM_CEMIC:
cstate->off_linktype.constant_part = 8;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
cstate->off_opc = 4;
cstate->off_dpc = 4;
cstate->off_sls = 7;
- cstate->off_linktype.constant_part = -1;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
cstate->off_opc = 8;
cstate->off_dpc = 8;
cstate->off_sls = 11;
- cstate->off_linktype.constant_part = -1;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
cstate->off_opc = 24;
cstate->off_dpc = 24;
cstate->off_sls = 27;
- cstate->off_linktype.constant_part = -1;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
break;
case DLT_PFSYNC:
- cstate->off_linktype.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
cstate->off_linkpl.constant_part = 4;
cstate->off_nl = 0;
cstate->off_nl_nosnap = 0;
/*
* Currently, only raw "link[N:M]" filtering is supported.
*/
- cstate->off_linktype.constant_part = -1; /* variable, min 15, max 71 steps of 7 */
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET; /* variable, min 15, max 71 steps of 7 */
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1; /* variable, min 16, max 71 steps of 7 */
cstate->off_nl_nosnap = -1; /* no 802.2 LLC */
break;
*/
if (cstate->linktype >= DLT_MATCHING_MIN &&
cstate->linktype <= DLT_MATCHING_MAX) {
- cstate->off_linktype.constant_part = -1;
- cstate->off_linkpl.constant_part = -1;
+ cstate->off_linktype.constant_part = OFFSET_NOT_SET;
+ cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
cstate->off_nl = -1;
cstate->off_nl_nosnap = -1;
} else {
* Does this link-layer header type have a field
* indicating the type of the next protocol? If
* so, off_linktype.constant_part will be the offset of that
- * field in the packet; if not, it will be -1.
+ * field in the packet; if not, it will be OFFSET_NOT_SET.
*/
- if (cstate->off_linktype.constant_part != (u_int)-1) {
+ if (cstate->off_linktype.constant_part != OFFSET_NOT_SET) {
/*
* Yes; assume it's an Ethernet type. (If
* it's not, it needs to be handled specially
if (alist == NULL || *alist == NULL)
bpf_error(cstate, "unknown host '%s'", name);
tproto = proto;
- if (cstate->off_linktype.constant_part == (u_int)-1 &&
+ if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
tproto == Q_DEFAULT)
tproto = Q_IP;
b = gen_host(cstate, **alist++, 0xffffffff, tproto, dir, q.addr);
cstate->ai = res;
b = tmp = NULL;
tproto = tproto6 = proto;
- if (cstate->off_linktype.constant_part == -1 &&
+ if (cstate->off_linktype.constant_part == OFFSET_NOT_SET &&
tproto == Q_DEFAULT) {
tproto = Q_IP;
tproto6 = Q_IPV6;
initialize_ops(p);
/* put in some defaults*/
- pcap_set_snaplen(p, MAXIMUM_SNAPLEN); /* max packet size */
- p->opt.timeout = 0; /* no timeout specified */
- p->opt.buffer_size = 0; /* use the platform's default */
+ p->snapshot = MAXIMUM_SNAPLEN; /* max packet size */
+ p->opt.timeout = 0; /* no timeout specified */
+ p->opt.buffer_size = 0; /* use the platform's default */
p->opt.promisc = 0;
p->opt.rfmon = 0;
p->opt.immediate = 0;
{
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
+
+ /*
+ * Turn invalid values, or excessively large values, into
+ * the maximum allowed value.
+ *
+ * If some application really *needs* a bigger snapshot
+ * length, we should just increase MAXIMUM_SNAPLEN.
+ */
+ if (snaplen <= 0 || snaplen > MAXIMUM_SNAPLEN)
+ snaplen = MAXIMUM_SNAPLEN;
p->snapshot = snaplen;
return (0);
}
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
+ /*
+ * The argument should have been u_int, but that's too late
+ * to change now - it's an API.
+ */
+ if (tstamp_type < 0)
+ return (PCAP_WARNING_TSTAMP_TYPE_NOTSUP);
+
/*
* If p->tstamp_type_count is 0, we only support PCAP_TSTAMP_HOST;
* the default time stamp type is PCAP_TSTAMP_HOST.
* Check whether we claim to support this type of time stamp.
*/
for (i = 0; i < p->tstamp_type_count; i++) {
- if (p->tstamp_type_list[i] == tstamp_type) {
+ if (p->tstamp_type_list[i] == (u_int)tstamp_type) {
/*
* Yes.
*/
{
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
+ if (buffer_size <= 0) {
+ /*
+ * Silently ignore invalid values.
+ */
+ return (0);
+ }
p->opt.buffer_size = buffer_size;
return (0);
}
if (pcap_check_activated(p))
return (PCAP_ERROR_ACTIVATED);
+ /*
+ * The argument should have been u_int, but that's too late
+ * to change now - it's an API.
+ */
+ if (tstamp_precision < 0)
+ return (PCAP_ERROR_TSTAMP_PRECISION_NOTSUP);
+
/*
* If p->tstamp_precision_count is 0, we only support setting
* the time stamp precision to microsecond precision; every
* time stamp.
*/
for (i = 0; i < p->tstamp_precision_count; i++) {
- if (p->tstamp_precision_list[i] == tstamp_precision) {
+ if (p->tstamp_precision_list[i] == (u_int)tstamp_precision) {
/*
* Yes.
*/
int i;
const char *dlt_name;
+ if (dlt < 0)
+ goto unsupported;
+
if (p->dlt_count == 0 || p->set_datalink_op == NULL) {
/*
* We couldn't fetch the list of DLTs, or we don't
return (0);
}
for (i = 0; i < p->dlt_count; i++)
- if (p->dlt_list[i] == dlt)
+ if (p->dlt_list[i] == (u_int)dlt)
break;
if (i >= p->dlt_count)
goto unsupported;