forked from osmocom/wireshark
Clean up modelines and indentation.
To quote Icf0831717de10fc615971fa1cf75af2f1ea2d03d: HT tab stops are set every 8 spaces on UN*X; UN*X tools that treat an HT character as tabbing to 4-space tab stops, or that even are configurable but *default* to 4-space tab stops (I'm looking at *you*, Xcode!) are broken. tab-width: 4, tabstop=4, and tabSize=4 are errors if you ever expect anybody to look at your file with a UN*X tool, and every text file will probably be looked at by a UN*X tool at some point, so Don't Do That. Adjust indentation to reflect the mode lines. Change-Id: Ic829541c696e0ddbc45cc109009319859c799066 Reviewed-on: https://code.wireshark.org/review/14340 Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
This commit is contained in:
parent
637aefd2b3
commit
ab5614ae10
|
@ -2605,6 +2605,6 @@ void proto_reg_handoff_pcp(void)
|
||||||
* indent-tabs-mode: nil
|
* indent-tabs-mode: nil
|
||||||
* End:
|
* End:
|
||||||
*
|
*
|
||||||
* vi: set shiftwidth=4 tabstop=4 expandtab:
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
||||||
* :indentSize=4:tabSize=8:noTabs=true:
|
* :indentSize=4:tabSize=8:noTabs=true:
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,9 +37,9 @@
|
||||||
* cog.py -D xmlfile=tools/SkinnyProtocolOptimized.xml -d -c -o epan/dissectors/packet-skinny.c epan/dissectors/packet-skinny.c.in
|
* cog.py -D xmlfile=tools/SkinnyProtocolOptimized.xml -d -c -o epan/dissectors/packet-skinny.c epan/dissectors/packet-skinny.c.in
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
|
/* c-basic-offset: 2; tab-width: 8; indent-tabs-mode: nil
|
||||||
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
||||||
* :indentSize=2:tabSize=2:noTabs=true:
|
* :indentSize=2:tabSize=8:noTabs=true:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -9748,10 +9748,10 @@ proto_reg_handoff_skinny(void)
|
||||||
*
|
*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-basic-offset: 2
|
* c-basic-offset: 2
|
||||||
* tab-width: 2
|
* tab-width: 8
|
||||||
* indent-tabs-mode: nil
|
* indent-tabs-mode: nil
|
||||||
* End:
|
* End:
|
||||||
*
|
*
|
||||||
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
||||||
* :indentSize=2:tabSize=2:noTabs=true:
|
* :indentSize=2:tabSize=8:noTabs=true:
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -50,9 +50,9 @@ cog.out(' */\n')
|
||||||
|
|
||||||
/*[[[end]]]*/
|
/*[[[end]]]*/
|
||||||
|
|
||||||
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
|
/* c-basic-offset: 2; tab-width: 8; indent-tabs-mode: nil
|
||||||
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
||||||
* :indentSize=2:tabSize=2:noTabs=true:
|
* :indentSize=2:tabSize=8:noTabs=true:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -551,10 +551,10 @@ proto_reg_handoff_skinny(void)
|
||||||
*
|
*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-basic-offset: 2
|
* c-basic-offset: 2
|
||||||
* tab-width: 2
|
* tab-width: 8
|
||||||
* indent-tabs-mode: nil
|
* indent-tabs-mode: nil
|
||||||
* End:
|
* End:
|
||||||
*
|
*
|
||||||
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
||||||
* :indentSize=2:tabSize=2:noTabs=true:
|
* :indentSize=2:tabSize=8:noTabs=true:
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,235 +31,235 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef HAVE_GETOPT_H
|
#ifdef HAVE_GETOPT_H
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_GETOPT_LONG
|
#ifndef HAVE_GETOPT_LONG
|
||||||
#include "wsutil/wsgetopt.h"
|
#include "wsutil/wsgetopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum extcap_options {
|
enum extcap_options {
|
||||||
EXTCAP_BASE_OPTIONS_ENUM
|
EXTCAP_BASE_OPTIONS_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _extcap_interface
|
typedef struct _extcap_interface
|
||||||
{
|
{
|
||||||
char * interface;
|
char * interface;
|
||||||
char * description;
|
char * description;
|
||||||
|
|
||||||
uint16_t dlt;
|
uint16_t dlt;
|
||||||
char * dltname;
|
char * dltname;
|
||||||
char * dltdescription;
|
char * dltdescription;
|
||||||
} extcap_interface;
|
} extcap_interface;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
BOOLEAN IsHandleRedirected(DWORD handle)
|
BOOLEAN IsHandleRedirected(DWORD handle)
|
||||||
{
|
{
|
||||||
HANDLE h = GetStdHandle(handle);
|
HANDLE h = GetStdHandle(handle);
|
||||||
if (h) {
|
if (h) {
|
||||||
BY_HANDLE_FILE_INFORMATION fi;
|
BY_HANDLE_FILE_INFORMATION fi;
|
||||||
if (GetFileInformationByHandle(h, &fi)) {
|
if (GetFileInformationByHandle(h, &fi)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
}
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void attach_parent_console()
|
void attach_parent_console()
|
||||||
{
|
{
|
||||||
BOOL outRedirected, errRedirected;
|
BOOL outRedirected, errRedirected;
|
||||||
|
|
||||||
outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
|
outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
|
||||||
errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
|
errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
|
||||||
|
|
||||||
if (outRedirected && errRedirected) {
|
if (outRedirected && errRedirected) {
|
||||||
/* Both standard output and error handles are redirected.
|
/* Both standard output and error handles are redirected.
|
||||||
* There is no point in attaching to parent process console.
|
* There is no point in attaching to parent process console.
|
||||||
*/
|
*/
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
|
||||||
|
/* Console attach failed. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Console attach succeeded */
|
||||||
|
if (outRedirected == FALSE) {
|
||||||
|
if (!freopen("CONOUT$", "w", stdout)) {
|
||||||
|
errmsg_print("WARNING: Cannot redirect to stdout.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
|
if (errRedirected == FALSE) {
|
||||||
/* Console attach failed. */
|
if (!freopen("CONOUT$", "w", stderr)) {
|
||||||
return;
|
errmsg_print("WARNING: Cannot redirect to strerr.");
|
||||||
}
|
|
||||||
|
|
||||||
/* Console attach succeeded */
|
|
||||||
if (outRedirected == FALSE) {
|
|
||||||
if (!freopen("CONOUT$", "w", stdout)) {
|
|
||||||
errmsg_print("WARNING: Cannot redirect to stdout.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errRedirected == FALSE) {
|
|
||||||
if (!freopen("CONOUT$", "w", stderr)) {
|
|
||||||
errmsg_print("WARNING: Cannot redirect to strerr.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription )
|
void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription )
|
||||||
{
|
{
|
||||||
extcap_base_register_interface_ext(extcap, interface, ifdescription, dlt, NULL, dltdescription );
|
extcap_base_register_interface_ext(extcap, interface, ifdescription, dlt, NULL, dltdescription );
|
||||||
}
|
}
|
||||||
|
|
||||||
void extcap_base_register_interface_ext(extcap_parameters * extcap,
|
void extcap_base_register_interface_ext(extcap_parameters * extcap,
|
||||||
const char * interface, const char * ifdescription,
|
const char * interface, const char * ifdescription,
|
||||||
uint16_t dlt, const char * dltname, const char * dltdescription )
|
uint16_t dlt, const char * dltname, const char * dltdescription )
|
||||||
{
|
{
|
||||||
extcap_interface * iface = g_new0(extcap_interface, 1);
|
extcap_interface * iface = g_new0(extcap_interface, 1);
|
||||||
|
|
||||||
if (interface == NULL)
|
if (interface == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
iface->interface = g_strdup(interface);
|
iface->interface = g_strdup(interface);
|
||||||
iface->description = g_strdup(ifdescription);
|
iface->description = g_strdup(ifdescription);
|
||||||
iface->dlt = dlt;
|
iface->dlt = dlt;
|
||||||
iface->dltname = g_strdup(dltname);
|
iface->dltname = g_strdup(dltname);
|
||||||
iface->dltdescription = g_strdup(dltdescription);
|
iface->dltdescription = g_strdup(dltdescription);
|
||||||
|
|
||||||
extcap->interfaces = g_list_append(extcap->interfaces, (gpointer) iface);
|
extcap->interfaces = g_list_append(extcap->interfaces, (gpointer) iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extcap_base_set_util_info(extcap_parameters * extcap, const char * major, const char * minor, const char * release, const char * helppage)
|
void extcap_base_set_util_info(extcap_parameters * extcap, const char * major, const char * minor, const char * release, const char * helppage)
|
||||||
{
|
{
|
||||||
g_assert(major);
|
g_assert(major);
|
||||||
extcap->version = g_strdup_printf("%s%s%s%s%s",
|
extcap->version = g_strdup_printf("%s%s%s%s%s",
|
||||||
major,
|
major,
|
||||||
minor ? "." : "",
|
minor ? "." : "",
|
||||||
minor ? minor : "",
|
minor ? minor : "",
|
||||||
release ? "." : "",
|
release ? "." : "",
|
||||||
release ? release : "");
|
release ? release : "");
|
||||||
extcap->helppage = g_strdup(helppage);
|
extcap->helppage = g_strdup(helppage);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument )
|
uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument )
|
||||||
{
|
{
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case EXTCAP_OPT_LIST_INTERFACES:
|
case EXTCAP_OPT_LIST_INTERFACES:
|
||||||
extcap->do_list_interfaces = 1;
|
extcap->do_list_interfaces = 1;
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_VERSION:
|
case EXTCAP_OPT_VERSION:
|
||||||
extcap->do_version = 1;
|
extcap->do_version = 1;
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_LIST_DLTS:
|
case EXTCAP_OPT_LIST_DLTS:
|
||||||
extcap->do_list_dlts = 1;
|
extcap->do_list_dlts = 1;
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_INTERFACE:
|
case EXTCAP_OPT_INTERFACE:
|
||||||
extcap->interface = g_strdup(optargument);
|
extcap->interface = g_strdup(optargument);
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_CONFIG:
|
case EXTCAP_OPT_CONFIG:
|
||||||
extcap->show_config = 1;
|
extcap->show_config = 1;
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_CAPTURE:
|
case EXTCAP_OPT_CAPTURE:
|
||||||
extcap->capture = 1;
|
extcap->capture = 1;
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_CAPTURE_FILTER:
|
case EXTCAP_OPT_CAPTURE_FILTER:
|
||||||
extcap->capture_filter = g_strdup(optargument);
|
extcap->capture_filter = g_strdup(optargument);
|
||||||
break;
|
break;
|
||||||
case EXTCAP_OPT_FIFO:
|
case EXTCAP_OPT_FIFO:
|
||||||
extcap->fifo = g_strdup(optargument);
|
extcap->fifo = g_strdup(optargument);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_iface_print(gpointer data, gpointer userdata _U_)
|
static void extcap_iface_print(gpointer data, gpointer userdata _U_)
|
||||||
{
|
{
|
||||||
extcap_interface * iface = (extcap_interface *)data;
|
extcap_interface * iface = (extcap_interface *)data;
|
||||||
|
|
||||||
printf("interface {value=%s}", iface->interface);
|
printf("interface {value=%s}", iface->interface);
|
||||||
if (iface->description != NULL)
|
if (iface->description != NULL)
|
||||||
printf ("{display=%s}\n", iface->description);
|
printf ("{display=%s}\n", iface->description);
|
||||||
else
|
else
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint extcap_iface_compare(gconstpointer a, gconstpointer b)
|
static gint extcap_iface_compare(gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
extcap_interface * iface_a = (extcap_interface *)a;
|
extcap_interface * iface_a = (extcap_interface *)a;
|
||||||
|
|
||||||
return (g_strcmp0(iface_a->interface, (char *) b));
|
return (g_strcmp0(iface_a->interface, (char *) b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_print_version(extcap_parameters * extcap)
|
static void extcap_print_version(extcap_parameters * extcap)
|
||||||
{
|
{
|
||||||
printf("extcap {version=%s}", extcap->version != NULL ? extcap->version : "unknown");
|
printf("extcap {version=%s}", extcap->version != NULL ? extcap->version : "unknown");
|
||||||
if (extcap->helppage != NULL)
|
if (extcap->helppage != NULL)
|
||||||
printf("{help=%s}", extcap->helppage);
|
printf("{help=%s}", extcap->helppage);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint extcap_iface_listall(extcap_parameters * extcap, uint8_t list_ifs)
|
static gint extcap_iface_listall(extcap_parameters * extcap, uint8_t list_ifs)
|
||||||
{
|
{
|
||||||
if (list_ifs) {
|
if (list_ifs) {
|
||||||
extcap_print_version(extcap);
|
extcap_print_version(extcap);
|
||||||
g_list_foreach(extcap->interfaces, extcap_iface_print, extcap);
|
g_list_foreach(extcap->interfaces, extcap_iface_print, extcap);
|
||||||
|
} else {
|
||||||
|
if (extcap->do_version) {
|
||||||
|
extcap_print_version(extcap);
|
||||||
} else {
|
} else {
|
||||||
if (extcap->do_version) {
|
GList * element = NULL;
|
||||||
extcap_print_version(extcap);
|
extcap_interface * iface = NULL;
|
||||||
} else {
|
if ((element = g_list_find_custom(extcap->interfaces, extcap->interface, extcap_iface_compare)) == NULL)
|
||||||
GList * element = NULL;
|
return 0;
|
||||||
extcap_interface * iface = NULL;
|
|
||||||
if ((element = g_list_find_custom(extcap->interfaces, extcap->interface, extcap_iface_compare)) == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
iface = (extcap_interface *) element->data;
|
iface = (extcap_interface *) element->data;
|
||||||
printf("dlt {number=%d}{name=%s}", iface->dlt, iface->dltname != NULL ? iface->dltname : iface->interface);
|
printf("dlt {number=%d}{name=%s}", iface->dlt, iface->dltname != NULL ? iface->dltname : iface->interface);
|
||||||
if (iface->description != NULL)
|
if (iface->description != NULL)
|
||||||
printf ("{display=%s}\n", iface->dltdescription);
|
printf ("{display=%s}\n", iface->dltdescription);
|
||||||
else
|
else
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t extcap_base_handle_interface(extcap_parameters * extcap)
|
uint8_t extcap_base_handle_interface(extcap_parameters * extcap)
|
||||||
{
|
{
|
||||||
/* A fifo must be provided for capture */
|
/* A fifo must be provided for capture */
|
||||||
if (extcap->capture && (extcap->fifo == NULL || strlen(extcap->fifo) <= 0)) {
|
if (extcap->capture && (extcap->fifo == NULL || strlen(extcap->fifo) <= 0)) {
|
||||||
extcap->capture = 0;
|
extcap->capture = 0;
|
||||||
errmsg_print("Extcap Error: No FIFO pipe provided");
|
errmsg_print("Extcap Error: No FIFO pipe provided");
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extcap->do_list_interfaces) {
|
|
||||||
return extcap_iface_listall(extcap, 1);
|
|
||||||
} else if (extcap->do_version || extcap->do_list_dlts) {
|
|
||||||
return extcap_iface_listall(extcap, 0);
|
|
||||||
} else {
|
|
||||||
/* An interface must exist */
|
|
||||||
if (g_list_find_custom(extcap->interfaces, extcap->interface, extcap_iface_compare) == NULL) {
|
|
||||||
errmsg_print("Extcap Error: No interface [%s] provided", extcap->interface);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extcap->do_list_interfaces) {
|
||||||
|
return extcap_iface_listall(extcap, 1);
|
||||||
|
} else if (extcap->do_version || extcap->do_list_dlts) {
|
||||||
|
return extcap_iface_listall(extcap, 0);
|
||||||
|
} else {
|
||||||
|
/* An interface must exist */
|
||||||
|
if (g_list_find_custom(extcap->interfaces, extcap->interface, extcap_iface_compare) == NULL) {
|
||||||
|
errmsg_print("Extcap Error: No interface [%s] provided", extcap->interface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_iface_free(gpointer data)
|
static void extcap_iface_free(gpointer data)
|
||||||
{
|
{
|
||||||
extcap_interface * iface = (extcap_interface *)data;
|
extcap_interface * iface = (extcap_interface *)data;
|
||||||
g_free(iface->interface);
|
g_free(iface->interface);
|
||||||
g_free(iface->description);
|
g_free(iface->description);
|
||||||
g_free(iface->dltname);
|
g_free(iface->dltname);
|
||||||
g_free(iface->dltdescription);
|
g_free(iface->dltdescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extcap_base_cleanup(extcap_parameters ** extcap)
|
void extcap_base_cleanup(extcap_parameters ** extcap)
|
||||||
{
|
{
|
||||||
g_list_free_full((*extcap)->interfaces, extcap_iface_free);
|
g_list_free_full((*extcap)->interfaces, extcap_iface_free);
|
||||||
g_free((*extcap)->fifo);
|
g_free((*extcap)->fifo);
|
||||||
g_free((*extcap)->interface);
|
g_free((*extcap)->interface);
|
||||||
g_free((*extcap)->version);
|
g_free((*extcap)->version);
|
||||||
g_free((*extcap)->helppage);
|
g_free((*extcap)->helppage);
|
||||||
g_free(*extcap);
|
g_free(*extcap);
|
||||||
*extcap = NULL;
|
*extcap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -267,10 +267,10 @@ void extcap_base_cleanup(extcap_parameters ** extcap)
|
||||||
*
|
*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-basic-offset: 4
|
* c-basic-offset: 4
|
||||||
* tab-width: 4
|
* tab-width: 8
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* End:
|
* End:
|
||||||
*
|
*
|
||||||
* vi: set shiftwidth=4 tabstop=4 noexpandtab:
|
* vi: set shiftwidth=4 tabstop=8 noexpandtab:
|
||||||
* :indentSize=4:tabSize=4:noTabs=false:
|
* :indentSize=4:tabSize=8:noTabs=false:
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,66 +30,66 @@
|
||||||
#include <wsutil/inet_addr.h>
|
#include <wsutil/inet_addr.h>
|
||||||
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
#ifdef HAVE_ARPA_INET_H
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_IFADDRS_H
|
#ifdef HAVE_IFADDRS_H
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GSList *local_interfaces_to_list(void)
|
GSList *local_interfaces_to_list(void)
|
||||||
{
|
{
|
||||||
GSList *interfaces = NULL;
|
GSList *interfaces = NULL;
|
||||||
#ifdef HAVE_GETIFADDRS
|
#ifdef HAVE_GETIFADDRS
|
||||||
struct ifaddrs *ifap;
|
struct ifaddrs *ifap;
|
||||||
struct ifaddrs *ifa;
|
struct ifaddrs *ifa;
|
||||||
int family;
|
int family;
|
||||||
char ip[INET6_ADDRSTRLEN];
|
char ip[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
if (getifaddrs(&ifap)) {
|
if (getifaddrs(&ifap)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
interfaces = g_slist_alloc();
|
interfaces = g_slist_alloc();
|
||||||
|
|
||||||
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
||||||
if (ifa->ifa_addr == NULL)
|
if (ifa->ifa_addr == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
family = ifa->ifa_addr->sa_family;
|
family = ifa->ifa_addr->sa_family;
|
||||||
|
|
||||||
memset(ip, 0x0, INET6_ADDRSTRLEN);
|
memset(ip, 0x0, INET6_ADDRSTRLEN);
|
||||||
|
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
{
|
{
|
||||||
struct sockaddr_in *addr4 = (struct sockaddr_in *)ifa->ifa_addr;
|
struct sockaddr_in *addr4 = (struct sockaddr_in *)ifa->ifa_addr;
|
||||||
ws_inet_ntop4(&addr4->sin_addr, ip, sizeof(ip));
|
ws_inet_ntop4(&addr4->sin_addr, ip, sizeof(ip));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case AF_INET6:
|
|
||||||
{
|
|
||||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)ifa->ifa_addr;
|
|
||||||
ws_inet_ntop6(&addr6->sin6_addr, ip, sizeof(ip));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip loopback addresses */
|
case AF_INET6:
|
||||||
if (!g_strcmp0(ip, "127.0.0.1") || !g_strcmp0(ip, "::1"))
|
{
|
||||||
continue;
|
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)ifa->ifa_addr;
|
||||||
|
ws_inet_ntop6(&addr6->sin6_addr, ip, sizeof(ip));
|
||||||
if (*ip) {
|
break;
|
||||||
interfaces = g_slist_prepend(interfaces, g_strdup(ip));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* skip loopback addresses */
|
||||||
|
if (!g_strcmp0(ip, "127.0.0.1") || !g_strcmp0(ip, "::1"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (*ip) {
|
||||||
|
interfaces = g_slist_prepend(interfaces, g_strdup(ip));
|
||||||
|
}
|
||||||
|
}
|
||||||
end:
|
end:
|
||||||
#endif /* HAVE_GETIFADDRS */
|
#endif /* HAVE_GETIFADDRS */
|
||||||
return interfaces;
|
return interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,10 +97,10 @@ end:
|
||||||
*
|
*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-basic-offset: 4
|
* c-basic-offset: 4
|
||||||
* tab-width: 4
|
* tab-width: 8
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* End:
|
* End:
|
||||||
*
|
*
|
||||||
* vi: set shiftwidth=4 tabstop=4 noexpandtab:
|
* vi: set shiftwidth=4 tabstop=8 noexpandtab:
|
||||||
* :indentSize=4:tabSize=4:noTabs=false:
|
* :indentSize=4:tabSize=8:noTabs=false:
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue