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:
parent
3df4925c28
commit
b95b96d6da
|
@ -33,7 +33,7 @@
|
||||||
*/
|
*/
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] _U_ =
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -162,7 +162,7 @@ bt_activate(pcap_t* handle)
|
||||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||||
"Can't get Bluetooth device index from %s",
|
"Can't get Bluetooth device index from %s",
|
||||||
handle->opt.source);
|
handle->opt.source);
|
||||||
return -1;
|
return PCAP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize some components of the pcap structure. */
|
/* Initialize some components of the pcap structure. */
|
||||||
|
@ -186,7 +186,7 @@ bt_activate(pcap_t* handle)
|
||||||
if (handle->fd < 0) {
|
if (handle->fd < 0) {
|
||||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s",
|
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
return -1;
|
return PCAP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->buffer = malloc(handle->bufsize);
|
handle->buffer = malloc(handle->bufsize);
|
||||||
|
@ -230,12 +230,26 @@ bt_activate(pcap_t* handle)
|
||||||
handle->md.ifindex, errno, strerror(errno));
|
handle->md.ifindex, errno, strerror(errno));
|
||||||
goto close_fail;
|
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;
|
handle->selectable_fd = handle->fd;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
close_fail:
|
close_fail:
|
||||||
close(handle->fd);
|
close(handle->fd);
|
||||||
return -1;
|
return PCAP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
32
pcap-linux.c
32
pcap-linux.c
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] _U_ =
|
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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -553,12 +553,21 @@ pcap_activate_linux(pcap_t *handle)
|
||||||
* up and report our failure (ebuf is expected to be
|
* up and report our failure (ebuf is expected to be
|
||||||
* set by the functions above).
|
* 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 */
|
/* Allocate the buffer */
|
||||||
|
@ -567,7 +576,8 @@ pcap_activate_linux(pcap_t *handle)
|
||||||
if (!handle->buffer) {
|
if (!handle->buffer) {
|
||||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||||
"malloc: %s", pcap_strerror(errno));
|
"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;
|
handle->selectable_fd = handle->fd;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
close(handle->fd);
|
||||||
|
if (handle->md.device != NULL) {
|
||||||
|
free(handle->md.device);
|
||||||
|
handle->md.device = NULL;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] _U_ =
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -234,7 +234,10 @@ pcap_activate_snoop(pcap_t *p)
|
||||||
pcap_strerror(errno));
|
pcap_strerror(errno));
|
||||||
goto bad;
|
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));
|
(void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&v, sizeof(v));
|
||||||
/*
|
/*
|
||||||
* XXX hack - map device name to link layer type
|
* XXX hack - map device name to link layer type
|
||||||
|
|
Reference in New Issue