summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/pcap.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2012-05-14 05:12:56 +0000
committerdelphij <delphij@FreeBSD.org>2012-05-14 05:12:56 +0000
commita3451bb93bbf335a8f6b5feb9b80b256b0e304fe (patch)
tree158e6045ed438c41ac8de6cb27ac3c73cdc6643a /contrib/libpcap/pcap.c
parenta17ebbd192e814c313397aefc289ab32a0ece772 (diff)
parente11c3f548e0bd184480800016b8567824dc35516 (diff)
downloadFreeBSD-src-a3451bb93bbf335a8f6b5feb9b80b256b0e304fe.zip
FreeBSD-src-a3451bb93bbf335a8f6b5feb9b80b256b0e304fe.tar.gz
Merge from vendor branch: update libpcap to 1.2.1.
MFC after: 2 weeks
Diffstat (limited to 'contrib/libpcap/pcap.c')
-rw-r--r--contrib/libpcap/pcap.c402
1 files changed, 287 insertions, 115 deletions
diff --git a/contrib/libpcap/pcap.c b/contrib/libpcap/pcap.c
index 324752f..3bed10d 100644
--- a/contrib/libpcap/pcap.c
+++ b/contrib/libpcap/pcap.c
@@ -58,7 +58,7 @@ static const char rcsid[] _U_ =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#if !defined(_MSC_VER) && !defined(__BORLANDC__)
+#if !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__MINGW32__)
#include <unistd.h>
#endif
#include <fcntl.h>
@@ -83,7 +83,7 @@ int
pcap_not_initialized(pcap_t *pcap)
{
/* this means 'not initialized' */
- return PCAP_ERROR_NOT_ACTIVATED;
+ return (PCAP_ERROR_NOT_ACTIVATED);
}
/*
@@ -106,6 +106,56 @@ pcap_cant_set_rfmon(pcap_t *p _U_)
}
/*
+ * Sets *tstamp_typesp to point to an array 1 or more supported time stamp
+ * types; the return value is the number of supported time stamp types.
+ * The list should be freed by a call to pcap_free_tstamp_types() when
+ * you're done with it.
+ *
+ * A return value of 0 means "you don't get a choice of time stamp type",
+ * in which case *tstamp_typesp is set to null.
+ *
+ * PCAP_ERROR is returned on error.
+ */
+int
+pcap_list_tstamp_types(pcap_t *p, int **tstamp_typesp)
+{
+ if (p->tstamp_type_count == 0) {
+ /*
+ * We don't support multiple time stamp types.
+ */
+ *tstamp_typesp = NULL;
+ } else {
+ *tstamp_typesp = (int*)calloc(sizeof(**tstamp_typesp),
+ p->tstamp_type_count);
+ if (*tstamp_typesp == NULL) {
+ (void)snprintf(p->errbuf, sizeof(p->errbuf),
+ "malloc: %s", pcap_strerror(errno));
+ return (PCAP_ERROR);
+ }
+ (void)memcpy(*tstamp_typesp, p->tstamp_type_list,
+ sizeof(**tstamp_typesp) * p->tstamp_type_count);
+ }
+ return (p->tstamp_type_count);
+}
+
+/*
+ * In Windows, you might have a library built with one version of the
+ * C runtime library and an application built with another version of
+ * the C runtime library, which means that the library might use one
+ * version of malloc() and free() and the application might use another
+ * version of malloc() and free(). If so, that means something
+ * allocated by the library cannot be freed by the application, so we
+ * need to have a pcap_free_tstamp_types() routine to free up the list
+ * allocated by pcap_list_tstamp_types(), even though it's just a wrapper
+ * around free().
+ */
+void
+pcap_free_tstamp_types(int *tstamp_type_list)
+{
+ free(tstamp_type_list);
+}
+
+/*
* Default one-shot callback; overridden for capture types where the
* packet data cannot be guaranteed to be available after the callback
* returns, so that a copy must be made.
@@ -150,7 +200,8 @@ pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
int status;
/* We are on an offline capture */
- status = pcap_offline_read(p, 1, pcap_oneshot, (u_char *)&s);
+ status = pcap_offline_read(p, 1, p->oneshot_callback,
+ (u_char *)&s);
/*
* Return codes for pcap_offline_read() are:
@@ -179,7 +230,7 @@ pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
* The first one ('0') conflicts with the return code of 0 from
* pcap_offline_read() meaning "end of file".
*/
- return (p->read_op(p, 1, pcap_oneshot, (u_char *)&s));
+ return (p->read_op(p, 1, p->oneshot_callback, (u_char *)&s));
}
static void
@@ -259,6 +310,7 @@ pcap_create_common(const char *source, char *ebuf)
pcap_set_snaplen(p, 65535); /* max packet size */
p->opt.promisc = 0;
p->opt.buffer_size = 0;
+ p->opt.tstamp_type = -1; /* default to not setting time stamp type */
return (p);
}
@@ -268,54 +320,89 @@ pcap_check_activated(pcap_t *p)
if (p->activated) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "can't perform "
" operation on activated capture");
- return -1;
+ return (-1);
}
- return 0;
+ return (0);
}
int
pcap_set_snaplen(pcap_t *p, int snaplen)
{
if (pcap_check_activated(p))
- return PCAP_ERROR_ACTIVATED;
+ return (PCAP_ERROR_ACTIVATED);
p->snapshot = snaplen;
- return 0;
+ return (0);
}
int
pcap_set_promisc(pcap_t *p, int promisc)
{
if (pcap_check_activated(p))
- return PCAP_ERROR_ACTIVATED;
+ return (PCAP_ERROR_ACTIVATED);
p->opt.promisc = promisc;
- return 0;
+ return (0);
}
int
pcap_set_rfmon(pcap_t *p, int rfmon)
{
if (pcap_check_activated(p))
- return PCAP_ERROR_ACTIVATED;
+ return (PCAP_ERROR_ACTIVATED);
p->opt.rfmon = rfmon;
- return 0;
+ return (0);
}
int
pcap_set_timeout(pcap_t *p, int timeout_ms)
{
if (pcap_check_activated(p))
- return PCAP_ERROR_ACTIVATED;
+ return (PCAP_ERROR_ACTIVATED);
p->md.timeout = timeout_ms;
- return 0;
+ return (0);
+}
+
+int
+pcap_set_tstamp_type(pcap_t *p, int tstamp_type)
+{
+ int i;
+
+ if (pcap_check_activated(p))
+ return (PCAP_ERROR_ACTIVATED);
+
+ /*
+ * If p->tstamp_type_count is 0, we don't support setting
+ * the time stamp type at all.
+ */
+ if (p->tstamp_type_count == 0)
+ return (PCAP_ERROR_CANTSET_TSTAMP_TYPE);
+
+ /*
+ * 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) {
+ /*
+ * Yes.
+ */
+ p->opt.tstamp_type = tstamp_type;
+ return (0);
+ }
+ }
+
+ /*
+ * No. We support setting the time stamp type, but not to this
+ * particular value.
+ */
+ return (PCAP_WARNING_TSTAMP_TYPE_NOTSUP);
}
int
pcap_set_buffer_size(pcap_t *p, int buffer_size)
{
if (pcap_check_activated(p))
- return PCAP_ERROR_ACTIVATED;
+ return (PCAP_ERROR_ACTIVATED);
p->opt.buffer_size = buffer_size;
- return 0;
+ return (0);
}
int
@@ -323,6 +410,15 @@ pcap_activate(pcap_t *p)
{
int status;
+ /*
+ * Catch attempts to re-activate an already-activated
+ * pcap_t; this should, for example, catch code that
+ * calls pcap_open_live() followed by pcap_activate(),
+ * as some code that showed up in a Stack Exchange
+ * question did.
+ */
+ if (pcap_check_activated(p))
+ return (PCAP_ERROR_ACTIVATED);
status = p->activate_op(p);
if (status >= 0)
p->activated = 1;
@@ -385,7 +481,8 @@ fail:
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source,
p->errbuf);
else if (status == PCAP_ERROR_NO_SUCH_DEVICE ||
- status == PCAP_ERROR_PERM_DENIED)
+ status == PCAP_ERROR_PERM_DENIED ||
+ status == PCAP_ERROR_PROMISC_PERM_DENIED)
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", source,
pcap_statustostr(status), p->errbuf);
else
@@ -398,7 +495,7 @@ fail:
int
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
- return p->read_op(p, cnt, callback, user);
+ return (p->read_op(p, cnt, callback, user));
}
/*
@@ -408,7 +505,7 @@ int
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
- return p->read_op(p, cnt, callback, user);
+ return (p->read_op(p, cnt, callback, user));
}
int
@@ -572,6 +669,91 @@ unsupported:
return (-1);
}
+/*
+ * This array is designed for mapping upper and lower case letter
+ * together for a case independent comparison. The mappings are
+ * based upon ascii character sequences.
+ */
+static const u_char charmap[] = {
+ (u_char)'\000', (u_char)'\001', (u_char)'\002', (u_char)'\003',
+ (u_char)'\004', (u_char)'\005', (u_char)'\006', (u_char)'\007',
+ (u_char)'\010', (u_char)'\011', (u_char)'\012', (u_char)'\013',
+ (u_char)'\014', (u_char)'\015', (u_char)'\016', (u_char)'\017',
+ (u_char)'\020', (u_char)'\021', (u_char)'\022', (u_char)'\023',
+ (u_char)'\024', (u_char)'\025', (u_char)'\026', (u_char)'\027',
+ (u_char)'\030', (u_char)'\031', (u_char)'\032', (u_char)'\033',
+ (u_char)'\034', (u_char)'\035', (u_char)'\036', (u_char)'\037',
+ (u_char)'\040', (u_char)'\041', (u_char)'\042', (u_char)'\043',
+ (u_char)'\044', (u_char)'\045', (u_char)'\046', (u_char)'\047',
+ (u_char)'\050', (u_char)'\051', (u_char)'\052', (u_char)'\053',
+ (u_char)'\054', (u_char)'\055', (u_char)'\056', (u_char)'\057',
+ (u_char)'\060', (u_char)'\061', (u_char)'\062', (u_char)'\063',
+ (u_char)'\064', (u_char)'\065', (u_char)'\066', (u_char)'\067',
+ (u_char)'\070', (u_char)'\071', (u_char)'\072', (u_char)'\073',
+ (u_char)'\074', (u_char)'\075', (u_char)'\076', (u_char)'\077',
+ (u_char)'\100', (u_char)'\141', (u_char)'\142', (u_char)'\143',
+ (u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
+ (u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
+ (u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
+ (u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
+ (u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
+ (u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\133',
+ (u_char)'\134', (u_char)'\135', (u_char)'\136', (u_char)'\137',
+ (u_char)'\140', (u_char)'\141', (u_char)'\142', (u_char)'\143',
+ (u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
+ (u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
+ (u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
+ (u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
+ (u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
+ (u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\173',
+ (u_char)'\174', (u_char)'\175', (u_char)'\176', (u_char)'\177',
+ (u_char)'\200', (u_char)'\201', (u_char)'\202', (u_char)'\203',
+ (u_char)'\204', (u_char)'\205', (u_char)'\206', (u_char)'\207',
+ (u_char)'\210', (u_char)'\211', (u_char)'\212', (u_char)'\213',
+ (u_char)'\214', (u_char)'\215', (u_char)'\216', (u_char)'\217',
+ (u_char)'\220', (u_char)'\221', (u_char)'\222', (u_char)'\223',
+ (u_char)'\224', (u_char)'\225', (u_char)'\226', (u_char)'\227',
+ (u_char)'\230', (u_char)'\231', (u_char)'\232', (u_char)'\233',
+ (u_char)'\234', (u_char)'\235', (u_char)'\236', (u_char)'\237',
+ (u_char)'\240', (u_char)'\241', (u_char)'\242', (u_char)'\243',
+ (u_char)'\244', (u_char)'\245', (u_char)'\246', (u_char)'\247',
+ (u_char)'\250', (u_char)'\251', (u_char)'\252', (u_char)'\253',
+ (u_char)'\254', (u_char)'\255', (u_char)'\256', (u_char)'\257',
+ (u_char)'\260', (u_char)'\261', (u_char)'\262', (u_char)'\263',
+ (u_char)'\264', (u_char)'\265', (u_char)'\266', (u_char)'\267',
+ (u_char)'\270', (u_char)'\271', (u_char)'\272', (u_char)'\273',
+ (u_char)'\274', (u_char)'\275', (u_char)'\276', (u_char)'\277',
+ (u_char)'\300', (u_char)'\341', (u_char)'\342', (u_char)'\343',
+ (u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
+ (u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
+ (u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
+ (u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
+ (u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
+ (u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\333',
+ (u_char)'\334', (u_char)'\335', (u_char)'\336', (u_char)'\337',
+ (u_char)'\340', (u_char)'\341', (u_char)'\342', (u_char)'\343',
+ (u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
+ (u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
+ (u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
+ (u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
+ (u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
+ (u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\373',
+ (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
+};
+
+int
+pcap_strcasecmp(const char *s1, const char *s2)
+{
+ register const u_char *cm = charmap,
+ *us1 = (const u_char *)s1,
+ *us2 = (const u_char *)s2;
+
+ while (cm[*us1] == cm[*us2++])
+ if (*us1++ == '\0')
+ return(0);
+ return (cm[*us1] - cm[*--us2]);
+}
+
struct dlt_choice {
const char *name;
const char *description;
@@ -654,7 +836,7 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
DLT_CHOICE(DLT_IEEE802_16_MAC_CPS_RADIO, "IEEE 802.16 MAC Common Part Sublayer plus radiotap header"),
DLT_CHOICE(DLT_JUNIPER_ISM, "Juniper Integrated Service Module"),
- DLT_CHOICE(DLT_IEEE802_15_4, "IEEE 802.15.4"),
+ DLT_CHOICE(DLT_IEEE802_15_4, "IEEE 802.15.4 with FCS"),
DLT_CHOICE(DLT_SITA, "SITA pseudo-header"),
DLT_CHOICE(DLT_ERF, "Endace ERF header"),
DLT_CHOICE(DLT_RAIF1, "Ethernet with u10 Networks pseudo-header"),
@@ -674,94 +856,19 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_CAN_SOCKETCAN, "CAN-bus with SocketCAN headers"),
DLT_CHOICE(DLT_IPV4, "Raw IPv4"),
DLT_CHOICE(DLT_IPV6, "Raw IPv6"),
+ DLT_CHOICE(DLT_IEEE802_15_4_NOFCS, "IEEE 802.15.4 without FCS"),
+ DLT_CHOICE(DLT_JUNIPER_VS, "Juniper Virtual Server"),
+ DLT_CHOICE(DLT_JUNIPER_SRX_E2E, "Juniper SRX E2E"),
+ DLT_CHOICE(DLT_JUNIPER_FIBRECHANNEL, "Juniper Fibre Channel"),
+ DLT_CHOICE(DLT_DVB_CI, "DVB-CI"),
+ DLT_CHOICE(DLT_JUNIPER_ATM_CEMIC, "Juniper ATM CEMIC"),
+ DLT_CHOICE(DLT_NFLOG, "Linux netfilter log messages"),
+ DLT_CHOICE(DLT_NETANALYZER, "Ethernet with Hilscher netANALYZER pseudo-header"),
+ DLT_CHOICE(DLT_NETANALYZER_TRANSPARENT, "Ethernet with Hilscher netANALYZER pseudo-header and with preamble and SFD"),
+ DLT_CHOICE(DLT_IPOIB, "RFC 4391 IP-over-Infiniband"),
DLT_CHOICE_SENTINEL
};
-/*
- * This array is designed for mapping upper and lower case letter
- * together for a case independent comparison. The mappings are
- * based upon ascii character sequences.
- */
-static const u_char charmap[] = {
- (u_char)'\000', (u_char)'\001', (u_char)'\002', (u_char)'\003',
- (u_char)'\004', (u_char)'\005', (u_char)'\006', (u_char)'\007',
- (u_char)'\010', (u_char)'\011', (u_char)'\012', (u_char)'\013',
- (u_char)'\014', (u_char)'\015', (u_char)'\016', (u_char)'\017',
- (u_char)'\020', (u_char)'\021', (u_char)'\022', (u_char)'\023',
- (u_char)'\024', (u_char)'\025', (u_char)'\026', (u_char)'\027',
- (u_char)'\030', (u_char)'\031', (u_char)'\032', (u_char)'\033',
- (u_char)'\034', (u_char)'\035', (u_char)'\036', (u_char)'\037',
- (u_char)'\040', (u_char)'\041', (u_char)'\042', (u_char)'\043',
- (u_char)'\044', (u_char)'\045', (u_char)'\046', (u_char)'\047',
- (u_char)'\050', (u_char)'\051', (u_char)'\052', (u_char)'\053',
- (u_char)'\054', (u_char)'\055', (u_char)'\056', (u_char)'\057',
- (u_char)'\060', (u_char)'\061', (u_char)'\062', (u_char)'\063',
- (u_char)'\064', (u_char)'\065', (u_char)'\066', (u_char)'\067',
- (u_char)'\070', (u_char)'\071', (u_char)'\072', (u_char)'\073',
- (u_char)'\074', (u_char)'\075', (u_char)'\076', (u_char)'\077',
- (u_char)'\100', (u_char)'\141', (u_char)'\142', (u_char)'\143',
- (u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
- (u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
- (u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
- (u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
- (u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
- (u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\133',
- (u_char)'\134', (u_char)'\135', (u_char)'\136', (u_char)'\137',
- (u_char)'\140', (u_char)'\141', (u_char)'\142', (u_char)'\143',
- (u_char)'\144', (u_char)'\145', (u_char)'\146', (u_char)'\147',
- (u_char)'\150', (u_char)'\151', (u_char)'\152', (u_char)'\153',
- (u_char)'\154', (u_char)'\155', (u_char)'\156', (u_char)'\157',
- (u_char)'\160', (u_char)'\161', (u_char)'\162', (u_char)'\163',
- (u_char)'\164', (u_char)'\165', (u_char)'\166', (u_char)'\167',
- (u_char)'\170', (u_char)'\171', (u_char)'\172', (u_char)'\173',
- (u_char)'\174', (u_char)'\175', (u_char)'\176', (u_char)'\177',
- (u_char)'\200', (u_char)'\201', (u_char)'\202', (u_char)'\203',
- (u_char)'\204', (u_char)'\205', (u_char)'\206', (u_char)'\207',
- (u_char)'\210', (u_char)'\211', (u_char)'\212', (u_char)'\213',
- (u_char)'\214', (u_char)'\215', (u_char)'\216', (u_char)'\217',
- (u_char)'\220', (u_char)'\221', (u_char)'\222', (u_char)'\223',
- (u_char)'\224', (u_char)'\225', (u_char)'\226', (u_char)'\227',
- (u_char)'\230', (u_char)'\231', (u_char)'\232', (u_char)'\233',
- (u_char)'\234', (u_char)'\235', (u_char)'\236', (u_char)'\237',
- (u_char)'\240', (u_char)'\241', (u_char)'\242', (u_char)'\243',
- (u_char)'\244', (u_char)'\245', (u_char)'\246', (u_char)'\247',
- (u_char)'\250', (u_char)'\251', (u_char)'\252', (u_char)'\253',
- (u_char)'\254', (u_char)'\255', (u_char)'\256', (u_char)'\257',
- (u_char)'\260', (u_char)'\261', (u_char)'\262', (u_char)'\263',
- (u_char)'\264', (u_char)'\265', (u_char)'\266', (u_char)'\267',
- (u_char)'\270', (u_char)'\271', (u_char)'\272', (u_char)'\273',
- (u_char)'\274', (u_char)'\275', (u_char)'\276', (u_char)'\277',
- (u_char)'\300', (u_char)'\341', (u_char)'\342', (u_char)'\343',
- (u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
- (u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
- (u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
- (u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
- (u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
- (u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\333',
- (u_char)'\334', (u_char)'\335', (u_char)'\336', (u_char)'\337',
- (u_char)'\340', (u_char)'\341', (u_char)'\342', (u_char)'\343',
- (u_char)'\344', (u_char)'\345', (u_char)'\346', (u_char)'\347',
- (u_char)'\350', (u_char)'\351', (u_char)'\352', (u_char)'\353',
- (u_char)'\354', (u_char)'\355', (u_char)'\356', (u_char)'\357',
- (u_char)'\360', (u_char)'\361', (u_char)'\362', (u_char)'\363',
- (u_char)'\364', (u_char)'\365', (u_char)'\366', (u_char)'\367',
- (u_char)'\370', (u_char)'\371', (u_char)'\372', (u_char)'\373',
- (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
-};
-
-int
-pcap_strcasecmp(const char *s1, const char *s2)
-{
- register const u_char *cm = charmap,
- *us1 = (const u_char *)s1,
- *us2 = (const u_char *)s2;
-
- while (cm[*us1] == cm[*us2++])
- if (*us1++ == '\0')
- return(0);
- return (cm[*us1] - cm[*--us2]);
-}
-
int
pcap_datalink_name_to_val(const char *name)
{
@@ -799,6 +906,57 @@ pcap_datalink_val_to_description(int dlt)
return (NULL);
}
+struct tstamp_type_choice {
+ const char *name;
+ const char *description;
+ int type;
+};
+
+static struct tstamp_type_choice tstamp_type_choices[] = {
+ { "host", "Host", PCAP_TSTAMP_HOST },
+ { "host_lowprec", "Host, low precision", PCAP_TSTAMP_HOST_LOWPREC },
+ { "host_hiprec", "Host, high precision", PCAP_TSTAMP_HOST_HIPREC },
+ { "adapter", "Adapter", PCAP_TSTAMP_ADAPTER },
+ { "adapter_unsynced", "Adapter, not synced with system time", PCAP_TSTAMP_ADAPTER_UNSYNCED },
+ { NULL, NULL, 0 }
+};
+
+int
+pcap_tstamp_type_name_to_val(const char *name)
+{
+ int i;
+
+ for (i = 0; tstamp_type_choices[i].name != NULL; i++) {
+ if (pcap_strcasecmp(tstamp_type_choices[i].name, name) == 0)
+ return (tstamp_type_choices[i].type);
+ }
+ return (PCAP_ERROR);
+}
+
+const char *
+pcap_tstamp_type_val_to_name(int tstamp_type)
+{
+ int i;
+
+ for (i = 0; tstamp_type_choices[i].name != NULL; i++) {
+ if (tstamp_type_choices[i].type == tstamp_type)
+ return (tstamp_type_choices[i].name);
+ }
+ return (NULL);
+}
+
+const char *
+pcap_tstamp_type_val_to_description(int tstamp_type)
+{
+ int i;
+
+ for (i = 0; tstamp_type_choices[i].name != NULL; i++) {
+ if (tstamp_type_choices[i].type == tstamp_type)
+ return (tstamp_type_choices[i].description);
+ }
+ return (NULL);
+}
+
int
pcap_snapshot(pcap_t *p)
{
@@ -865,7 +1023,7 @@ pcap_geterr(pcap_t *p)
int
pcap_getnonblock(pcap_t *p, char *errbuf)
{
- return p->getnonblock_op(p, errbuf);
+ return (p->getnonblock_op(p, errbuf));
}
/*
@@ -897,7 +1055,7 @@ pcap_getnonblock_fd(pcap_t *p, char *errbuf)
int
pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{
- return p->setnonblock_op(p, nonblock, errbuf);
+ return (p->setnonblock_op(p, nonblock, errbuf));
}
#if !defined(WIN32) && !defined(MSDOS)
@@ -977,6 +1135,9 @@ pcap_statustostr(int errnum)
case PCAP_WARNING:
return("Generic warning");
+ case PCAP_WARNING_TSTAMP_TYPE_NOTSUP:
+ return ("That type of time stamp is not supported by that device");
+
case PCAP_WARNING_PROMISC_NOTSUP:
return ("That device doesn't support promiscuous mode");
@@ -1006,6 +1167,12 @@ pcap_statustostr(int errnum)
case PCAP_ERROR_IFACE_NOT_UP:
return ("That device is not up");
+
+ case PCAP_ERROR_CANTSET_TSTAMP_TYPE:
+ return ("That device doesn't support setting the time stamp type");
+
+ case PCAP_ERROR_PROMISC_PERM_DENIED:
+ return ("You don't have permission to capture in promiscuous mode on that device");
}
(void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
@@ -1034,7 +1201,7 @@ pcap_strerror(int errnum)
int
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
{
- return p->setfilter_op(p, fp);
+ return (p->setfilter_op(p, fp));
}
/*
@@ -1049,15 +1216,15 @@ pcap_setdirection(pcap_t *p, pcap_direction_t d)
if (p->setdirection_op == NULL) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"Setting direction is not implemented on this platform");
- return -1;
+ return (-1);
} else
- return p->setdirection_op(p, d);
+ return (p->setdirection_op(p, d));
}
int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
- return p->stats_op(p, ps);
+ return (p->stats_op(p, ps));
}
static int
@@ -1072,7 +1239,7 @@ pcap_stats_dead(pcap_t *p, struct pcap_stat *ps _U_)
int
pcap_setbuff(pcap_t *p, int dim)
{
- return p->setbuff_op(p, dim);
+ return (p->setbuff_op(p, dim));
}
static int
@@ -1086,7 +1253,7 @@ pcap_setbuff_dead(pcap_t *p, int dim)
int
pcap_setmode(pcap_t *p, int mode)
{
- return p->setmode_op(p, mode);
+ return (p->setmode_op(p, mode));
}
static int
@@ -1100,7 +1267,7 @@ pcap_setmode_dead(pcap_t *p, int mode)
int
pcap_setmintocopy(pcap_t *p, int size)
{
- return p->setmintocopy_op(p, size);
+ return (p->setmintocopy_op(p, size));
}
static int
@@ -1213,6 +1380,11 @@ pcap_cleanup_live_common(pcap_t *p)
p->dlt_list = NULL;
p->dlt_count = 0;
}
+ if (p->tstamp_type_list != NULL) {
+ free(p->tstamp_type_list);
+ p->tstamp_type_list = NULL;
+ p->tstamp_type_count = 0;
+ }
pcap_freecode(&p->fcode);
#if !defined(WIN32) && !defined(MSDOS)
if (p->fd >= 0) {
@@ -1249,7 +1421,7 @@ pcap_open_dead(int linktype, int snaplen)
#endif
p->cleanup_op = pcap_cleanup_dead;
p->activated = 1;
- return p;
+ return (p);
}
/*
OpenPOWER on IntegriCloud