dect
/
libpcap
Archived
13
0
Fork 0

For Linux non-mmapped captures, Linux bluetooth captures, and Irix

captures, set the socket buffer size to the value specified by
pcap_set_buffer_size() if a value was set.

Clean up if memory buffer allocation fails on Linux.
This commit is contained in:
guy 2008-04-07 03:57:32 +00:00
parent 3df4925c28
commit b95b96d6da
3 changed files with 48 additions and 13 deletions

View File

@ -33,7 +33,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.11 2008-04-04 19:37:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.12 2008-04-07 03:57:32 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -162,7 +162,7 @@ bt_activate(pcap_t* handle)
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get Bluetooth device index from %s",
handle->opt.source);
return -1;
return PCAP_ERROR;
}
/* Initialize some components of the pcap structure. */
@ -186,7 +186,7 @@ bt_activate(pcap_t* handle)
if (handle->fd < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s",
errno, strerror(errno));
return -1;
return PCAP_ERROR;
}
handle->buffer = malloc(handle->bufsize);
@ -230,12 +230,26 @@ bt_activate(pcap_t* handle)
handle->md.ifindex, errno, strerror(errno));
goto close_fail;
}
if (handle->opt.buffer_size == 0) {
/*
* Set the socket buffer size to the specified value.
*/
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
&handle->opt.buffer_size,
sizeof(handle->opt.buffer_size)) == -1) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"SO_RCVBUF: %s", pcap_strerror(errno));
goto close_fail;
}
}
handle->selectable_fd = handle->fd;
return 0;
close_fail:
close(handle->fd);
return -1;
return PCAP_ERROR;
}
static int

View File

@ -34,7 +34,7 @@
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.142 2008-04-07 00:31:47 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.143 2008-04-07 03:57:32 guy Exp $ (LBL)";
#endif
/*
@ -553,12 +553,21 @@ pcap_activate_linux(pcap_t *handle)
* up and report our failure (ebuf is expected to be
* set by the functions above).
*/
goto fail;
}
if (handle->md.device != NULL) {
free(handle->md.device);
handle->md.device = NULL;
if (handle->opt.buffer_size == 0) {
/*
* Set the socket buffer size to the specified value.
*/
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
&handle->opt.buffer_size,
sizeof(handle->opt.buffer_size)) == -1) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"SO_RCVBUF: %s", pcap_strerror(errno));
err = PCAP_ERROR;
goto fail;
}
return err;
}
/* Allocate the buffer */
@ -567,7 +576,8 @@ pcap_activate_linux(pcap_t *handle)
if (!handle->buffer) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"malloc: %s", pcap_strerror(errno));
return PCAP_ERROR;
err = PCAP_ERROR;
goto fail;
}
/*
@ -577,6 +587,14 @@ pcap_activate_linux(pcap_t *handle)
handle->selectable_fd = handle->fd;
return 0;
fail:
close(handle->fd);
if (handle->md.device != NULL) {
free(handle->md.device);
handle->md.device = NULL;
}
return err;
}
/*
@ -1775,7 +1793,7 @@ activate_new(pcap_t *handle)
handle->bufsize = handle->snapshot;
/* Save the socket FD in the pcap structure */
handle->fd = sock_fd;
handle->fd = sock_fd;
return 1;
#else

View File

@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.56 2008-04-04 19:37:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.57 2008-04-07 03:57:32 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -234,7 +234,10 @@ pcap_activate_snoop(pcap_t *p)
pcap_strerror(errno));
goto bad;
}
v = 64 * 1024;
if (handle->opt.buffer_size != 0)
v = handle->opt.buffer_size;
else
v = 64 * 1024; /* default to 64K buffer size */
(void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&v, sizeof(v));
/*
* XXX hack - map device name to link layer type