2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/nwif.h>
|
2012-11-16 16:46:49 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
|
|
|
#include <qse/cmn/main.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2012-11-16 16:46:49 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
|
|
|
#include <qse/cmn/str.h>
|
2014-08-30 05:40:57 +00:00
|
|
|
#include <qse/cmn/fmt.h>
|
2012-11-16 16:46:49 +00:00
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void print_nwifcfg (qse_nwifcfg_t* ptr)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[128];
|
|
|
|
|
2012-11-22 13:36:46 +00:00
|
|
|
if (ptr->flags & QSE_NWIFCFG_UP) qse_printf (QSE_T("UP "));
|
|
|
|
if (ptr->flags & QSE_NWIFCFG_LINKUP) qse_printf (QSE_T("LINKUP "));
|
|
|
|
if (ptr->flags & QSE_NWIFCFG_LINKDOWN) qse_printf (QSE_T("LINKDOWN "));
|
2012-11-16 16:46:49 +00:00
|
|
|
qse_printf (QSE_T("[%s] ifindex=[%u] "), ptr->name, ptr->index);
|
|
|
|
|
|
|
|
qse_nwadtostr (&ptr->addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
|
|
|
qse_printf (QSE_T("addr=[%s] "), tmp);
|
|
|
|
qse_nwadtostr (&ptr->mask, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
|
|
|
qse_printf (QSE_T("mask=[%s] "), tmp);
|
|
|
|
|
|
|
|
if (ptr->flags & QSE_NWIFCFG_BCAST)
|
|
|
|
{
|
|
|
|
qse_nwadtostr (&ptr->bcast, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
|
|
|
qse_printf (QSE_T("bcast=[%s] "), tmp);
|
|
|
|
}
|
2012-11-22 13:36:46 +00:00
|
|
|
if (ptr->flags & QSE_NWIFCFG_PTOP)
|
|
|
|
{
|
|
|
|
qse_nwadtostr (&ptr->ptop, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
|
|
|
qse_printf (QSE_T("ptop=[%s] "), tmp);
|
|
|
|
}
|
2012-11-16 16:46:49 +00:00
|
|
|
|
|
|
|
qse_printf (QSE_T("mtu=[%d] "), (int)ptr->mtu);
|
2012-11-18 15:19:51 +00:00
|
|
|
qse_printf (QSE_T("hwaddr=[%02X:%02X:%02X:%02X:%02X:%02X] "), ptr->ethw[0], ptr->ethw[1], ptr->ethw[2], ptr->ethw[3], ptr->ethw[4], ptr->ethw[5]);
|
2012-11-16 16:46:49 +00:00
|
|
|
qse_printf (QSE_T("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_main (int argc, qse_char_t* argv[])
|
|
|
|
{
|
|
|
|
qse_nwifcfg_t cfg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; ;i++)
|
|
|
|
{
|
|
|
|
if (qse_nwifindextostr (i, cfg.name, QSE_COUNTOF(cfg.name)) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("ifindex %d failed for IN4\n"), i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.type = QSE_NWIFCFG_IN4;
|
|
|
|
if (qse_getnwifcfg (&cfg) <= -1)
|
|
|
|
qse_printf (QSE_T("Cannot get v4 configuration - %s\n"), cfg.name);
|
|
|
|
else print_nwifcfg (&cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; ;i++)
|
|
|
|
{
|
|
|
|
if (qse_nwifindextostr (i, cfg.name, QSE_COUNTOF(cfg.name)) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("ifindex %d failed for IN6\n"), i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.type = QSE_NWIFCFG_IN6;
|
|
|
|
if (qse_getnwifcfg (&cfg) <= -1)
|
|
|
|
qse_printf (QSE_T("Cannot get v6 configuration - %s\n"), cfg.name);
|
|
|
|
else print_nwifcfg (&cfg);
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("================================================\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
|
|
|
{
|
2014-08-30 05:40:57 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-11-16 16:46:49 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
char locale[100];
|
|
|
|
UINT codepage = GetConsoleOutputCP();
|
|
|
|
if (codepage == CP_UTF8)
|
|
|
|
{
|
|
|
|
/*SetConsoleOutputCP (CP_UTF8);*/
|
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-30 05:40:57 +00:00
|
|
|
qse_fmtuintmaxtombs (locale, QSE_COUNTOF(locale),
|
|
|
|
codepage, 10, -1, QSE_MT('\0'), QSE_MT("."));
|
|
|
|
setlocale (LC_ALL, locale);
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-11-16 16:46:49 +00:00
|
|
|
}
|
|
|
|
#else
|
2014-08-30 05:40:57 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-11-16 16:46:49 +00:00
|
|
|
#endif
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2018-09-13 03:16:23 +00:00
|
|
|
ret = qse_run_main (argc, argv, test_main);
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2014-08-30 05:40:57 +00:00
|
|
|
|
|
|
|
return ret;
|
2012-11-16 16:46:49 +00:00
|
|
|
}
|
|
|
|
|