dect
/
libpcap
Archived
13
0
Fork 0

Add pcap_free_datalinks() - on Windows, something allocated in Vegas^Wa

library has to be freed by the library, as an application or other
library using that library might have been built with a different
version of the C runtime library.
This commit is contained in:
guy 2008-05-26 19:58:06 +00:00
parent c975220bd1
commit d592f692d0
6 changed files with 68 additions and 6 deletions

1
FILES
View File

@ -138,6 +138,7 @@ pcap_fileno.3pcap
pcap_findalldevs.3pcap
pcap_freealldevs.3pcap
pcap_freecode.3pcap
pcap_free_datalinks.3pcap
pcap_get_selectable_fd.3pcap
pcap_geterr.3pcap
pcap_inject.3pcap

View File

@ -17,7 +17,7 @@
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.119 2008-05-13 15:19:56 guy Exp $ (LBL)
# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.120 2008-05-26 19:58:06 guy Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@ -120,6 +120,7 @@ MAN3PCAP = pcap.3pcap \
pcap_findalldevs.3pcap \
pcap_freealldevs.3pcap \
pcap_freecode.3pcap \
pcap_free_datalinks.3pcap \
pcap_get_selectable_fd.3pcap \
pcap_geterr.3pcap \
pcap_inject.3pcap \

19
pcap.c
View File

@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.121 2008-05-13 15:19:56 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.122 2008-05-26 19:58:06 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -453,6 +453,23 @@ pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
}
}
/*
* 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_datalinks() routine to free up the list
* allocated by pcap_list_datalinks(), even though it's just a wrapper
* around free().
*/
void
pcap_free_datalinks(int *dlt_list)
{
free(dlt_list);
}
int
pcap_set_datalink(pcap_t *p, int dlt)
{

View File

@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.11 2008-05-13 15:19:56 guy Exp $ (LBL)
* @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.12 2008-05-26 19:58:06 guy Exp $ (LBL)
*/
#ifndef lib_pcap_pcap_h
@ -294,6 +294,7 @@ int pcap_datalink(pcap_t *);
int pcap_datalink_ext(pcap_t *);
int pcap_list_datalinks(pcap_t *, int **);
int pcap_set_datalink(pcap_t *, int);
void pcap_free_datalinks(int *);
int pcap_datalink_name_to_val(const char *);
const char *pcap_datalink_val_to_name(int);
const char *pcap_datalink_val_to_description(int);

41
pcap_free_datalinks.3pcap Normal file
View File

@ -0,0 +1,41 @@
.\" @(#) $Header: /tcpdump/master/libpcap/pcap_free_datalinks.3pcap,v 1.1 2008-05-26 19:58:06 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that: (1) source code distributions
.\" retain the above copyright notice and this paragraph in its entirety, (2)
.\" distributions including binary code include the above copyright notice and
.\" this paragraph in its entirety in the documentation or other materials
.\" provided with the distribution, and (3) all advertising materials mentioning
.\" features or use of this software display the following acknowledgement:
.\" ``This product includes software developed by the University of California,
.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
.\" the University nor the names of its contributors may be used to endorse
.\" or promote products derived from this software without specific prior
.\" written permission.
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP_FREE_DATALINKS 3PCAP "26 May 2008"
.SH NAME
pcap_free_datalinks \- free a list of link-layer header types from
pcap_get_datalinks()
.SH SYNOPSIS
.nf
.ft B
#include <pcap/pcap.h>
.ft
.LP
.ft B
void pcap_free_datalinks(int *dlt_list);
.ft
.fi
.SH DESCRIPTION
.B pcap_free_datalinks()
is used to free a list of supported data link types returned by
.BR pcap_list_datalinks() .
.SH SEE ALSO
pcap(3PCAP), pcap_list_datalinks(3PCAP)

View File

@ -1,4 +1,4 @@
.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap_list_datalinks.3pcap,v 1.3 2008-04-06 02:53:22 guy Exp $
.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap_list_datalinks.3pcap,v 1.4 2008-05-26 19:58:06 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -41,7 +41,7 @@ associated with the pcap descriptor.
allocates an array to hold the list and sets
.IR *dlt_buf .
The caller is responsible for freeing the array with
.BR free (3).
.BR pcap_free_datalinks (3PCAP).
.SH RETURN VALUE
.B pcap_list_datalinks()
returns the number of data link types in the array on success and \-1
@ -54,4 +54,5 @@ may be called with
.I p
as an argument to fetch or display the error text.
.SH SEE ALSO
pcap(3PCAP), pcap_geterr(3PCAP), pcap-linktype(4)
pcap(3PCAP), pcap_geterr(3PCAP), pcap_free_datalinks(3PCAP),
pcap-linktype(4)