aboutsummaryrefslogtreecommitdiff
path: root/pcap-libdlpi.c
diff options
context:
space:
mode:
authorguy <guy>2008-04-14 20:40:58 +0000
committerguy <guy>2008-04-14 20:40:58 +0000
commit2527d1ac889ed9b6c6c36d1d312700a643beb346 (patch)
tree26a05e35cdf7c3c5aec5c65892c2a5f185a6a285 /pcap-libdlpi.c
parent0fdc174e4c2d9dfd58a11027ab8ce3b5f99874a5 (diff)
downloadlibpcap-2527d1ac889ed9b6c6c36d1d312700a643beb346.tar.gz
Turn close_op into cleanup_op; the routine that handles it can also be
used to clean up after a failed pcap_activate() call. Convert the existing close_op routines to cleanup_op routines, and use them to clean up; rename pcap_close_common() to pcap_cleanup_live_common(), and use it directly if there's no platform-dependent cleanup needed. That means we don't have to write the same cleanup code twice (and possibly forget stuff in the version done on a failed pcap_activate() call). Have the cleanup routines do whatever is necessary to indicate that cleanup has been done, and not do any particular cleaning up if it's already been done (i.e., don't free something if the pointer to it is null and null out the pointer once it's been freed, don't close an FD if it's -1 and set it to -1 once it's been closed, etc.). For device types/platforms where we don't support monitor mode, check for it and return PCAP_ERROR_RFMON_NOTSUP - but do so after we've checked whether we can open the device, so we return "no such device" or "permission denied" rather than "that device doesn't support monitor mode" if we can't open the device in the first place. Fix a comment.
Diffstat (limited to 'pcap-libdlpi.c')
-rw-r--r--pcap-libdlpi.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/pcap-libdlpi.c b/pcap-libdlpi.c
index 90029847..8666117f 100644
--- a/pcap-libdlpi.c
+++ b/pcap-libdlpi.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-libdlpi.c,v 1.5 2008-04-09 19:58:02 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-libdlpi.c,v 1.6 2008-04-14 20:40:58 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -104,8 +104,6 @@ pcap_activate_libdlpi(pcap_t *p)
dlpi_info_t dlinfo;
int err = PCAP_ERROR;
- p->fd = -1; /* indicate that it hasn't been opened yet */
-
/*
* Enable Solaris raw and passive DLPI extensions;
* dlpi_open() will not fail if the underlying link does not support
@@ -211,14 +209,11 @@ pcap_activate_libdlpi(pcap_t *p)
p->getnonblock_op = pcap_getnonblock_fd;
p->setnonblock_op = pcap_setnonblock_fd;
p->stats_op = pcap_stats_dlpi;
- p->close_op = pcap_close_libdlpi;
+ p->cleanup_op = pcap_cleanup_libdlpi;
return (0);
bad:
- /* Get rid of any link-layer type list we allocated. */
- if (p->dlt_list != NULL)
- free(p->dlt_list);
- dlpi_close(p->dlpi_hd);
+ pcap_cleanup_libdlpi(p);
return (err);
}
@@ -338,13 +333,17 @@ pcap_inject_libdlpi(pcap_t *p, const void *buf, size_t size)
}
/*
- * Close dlpi handle and deallocate data buffer.
+ * Close dlpi handle.
*/
static void
-pcap_close_libdlpi(pcap_t *p)
+pcap_cleanup_libdlpi(pcap_t *p)
{
- dlpi_close(p->dlpi_hd);
- free(p->buffer);
+ if (p->dlpi_hd != NULL) {
+ dlpi_close(p->dlpi_hd);
+ p->dlpi_hd = NULL;
+ p->fd = -1;
+ }
+ pcap_cleanup_live_common(p);
}
/*