From 2527d1ac889ed9b6c6c36d1d312700a643beb346 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 14 Apr 2008 20:40:58 +0000 Subject: 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. --- pcap-sita.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pcap-sita.c') diff --git a/pcap-sita.c b/pcap-sita.c index 8634922..971f8b0 100644 --- a/pcap-sita.c +++ b/pcap-sita.c @@ -344,7 +344,7 @@ static void close_with_IOP(int chassis, int geoslot, int flag) { } } -static void pcap_close_acn(pcap_t *handle) { +static void pcap_cleanup_acn(pcap_t *handle) { int chassis, geoslot; unit_t *u; @@ -353,6 +353,7 @@ static void pcap_close_acn(pcap_t *handle) { close_with_IOP(chassis, geoslot, LIVE); if (u) u->first_time = 0; + pcap_cleanup_live_common(handle); } static void send_to_fd(int fd, int len, unsigned char *str) { @@ -936,7 +937,7 @@ static int pcap_activate_sita(pcap_t *handle) { handle->set_datalink_op = NULL; /* can't change data link type */ handle->getnonblock_op = pcap_getnonblock_fd; handle->setnonblock_op = pcap_setnonblock_fd; - handle->close_op = pcap_close_acn; + handle->cleanup_op = pcap_cleanup_acn; handle->read_op = pcap_read_acn; handle->stats_op = pcap_stats_acn; @@ -954,7 +955,7 @@ static int pcap_activate_sita(pcap_t *handle) { if (!handle->buffer) { snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); - pcap_close_acn(handle); + pcap_cleanup_acn(handle); return PCAP_ERROR; } -- cgit v1.2.3