From 96fece483a8a447a7550eb2798a4352143af0c5a Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 11 Aug 2009 21:31:18 -0700 Subject: [PATCH] From Dustin Spicuzza: if the activate routine doesn't supply an error message, supply the error message corresponding to the activate routine's return status, for the benefit of programs that don't handle different error returns differently. --- pcap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pcap.c b/pcap.c index 310e5d2..c9b461c 100644 --- a/pcap.c +++ b/pcap.c @@ -303,6 +303,16 @@ pcap_activate(pcap_t *p) status = p->activate_op(p); if (status >= 0) p->activated = 1; + else if (p->errbuf[0] == '\0') { + /* + * No error message supplied by the activate routine; + * for the benefit of programs that don't specially + * handle errors other than PCAP_ERROR, return the + * error message corresponding to the status. + */ + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s", + pcap_statustostr(status)); + } return (status); } @@ -343,7 +353,7 @@ fail: if (status == PCAP_ERROR) snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", source, p->errbuf); - else if(status == PCAP_ERROR_NO_SUCH_DEVICE || + else if (status == PCAP_ERROR_NO_SUCH_DEVICE || status == PCAP_ERROR_PERM_DENIED) snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", source, pcap_statustostr(status), p->errbuf);