dect
/
libpcap
Archived
13
0
Fork 0

Have a separate pcap_errtostr() routine to turn PCAP_ERROR_ values to

strings; leave pcap_strerror() for UN*X errnos.
This commit is contained in:
guy 2008-04-06 19:55:32 +00:00
parent 9e496cdc75
commit a161340b6e
5 changed files with 78 additions and 34 deletions

1
FILES
View File

@ -132,6 +132,7 @@ pcap_dump_file.3pcap
pcap_dump_flush.3pcap
pcap_dump_ftell.3pcap
pcap_dump_open.3pcap
pcap_errtostr.3pcap
pcap_file.3pcap
pcap_fileno.3pcap
pcap_findalldevs.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.114 2008-04-06 17:29:31 guy Exp $ (LBL)
# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.115 2008-04-06 19:55:32 guy Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@ -114,6 +114,7 @@ MAN3PCAP = pcap.3pcap \
pcap_dump_flush.3pcap \
pcap_dump_ftell.3pcap \
pcap_dump_open.3pcap \
pcap_errtostr.3pcap \
pcap_file.3pcap \
pcap_fileno.3pcap \
pcap_findalldevs.3pcap \

62
pcap.c
View File

@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.115 2008-04-04 19:37:45 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.116 2008-04-06 19:55:32 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -883,60 +883,60 @@ pcap_win32strerror(void)
#endif
/*
* Not all systems have strerror().
* We also use this to generate error strings for PCAP_ERROR_ values.
* Generate error strings for PCAP_ERROR_ values.
*/
const char *
pcap_strerror(int errnum)
pcap_errtostr(int errnum)
{
static char ebuf[128+1];
#ifndef HAVE_STRERROR
extern int sys_nerr;
extern const char *const sys_errlist[];
#endif
static char ebuf[15+10+1];
switch (errnum) {
case PCAP_ERROR:
(void)snprintf(ebuf, sizeof ebuf, "Generic error");
return(ebuf);
return("Generic error");
case PCAP_ERROR_BREAK:
(void)snprintf(ebuf, sizeof ebuf, "Loop terminated by pcap_breakloop");
return(ebuf);
return("Loop terminated by pcap_breakloop");
case PCAP_ERROR_NOT_ACTIVATED:
(void)snprintf(ebuf, sizeof ebuf, "The pcap_t has not been activated");
return(ebuf);
return("The pcap_t has not been activated");
case PCAP_ERROR_ACTIVATED:
(void)snprintf(ebuf, sizeof ebuf, "The setting can't be changed after the pcap_t is activated");
return(ebuf);
return ("The setting can't be changed after the pcap_t is activated");
case PCAP_ERROR_NO_SUCH_DEVICE:
(void)snprintf(ebuf, sizeof ebuf, "No such device exists");
return(ebuf);
return ("No such device exists");
case PCAP_ERROR_RFMON_NOTSUP:
(void)snprintf(ebuf, sizeof ebuf, "That device doesn't support monitor mode");
return(ebuf);
return ("That device doesn't support monitor mode");
case PCAP_ERROR_NOT_RFMON:
(void)snprintf(ebuf, sizeof ebuf, "That operation is supported only in monitor mode");
return(ebuf);
}
if (errnum >= 0) {
#ifdef HAVE_STRERROR
return (strerror(errnum));
#else
if ((unsigned int)errnum < sys_nerr)
return ((char *)sys_errlist[errnum]);
#endif
return ("That operation is supported only in monitor mode");
}
(void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
}
/*
* Not all systems have strerror().
*/
const char *
pcap_strerror(int errnum)
{
#ifdef HAVE_STRERROR
return (strerror(errnum));
#else
extern int sys_nerr;
extern const char *const sys_errlist[];
static char ebuf[15+10+1];
if ((unsigned int)errnum < sys_nerr)
return ((char *)sys_errlist[errnum]);
(void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
#endif
}
int
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
{

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.6 2008-04-04 19:37:45 guy Exp $ (LBL)
* @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.7 2008-04-06 19:55:33 guy Exp $ (LBL)
*/
#ifndef lib_pcap_pcap_h
@ -263,11 +263,12 @@ int pcap_setfilter(pcap_t *, struct bpf_program *);
int pcap_setdirection(pcap_t *, pcap_direction_t);
int pcap_getnonblock(pcap_t *, char *);
int pcap_setnonblock(pcap_t *, int, char *);
void pcap_perror(pcap_t *, char *);
int pcap_inject(pcap_t *, const void *, size_t);
int pcap_sendpacket(pcap_t *, const u_char *, int);
const char *pcap_errtostr(int);
const char *pcap_strerror(int);
char *pcap_geterr(pcap_t *);
void pcap_perror(pcap_t *, char *);
int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
bpf_u_int32);
int pcap_compile_nopcap(int, int, struct bpf_program *,

41
pcap_errtostr.3pcap Normal file
View File

@ -0,0 +1,41 @@
.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap_errtostr.3pcap,v 1.1 2008-04-06 19:55:33 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_ERRTOSTR 3PCAP "6 April 2008"
.SH NAME
pcap_errtostr \- convert a PCAP_ERROR_ value to a string
.SH SYNOPSIS
.nf
.ft B
#include <pcap/pcap.h>
.ft
.LP
.ft B
const char *pcap_errtostr(int error);
.ft
.fi
.SH DESCRIPTION
.B pcap_errtostr()
converts a
.B PCAP_ERROR_
value returned by a libpcap routine to an error string.
.SH SEE ALSO
pcap(3PCAP)