aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-sita.c
diff options
context:
space:
mode:
authorguy <guy>2008-04-04 19:37:44 +0000
committerguy <guy>2008-04-04 19:37:44 +0000
commitd9b420231a4428234f666eb6c44a4dea6f1f2d71 (patch)
tree83275824f39128a3f3ce9860b5cd8ed99b5a216f /pcap-sita.c
parent19d1a629c7adea3d04f53c69d08cc4ce9e1693b0 (diff)
From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set the properties of the pcap_t handle" routines, so that, for example, the buffer size can be set on a BPF device before the device is bound to an interface. Add additional routines to set monitor mode, and make at least an initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and 10.5. (Very much "initial" for Linux, which is a twisty little maze of wireless drivers, many different.) Have a "timeout" member of the pcap_md structure on all platforms, use that on Windows instead of the "timeout" member of the pcap_t structure, and get rid of the "timeout" member of that structure.
Diffstat (limited to 'pcap-sita.c')
-rw-r--r--pcap-sita.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/pcap-sita.c b/pcap-sita.c
index 658362c..8634922 100644
--- a/pcap-sita.c
+++ b/pcap-sita.c
@@ -917,25 +917,19 @@ static int pcap_read_acn(pcap_t *handle, int max_packets, pcap_handler callback,
return 1;
}
-pcap_t *pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, char *ebuf) {
- pcap_t *handle;
+static int pcap_activate_sita(pcap_t *handle) {
int fd;
- /* Allocate a handle for this session. */
-
- handle = malloc(sizeof(*handle));
- if (handle == NULL) {
- snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
- pcap_strerror(errno));
- return NULL;
+ if (handle->opt.rfmon) {
+ /*
+ * No monitor mode on SITA devices (they're not Wi-Fi
+ * devices).
+ */
+ return PCAP_ERROR_RFMON_NOTSUP;
}
/* Initialize some components of the pcap structure. */
- memset(handle, 0, sizeof(*handle));
- handle->snapshot = snaplen;
- handle->md.timeout = to_ms;
-
handle->inject_op = pcap_inject_acn;
handle->setfilter_op = pcap_setfilter_acn;
handle->setdirection_op = pcap_setdirection_acn;
@@ -946,12 +940,11 @@ pcap_t *pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
handle->read_op = pcap_read_acn;
handle->stats_op = pcap_stats_acn;
- fd = acn_open_live(device, ebuf, &handle->linktype);
- if (fd == -1) {
- free(handle);
- return NULL;
- }
- handle->md.clear_promisc = promisc;
+ fd = acn_open_live(handle->opt.source, handle->errbuf,
+ &handle->linktype);
+ if (fd == -1)
+ return PCAP_ERROR;
+ handle->md.clear_promisc = handle->md.promisc;
handle->fd = fd;
handle->bufsize = handle->snapshot;
@@ -959,11 +952,10 @@ pcap_t *pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
handle->buffer = malloc(handle->bufsize + handle->offset);
if (!handle->buffer) {
- snprintf(ebuf, PCAP_ERRBUF_SIZE,
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
pcap_close_acn(handle);
- free(handle);
- return NULL;
+ return PCAP_ERROR;
}
/*
@@ -972,5 +964,16 @@ pcap_t *pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
*/
handle->selectable_fd = handle->fd;
- return handle;
+ return 0;
+}
+
+pcap_t *pcap_create(const char *device, char *ebuf) {
+ pcap_t *p;
+
+ p = pcap_create_common(device, ebuf);
+ if (p == NULL)
+ return (NULL);
+
+ p->activate_op = pcap_activate_sita;
+ return (p);
}