aboutsummaryrefslogtreecommitdiffstats
path: root/caputils
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-03-15 02:55:45 -0700
committerGuy Harris <guy@alum.mit.edu>2020-03-15 10:13:39 +0000
commit0f0e486b91b7173409c70957955f39e69f613432 (patch)
tree1ac64639880bc37278823a58805ed86c2f94a2ac /caputils
parentc939ef82468e17b1379979efa839be3a04a6827b (diff)
Put common code into get_interface_list_findalldevs_ex().
Remove duplication of code. Change-Id: I7cd1bd73ee9eda962a37468cadb72de291f1ec6a Reviewed-on: https://code.wireshark.org/review/36432 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'caputils')
-rw-r--r--caputils/capture-pcap-util-int.h5
-rw-r--r--caputils/capture-pcap-util-unix.c24
-rw-r--r--caputils/capture-pcap-util.c28
-rw-r--r--caputils/capture-wpcap.c24
4 files changed, 31 insertions, 50 deletions
diff --git a/caputils/capture-pcap-util-int.h b/caputils/capture-pcap-util-int.h
index 789f96dfdf..efeb467409 100644
--- a/caputils/capture-pcap-util-int.h
+++ b/caputils/capture-pcap-util-int.h
@@ -15,8 +15,9 @@ extern if_info_t *if_info_new(const char *name, const char *description,
gboolean loopback);
extern void if_info_add_address(if_info_t *if_info, struct sockaddr *addr);
#ifdef HAVE_PCAP_REMOTE
-extern GList *get_interface_list_findalldevs_ex(const char *source,
- struct pcap_rmtauth *auth, int *err, char **err_str);
+extern GList *get_interface_list_findalldevs_ex(const char *hostname,
+ const char *port, int auth_type, const char *username, const char *passwd,
+ int *err, char **err_str);
#endif /* HAVE_PCAP_REMOTE */
extern GList *get_interface_list_findalldevs(int *err, char **err_str);
diff --git a/caputils/capture-pcap-util-unix.c b/caputils/capture-pcap-util-unix.c
index 9ad2296fbc..e963f3de60 100644
--- a/caputils/capture-pcap-util-unix.c
+++ b/caputils/capture-pcap-util-unix.c
@@ -36,28 +36,8 @@ get_remote_interface_list(const char *hostname, const char *port,
int auth_type, const char *username,
const char *passwd, int *err, char **err_str)
{
- struct pcap_rmtauth auth;
- char source[PCAP_BUF_SIZE];
- char errbuf[PCAP_ERRBUF_SIZE];
- GList *result;
-
- if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
- NULL, errbuf) == -1) {
- *err = CANT_GET_INTERFACE_LIST;
- if (err_str != NULL)
- *err_str = cant_get_if_list_error_message(errbuf);
- return NULL;
- }
-
- auth.type = auth_type;
- auth.username = g_strdup(username);
- auth.password = g_strdup(passwd);
-
- result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
- g_free(auth.username);
- g_free(auth.password);
-
- return result;
+ return get_interface_list_findalldevs_ex(hostname, port, auth_type,
+ username, passwd, err, err_str);
}
#endif
diff --git a/caputils/capture-pcap-util.c b/caputils/capture-pcap-util.c
index 6fb1eb4dd5..6b16ddceca 100644
--- a/caputils/capture-pcap-util.c
+++ b/caputils/capture-pcap-util.c
@@ -591,10 +591,12 @@ if_info_ip(if_info_t *if_info, pcap_if_t *d)
#ifdef HAVE_PCAP_REMOTE
GList *
-get_interface_list_findalldevs_ex(const char *source,
- struct pcap_rmtauth *auth,
- int *err, char **err_str)
+get_interface_list_findalldevs_ex(const char *hostname, const char *port,
+ int auth_type, const char *username,
+ const char *passwd, int *err, char **err_str)
{
+ char source[PCAP_BUF_SIZE];
+ struct pcap_rmtauth auth;
GList *il = NULL;
pcap_if_t *alldevs, *dev;
if_info_t *if_info;
@@ -604,10 +606,24 @@ get_interface_list_findalldevs_ex(const char *source,
*/
char errbuf[PCAP_ERRBUF_SIZE*4];
- if (pcap_findalldevs_ex((char *)source, auth, &alldevs, errbuf) == -1) {
+ if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
+ NULL, errbuf) == -1) {
+ *err = CANT_GET_INTERFACE_LIST;
+ if (err_str != NULL)
+ *err_str = cant_get_if_list_error_message(errbuf);
+ return NULL;
+ }
+
+ auth.type = auth_type;
+ auth.username = g_strdup(username);
+ auth.password = g_strdup(passwd);
+
+ if (pcap_findalldevs_ex(source, &auth, &alldevs, errbuf) == -1) {
*err = CANT_GET_INTERFACE_LIST;
if (err_str != NULL)
*err_str = cant_get_if_list_error_message(errbuf);
+ g_free(auth.username);
+ g_free(auth.password);
return NULL;
}
@@ -618,6 +634,8 @@ get_interface_list_findalldevs_ex(const char *source,
*err = 0;
if (err_str != NULL)
*err_str = NULL;
+ g_free(auth.username);
+ g_free(auth.password);
return NULL;
}
@@ -628,6 +646,8 @@ get_interface_list_findalldevs_ex(const char *source,
if_info_ip(if_info, dev);
}
pcap_freealldevs(alldevs);
+ g_free(auth.username);
+ g_free(auth.password);
return il;
}
diff --git a/caputils/capture-wpcap.c b/caputils/capture-wpcap.c
index 0835b707c4..0d856fe8a5 100644
--- a/caputils/capture-wpcap.c
+++ b/caputils/capture-wpcap.c
@@ -633,11 +633,6 @@ get_remote_interface_list(const char *hostname, const char *port,
int auth_type, const char *username,
const char *passwd, int *err, char **err_str)
{
- struct pcap_rmtauth auth;
- char source[PCAP_BUF_SIZE];
- char errbuf[PCAP_ERRBUF_SIZE];
- GList *result;
-
if (!has_wpcap) {
/*
* We don't have Npcap or WinPcap, so we can't get a list of
@@ -649,23 +644,8 @@ get_remote_interface_list(const char *hostname, const char *port,
return NULL;
}
- if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
- NULL, errbuf) == -1) {
- *err = CANT_GET_INTERFACE_LIST;
- if (err_str != NULL)
- *err_str = cant_get_if_list_error_message(errbuf);
- return NULL;
- }
-
- auth.type = auth_type;
- auth.username = g_strdup(username);
- auth.password = g_strdup(passwd);
-
- result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
- g_free(auth.username);
- g_free(auth.password);
-
- return result;
+ return get_interface_list_findalldevs_ex(hostname, port, auth_type,
+ username, passwd, err, err_str);
}
#endif