summaryrefslogtreecommitdiff
path: root/capture-pcap-util.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2007-01-21 23:45:36 +0000
committerGuy Harris <guy@alum.mit.edu>2007-01-21 23:45:36 +0000
commitcc2274816903f4ef20b406e687dfa3d4de1ac488 (patch)
tree5512510787af52895ceb934713d75bf182fa3033 /capture-pcap-util.c
parent62c148c1d58c84791033da807db32c5a5752c4b8 (diff)
downloadwireshark-cc2274816903f4ef20b406e687dfa3d4de1ac488.tar.gz
Have the routines to get interface lists take a pointer to a "gchar *"
as an argument, and, on an error, if they have an error message, have them set that "gchar *" to point to a g_malloc()ed string containing the error message, rather than taking a pointer to a buffer for that message as an argument. That's more like what's done in Wiretap, and doesn't impose an upper limit on the lengths of those error messages. If that pointer is null, don't allocate the message string and return it. Have that error message already have the "cant_get" processing applied to it, so nobody other than those routines need to call the "cant_get" routines to process the error messages. Have get_airpcap_interface_list() explicitly set "*err" to the appropriate error code. Clean up indentation. svn path=/trunk/; revision=20521
Diffstat (limited to 'capture-pcap-util.c')
-rw-r--r--capture-pcap-util.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/capture-pcap-util.c b/capture-pcap-util.c
index 1342267a91..2a5ae50bcf 100644
--- a/capture-pcap-util.c
+++ b/capture-pcap-util.c
@@ -249,14 +249,17 @@ if_info_ip(if_info_t *if_info, pcap_if_t *d)
}
GList *
-get_interface_list_findalldevs(int *err, char *err_str)
+get_interface_list_findalldevs(int *err, char **err_str)
{
GList *il = NULL;
pcap_if_t *alldevs, *dev;
if_info_t *if_info;
+ char errbuf[PCAP_ERRBUF_SIZE];
- if (pcap_findalldevs(&alldevs, err_str) == -1) {
+ if (pcap_findalldevs(&alldevs, errbuf) == -1) {
*err = CANT_GET_INTERFACE_LIST;
+ if (err_str != NULL)
+ *err_str = cant_get_if_list_error_message(errbuf);
return NULL;
}
@@ -265,6 +268,8 @@ get_interface_list_findalldevs(int *err, char *err_str)
* No interfaces found.
*/
*err = NO_INTERFACES_FOUND;
+ if (err_str != NULL)
+ *err_str = NULL;
return NULL;
}
@@ -349,28 +354,33 @@ create_data_link_info(int dlt)
}
GList *
-get_pcap_linktype_list(const char *devname, char *err_buf)
+get_pcap_linktype_list(const char *devname, char **err_str)
{
GList *linktype_list = NULL;
pcap_t *pch;
int deflt;
+ char errbuf[PCAP_ERRBUF_SIZE];
#ifdef HAVE_PCAP_SET_DATALINK
int *linktypes;
int i, nlt;
#endif
data_link_info_t *data_link_info;
- pch = pcap_open_live(devname, MIN_PACKET_SIZE, 0, 0, err_buf);
- if (pch == NULL)
+ pch = pcap_open_live(devname, MIN_PACKET_SIZE, 0, 0, errbuf);
+ if (pch == NULL) {
+ if (err_str != NULL)
+ *err_str = g_strdup(errbuf);
return NULL;
- err_buf[0] = '\0'; /* an empty list doesn't mean an error */
+ }
deflt = get_pcap_linktype(pch, devname);
#ifdef HAVE_PCAP_LIST_DATALINKS
nlt = pcap_list_datalinks(pch, &linktypes);
- if (nlt == 0 || linktypes == NULL) {
+ if (nlt == 0 || linktypes == NULL) {
pcap_close(pch);
+ if (err_str != NULL)
+ *err_str = NULL; /* an empty list doesn't mean an error */
return NULL;
- }
+ }
for (i = 0; i < nlt; i++) {
data_link_info = create_data_link_info(linktypes[i]);