added QSE_NWIFCFG_LINKUP, QSE_NWIFCFG_LINKDOWN, QSE_NWAD_NX.
changed qse_nwifcfg() to set an address type to QSE_NWAD_NX when the address can't be retrieved
This commit is contained in:
parent
c2668bbe26
commit
f04bea44e1
2
qse/configure
vendored
2
qse/configure
vendored
@ -17349,7 +17349,7 @@ fi
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for ac_header in sys/stropts.h sys/macstat.h
|
for ac_header in sys/stropts.h sys/macstat.h linux/ethtool.h linux/sockios.h
|
||||||
do :
|
do :
|
||||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||||
|
@ -106,7 +106,7 @@ AC_CHECK_HEADERS([sys/sysctl.h sys/socket.h sys/sockio.h ifaddrs.h])
|
|||||||
AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
|
AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>])
|
#include <sys/socket.h>])
|
||||||
AC_CHECK_HEADERS([sys/stropts.h sys/macstat.h])
|
AC_CHECK_HEADERS([sys/stropts.h sys/macstat.h linux/ethtool.h linux/sockios.h])
|
||||||
AC_CHECK_HEADERS([uci.h])
|
AC_CHECK_HEADERS([uci.h])
|
||||||
|
|
||||||
dnl check data types
|
dnl check data types
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
enum qse_nwad_type_t
|
enum qse_nwad_type_t
|
||||||
{
|
{
|
||||||
|
QSE_NWAD_NX, /* non-existent */
|
||||||
QSE_NWAD_IN4,
|
QSE_NWAD_IN4,
|
||||||
QSE_NWAD_IN6
|
QSE_NWAD_IN6
|
||||||
};
|
};
|
||||||
|
@ -29,10 +29,12 @@ typedef struct qse_nwifcfg_t qse_nwifcfg_t;
|
|||||||
|
|
||||||
enum qse_nwifcfg_flag_t
|
enum qse_nwifcfg_flag_t
|
||||||
{
|
{
|
||||||
QSE_NWIFCFG_UP = (1 << 0),
|
QSE_NWIFCFG_UP = (1 << 0),
|
||||||
QSE_NWIFCFG_RUNNING = (1 << 1),
|
QSE_NWIFCFG_RUNNING = (1 << 1),
|
||||||
QSE_NWIFCFG_BCAST = (1 << 2),
|
QSE_NWIFCFG_BCAST = (1 << 2),
|
||||||
QSE_NWIFCFG_PTOP = (1 << 3)
|
QSE_NWIFCFG_PTOP = (1 << 3),
|
||||||
|
QSE_NWIFCFG_LINKUP = (1 << 4),
|
||||||
|
QSE_NWIFCFG_LINKDOWN = (1 << 5)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qse_nwifcfg_type_t
|
enum qse_nwifcfg_type_t
|
||||||
|
@ -203,6 +203,12 @@
|
|||||||
/* Define to 1 if you have the `ltdl' library (-lltdl). */
|
/* Define to 1 if you have the `ltdl' library (-lltdl). */
|
||||||
#undef HAVE_LIBLTDL
|
#undef HAVE_LIBLTDL
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <linux/ethtool.h> header file. */
|
||||||
|
#undef HAVE_LINUX_ETHTOOL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <linux/sockios.h> header file. */
|
||||||
|
#undef HAVE_LINUX_SOCKIOS_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `log' function. */
|
/* Define to 1 if you have the `log' function. */
|
||||||
#undef HAVE_LOG
|
#undef HAVE_LOG
|
||||||
|
|
||||||
|
@ -65,6 +65,12 @@
|
|||||||
# if defined(HAVE_SYS_MACSTAT_H)
|
# if defined(HAVE_SYS_MACSTAT_H)
|
||||||
# include <sys/macstat.h>
|
# include <sys/macstat.h>
|
||||||
# endif
|
# endif
|
||||||
|
# if defined(HAVE_LINUX_ETHTOOL_H)
|
||||||
|
# include <linux/ethtool.h>
|
||||||
|
# endif
|
||||||
|
# if defined(HAVE_LINUX_SOCKIOS_H)
|
||||||
|
# include <linux/sockios.h>
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -269,7 +275,7 @@ void qse_freenwifcfg (qse_nwifcfg_t* cfg)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
static int get_nwifcfg (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
|
||||||
{
|
{
|
||||||
#if defined(SIOCGLIFADDR) && defined(SIOCGLIFINDEX) && \
|
#if defined(SIOCGLIFADDR) && defined(SIOCGLIFINDEX) && \
|
||||||
defined(HAVE_STRUCT_LIFCONF) && defined(HAVE_STRUCT_LIFREQ)
|
defined(HAVE_STRUCT_LIFCONF) && defined(HAVE_STRUCT_LIFREQ)
|
||||||
@ -279,12 +285,7 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
|
|
||||||
QSE_MEMSET (&lifrbuf, 0, QSE_SIZEOF(lifrbuf));
|
QSE_MEMSET (&lifrbuf, 0, QSE_SIZEOF(lifrbuf));
|
||||||
|
|
||||||
#if defined(QSE_CHAR_IS_MCHAR)
|
qse_mbsxcpy (lifrbuf.lifr_name, QSE_SIZEOF(lifrbuf.lifr_name), ifr->ifr_name);
|
||||||
qse_mbsxcpy (lifrbuf.lifr_name, QSE_SIZEOF(lifrbuf.lifr_name), cfg->name);
|
|
||||||
#else
|
|
||||||
ml = QSE_COUNTOF(lifrbuf.lifr_name);
|
|
||||||
if (qse_wcstombs (cfg->name, &wl, lifrbuf.lifr_name, &ml) <= -1) return -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ioctl (s, SIOCGLIFINDEX, &lifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGLIFINDEX, &lifrbuf) <= -1) return -1;
|
||||||
cfg->index = lifrbuf.lifr_index;
|
cfg->index = lifrbuf.lifr_index;
|
||||||
@ -299,10 +300,10 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
if (ioctl (s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1;
|
||||||
cfg->mtu = lifrbuf.lifr_mtu;
|
cfg->mtu = lifrbuf.lifr_mtu;
|
||||||
|
|
||||||
qse_clearnwad (&cfg->addr, cfg->type);
|
qse_clearnwad (&cfg->addr, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->mask, cfg->type);
|
qse_clearnwad (&cfg->mask, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->bcast, cfg->type);
|
qse_clearnwad (&cfg->bcast, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->ptop, cfg->type);
|
qse_clearnwad (&cfg->ptop, QSE_NWAD_NX);
|
||||||
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
||||||
|
|
||||||
if (ioctl (s, SIOCGLIFADDR, &lifrbuf) >= 0)
|
if (ioctl (s, SIOCGLIFADDR, &lifrbuf) >= 0)
|
||||||
@ -324,13 +325,10 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
|
|
||||||
#if defined(SIOCGENADDR)
|
#if defined(SIOCGENADDR)
|
||||||
{
|
{
|
||||||
struct ifreq ifrbuf;
|
if (ioctl (s, SIOCGENADDR, ifr) >= 0 &&
|
||||||
QSE_MEMSET (&ifrbuf, 0, QSE_SIZEOF(ifrbuf));
|
QSE_SIZEOF(ifr->ifr_enaddr) >= QSE_SIZEOF(cfg->ethw))
|
||||||
qse_mbsxcpy (ifrbuf.ifr_name, QSE_COUNTOF(ifrbuf.ifr_name), lifrbuf.lifr_name);
|
|
||||||
if (ioctl (s, SIOCGENADDR, &ifrbuf) >= 0 &&
|
|
||||||
QSE_SIZEOF(ifrbuf.ifr_enaddr) >= QSE_SIZEOF(cfg->ethw))
|
|
||||||
{
|
{
|
||||||
QSE_MEMCPY (cfg->ethw, ifrbuf.ifr_enaddr, QSE_SIZEOF(cfg->ethw));
|
QSE_MEMCPY (cfg->ethw, ifr->ifr_enaddr, QSE_SIZEOF(cfg->ethw));
|
||||||
}
|
}
|
||||||
/* TODO: try DLPI if SIOCGENADDR fails... */
|
/* TODO: try DLPI if SIOCGENADDR fails... */
|
||||||
}
|
}
|
||||||
@ -340,61 +338,48 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
|
|
||||||
#elif defined(SIOCGLIFADDR) && defined(HAVE_STRUCT_IF_LADDRREQ) && !defined(SIOCGLIFINDEX)
|
#elif defined(SIOCGLIFADDR) && defined(HAVE_STRUCT_IF_LADDRREQ) && !defined(SIOCGLIFINDEX)
|
||||||
/* freebsd */
|
/* freebsd */
|
||||||
struct ifreq ifrbuf;
|
|
||||||
struct if_laddrreq iflrbuf;
|
|
||||||
qse_size_t ml, wl;
|
qse_size_t ml, wl;
|
||||||
|
|
||||||
QSE_MEMSET (&ifrbuf, 0, QSE_SIZEOF(ifrbuf));
|
|
||||||
QSE_MEMSET (&iflrbuf, 0, QSE_SIZEOF(iflrbuf));
|
|
||||||
|
|
||||||
#if defined(QSE_CHAR_IS_MCHAR)
|
|
||||||
qse_mbsxcpy (iflrbuf.iflr_name, QSE_SIZEOF(iflrbuf.iflr_name), cfg->name);
|
|
||||||
|
|
||||||
qse_mbsxcpy (ifrbuf.ifr_name, QSE_SIZEOF(ifrbuf.ifr_name), cfg->name);
|
|
||||||
#else
|
|
||||||
ml = QSE_COUNTOF(iflrbuf.iflr_name);
|
|
||||||
if (qse_wcstombs (cfg->name, &wl, iflrbuf.iflr_name, &ml) <= -1) return -1;
|
|
||||||
|
|
||||||
ml = QSE_COUNTOF(ifrbuf.ifr_name);
|
|
||||||
if (qse_wcstombs (cfg->name, &wl, ifrbuf.ifr_name, &ml) <= -1) return -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SIOCGIFINDEX)
|
#if defined(SIOCGIFINDEX)
|
||||||
if (ioctl (s, SIOCGIFINDEX, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFINDEX, ifr) <= -1) return -1;
|
||||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||||
cfg->index = ifrbuf.ifr_ifindex;
|
cfg->index = ifr->ifr_ifindex;
|
||||||
#else
|
#else
|
||||||
cfg->index = ifrbuf.ifr_index;
|
cfg->index = ifr->ifr_index;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
cfg->index = 0;
|
cfg->index = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFFLAGS, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFFLAGS, ifr) <= -1) return -1;
|
||||||
cfg->flags = 0;
|
cfg->flags = 0;
|
||||||
if (ifrbuf.ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
|
if (ifr->ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
|
||||||
if (ifrbuf.ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
|
if (ifr->ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
|
||||||
if (ifrbuf.ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
|
if (ifr->ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
|
||||||
if (ifrbuf.ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
|
if (ifr->ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFMTU, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFMTU, ifr) <= -1) return -1;
|
||||||
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
|
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
|
||||||
cfg->mtu = ifrbuf.ifr_mtu;
|
cfg->mtu = ifr->ifr_mtu;
|
||||||
#else
|
#else
|
||||||
/* well, this is a bit dirty. but since all these are unions,
|
/* well, this is a bit dirty. but since all these are unions,
|
||||||
* the name must not really matter. some OSes just omitts defining
|
* the name must not really matter. some OSes just omitts defining
|
||||||
* the MTU field */
|
* the MTU field */
|
||||||
cfg->mtu = ifrbuf.ifr_metric;
|
cfg->mtu = ifr->ifr_metric;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qse_clearnwad (&cfg->addr, cfg->type);
|
qse_clearnwad (&cfg->addr, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->mask, cfg->type);
|
qse_clearnwad (&cfg->mask, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->bcast, cfg->type);
|
qse_clearnwad (&cfg->bcast, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->ptop, cfg->type);
|
qse_clearnwad (&cfg->ptop, QSE_NWAD_NX);
|
||||||
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
||||||
|
|
||||||
if (cfg->type == QSE_NWIFCFG_IN6)
|
if (cfg->type == QSE_NWIFCFG_IN6)
|
||||||
{
|
{
|
||||||
|
struct if_laddrreq iflrbuf;
|
||||||
|
QSE_MEMSET (&iflrbuf, 0, QSE_SIZEOF(iflrbuf));
|
||||||
|
qse_mbsxcpy (iflrbuf.iflr_name, QSE_SIZEOF(iflrbuf.iflr_name), ifr->ifr_name);
|
||||||
|
|
||||||
if (ioctl (s, SIOCGLIFADDR, &iflrbuf) >= 0)
|
if (ioctl (s, SIOCGLIFADDR, &iflrbuf) >= 0)
|
||||||
{
|
{
|
||||||
qse_skadtonwad (&iflrbuf.addr, &cfg->addr);
|
qse_skadtonwad (&iflrbuf.addr, &cfg->addr);
|
||||||
@ -408,22 +393,22 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ioctl (s, SIOCGIFADDR, &ifrbuf) >= 0)
|
if (ioctl (s, SIOCGIFADDR, ifr) >= 0)
|
||||||
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
|
qse_skadtonwad (&ifr->ifr_addr, &cfg->addr);
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) >= 0)
|
if (ioctl (s, SIOCGIFNETMASK, ifr) >= 0)
|
||||||
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
|
qse_skadtonwad (&ifr->ifr_addr, &cfg->mask);
|
||||||
|
|
||||||
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
|
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
|
||||||
ioctl (s, SIOCGIFBRDADDR, &ifrbuf) >= 0)
|
ioctl (s, SIOCGIFBRDADDR, ifr) >= 0)
|
||||||
{
|
{
|
||||||
qse_skadtonwad (&ifrbuf.ifr_broadaddr, &cfg->bcast);
|
qse_skadtonwad (&ifr->ifr_broadaddr, &cfg->bcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cfg->flags & QSE_NWIFCFG_PTOP) &&
|
if ((cfg->flags & QSE_NWIFCFG_PTOP) &&
|
||||||
ioctl (s, SIOCGIFDSTADDR, &ifrbuf) >= 0)
|
ioctl (s, SIOCGIFDSTADDR, ifr) >= 0)
|
||||||
{
|
{
|
||||||
qse_skadtonwad (&ifrbuf.ifr_dstaddr, &cfg->ptop);
|
qse_skadtonwad (&ifr->ifr_dstaddr, &cfg->ptop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,74 +451,63 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#elif defined(SIOCGIFADDR)
|
#elif defined(SIOCGIFADDR)
|
||||||
struct ifreq ifrbuf;
|
|
||||||
qse_size_t ml, wl;
|
|
||||||
|
|
||||||
QSE_MEMSET (&ifrbuf, 0, QSE_SIZEOF(ifrbuf));
|
|
||||||
|
|
||||||
#if defined(QSE_CHAR_IS_MCHAR)
|
|
||||||
qse_mbsxcpy (ifrbuf.ifr_name, QSE_SIZEOF(ifrbuf.ifr_name), cfg->name);
|
|
||||||
#else
|
|
||||||
ml = QSE_COUNTOF(ifrbuf.ifr_name);
|
|
||||||
if (qse_wcstombs (cfg->name, &wl, ifrbuf.ifr_name, &ml) <= -1) return -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SIOCGIFINDEX)
|
#if defined(SIOCGIFINDEX)
|
||||||
if (ioctl (s, SIOCGIFINDEX, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFINDEX, ifr) <= -1) return -1;
|
||||||
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
|
||||||
cfg->index = ifrbuf.ifr_ifindex;
|
cfg->index = ifr->ifr_ifindex;
|
||||||
#else
|
#else
|
||||||
cfg->index = ifrbuf.ifr_index;
|
cfg->index = ifr->ifr_index;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
cfg->index = 0;
|
cfg->index = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFFLAGS, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFFLAGS, ifr) <= -1) return -1;
|
||||||
cfg->flags = 0;
|
cfg->flags = 0;
|
||||||
if (ifrbuf.ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
|
if (ifr->ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
|
||||||
if (ifrbuf.ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
|
if (ifr->ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
|
||||||
if (ifrbuf.ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
|
if (ifr->ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
|
||||||
if (ifrbuf.ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
|
if (ifr->ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFMTU, &ifrbuf) <= -1) return -1;
|
if (ioctl (s, SIOCGIFMTU, ifr) <= -1) return -1;
|
||||||
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
|
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
|
||||||
cfg->mtu = ifrbuf.ifr_mtu;
|
cfg->mtu = ifr->ifr_mtu;
|
||||||
#else
|
#else
|
||||||
/* well, this is a bit dirty. but since all these are unions,
|
/* well, this is a bit dirty. but since all these are unions,
|
||||||
* the name must not really matter. SCO just omits defining
|
* the name must not really matter. SCO just omits defining
|
||||||
* the MTU field, and uses ifr_metric instead */
|
* the MTU field, and uses ifr_metric instead */
|
||||||
cfg->mtu = ifrbuf.ifr_metric;
|
cfg->mtu = ifr->ifr_metric;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qse_clearnwad (&cfg->addr, cfg->type);
|
qse_clearnwad (&cfg->addr, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->mask, cfg->type);
|
qse_clearnwad (&cfg->mask, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->bcast, cfg->type);
|
qse_clearnwad (&cfg->bcast, QSE_NWAD_NX);
|
||||||
qse_clearnwad (&cfg->ptop, cfg->type);
|
qse_clearnwad (&cfg->ptop, QSE_NWAD_NX);
|
||||||
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFADDR, &ifrbuf) >= 0)
|
if (ioctl (s, SIOCGIFADDR, ifr) >= 0)
|
||||||
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
|
qse_skadtonwad (&ifr->ifr_addr, &cfg->addr);
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) >= 0)
|
if (ioctl (s, SIOCGIFNETMASK, ifr) >= 0)
|
||||||
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
|
qse_skadtonwad (&ifr->ifr_addr, &cfg->mask);
|
||||||
|
|
||||||
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
|
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
|
||||||
ioctl (s, SIOCGIFBRDADDR, &ifrbuf) >= 0)
|
ioctl (s, SIOCGIFBRDADDR, ifr) >= 0)
|
||||||
{
|
{
|
||||||
qse_skadtonwad (&ifrbuf.ifr_broadaddr, &cfg->bcast);
|
qse_skadtonwad (&ifr->ifr_broadaddr, &cfg->bcast);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cfg->flags & QSE_NWIFCFG_PTOP) &&
|
if ((cfg->flags & QSE_NWIFCFG_PTOP) &&
|
||||||
ioctl (s, SIOCGIFDSTADDR, &ifrbuf) >= 0)
|
ioctl (s, SIOCGIFDSTADDR, ifr) >= 0)
|
||||||
{
|
{
|
||||||
qse_skadtonwad (&ifrbuf.ifr_dstaddr, &cfg->ptop);
|
qse_skadtonwad (&ifr->ifr_dstaddr, &cfg->ptop);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SIOCGIFHWADDR)
|
#if defined(SIOCGIFHWADDR)
|
||||||
if (ioctl (s, SIOCGIFHWADDR, &ifrbuf) >= 0)
|
if (ioctl (s, SIOCGIFHWADDR, ifr) >= 0)
|
||||||
{
|
{
|
||||||
QSE_MEMCPY (cfg->ethw, ifrbuf.ifr_hwaddr.sa_data, QSE_SIZEOF(cfg->ethw));
|
QSE_MEMCPY (cfg->ethw, ifr->ifr_hwaddr.sa_data, QSE_SIZEOF(cfg->ethw));
|
||||||
}
|
}
|
||||||
#elif defined(MACIOC_GETADDR)
|
#elif defined(MACIOC_GETADDR)
|
||||||
{
|
{
|
||||||
@ -541,8 +515,8 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
* use the streams interface to get the hardware address.
|
* use the streams interface to get the hardware address.
|
||||||
*/
|
*/
|
||||||
int strfd;
|
int strfd;
|
||||||
qse_mchar_t devname[QSE_COUNTOF(ifrbuf.ifr_name) + 5 + 1] = QSE_MT("/dev/");
|
qse_mchar_t devname[QSE_COUNTOF(ifr->ifr_name) + 5 + 1] = QSE_MT("/dev/");
|
||||||
qse_mbscpy (&devname[5], ifrbuf.ifr_name);
|
qse_mbscpy (&devname[5], ifr->ifr_name);
|
||||||
if ((strfd = QSE_OPEN (devname, O_RDONLY, 0)) >= 0)
|
if ((strfd = QSE_OPEN (devname, O_RDONLY, 0)) >= 0)
|
||||||
{
|
{
|
||||||
qse_uint8_t buf[QSE_SIZEOF(cfg->ethw)];
|
qse_uint8_t buf[QSE_SIZEOF(cfg->ethw)];
|
||||||
@ -568,6 +542,53 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void get_moreinfo (int s, qse_nwifcfg_t* cfg, struct ifreq* ifr)
|
||||||
|
{
|
||||||
|
#if defined(ETHTOOL_GLINK)
|
||||||
|
{
|
||||||
|
/* get link status */
|
||||||
|
struct ethtool_value ev;
|
||||||
|
|
||||||
|
QSE_MEMSET (&ev, 0, QSE_SIZEOF(ev));
|
||||||
|
ev.cmd= ETHTOOL_GLINK;
|
||||||
|
ifr->ifr_data = &ev;
|
||||||
|
if (ioctl (s, SIOCETHTOOL,ifr) >= 0)
|
||||||
|
cfg->flags |= ev.data? QSE_NWIFCFG_LINKUP: QSE_NWIFCFG_LINKDOWN;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
#if defined(ETHTOOL_GSTATS)
|
||||||
|
{
|
||||||
|
/* get link statistics */
|
||||||
|
struct ethtool_drvinfo drvinfo;
|
||||||
|
|
||||||
|
|
||||||
|
drvinfo.cmd = ETHTOOL_GDRVINFO;
|
||||||
|
ifr->ifr_data = &drvinfo;
|
||||||
|
if (ioctl (s, SIOCETHTOOL, ifr) >= 0)
|
||||||
|
{
|
||||||
|
struct ethtool_stats *stats;
|
||||||
|
qse_uint8_t buf[1000]; /* TODO: make this dynamic according to drvinfo.n_stats */
|
||||||
|
|
||||||
|
stats = buf;
|
||||||
|
stats->cmd = ETHTOOL_GSTATS;
|
||||||
|
stats->n_stats = drvinfo.n_stats * QSE_SIZEOF(stats->data[0]);
|
||||||
|
ifr->ifr_data = (caddr_t) stats;
|
||||||
|
if (ioctl (s, SIOCETHTOOL, ifr) >= 0)
|
||||||
|
{
|
||||||
|
for (i = 0; i < drvinfo.n_stats; i++)
|
||||||
|
{
|
||||||
|
qse_printf (QSE_T(">>> %llu \n"), stats->data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int qse_getnwifcfg (qse_nwifcfg_t* cfg)
|
int qse_getnwifcfg (qse_nwifcfg_t* cfg)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -580,7 +601,9 @@ int qse_getnwifcfg (qse_nwifcfg_t* cfg)
|
|||||||
/* TODO */
|
/* TODO */
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
int x, s = -1;
|
int x = -1, s = -1;
|
||||||
|
struct ifreq ifr;
|
||||||
|
qse_size_t ml, wl;
|
||||||
|
|
||||||
if (cfg->type == QSE_NWIFCFG_IN4)
|
if (cfg->type == QSE_NWIFCFG_IN4)
|
||||||
{
|
{
|
||||||
@ -601,8 +624,19 @@ int qse_getnwifcfg (qse_nwifcfg_t* cfg)
|
|||||||
/* TODO: support lookup by ifindex */
|
/* TODO: support lookup by ifindex */
|
||||||
}
|
}
|
||||||
|
|
||||||
x = get_nwifcfg (s, cfg);
|
QSE_MEMSET (&ifr, 0, sizeof(ifr));
|
||||||
|
#if defined(QSE_CHAR_IS_MCHAR)
|
||||||
|
qse_mbsxcpy (ifr.ifr_name, QSE_SIZEOF(ifr.ifr_name), cfg->name);
|
||||||
|
#else
|
||||||
|
ml = QSE_COUNTOF(ifr.ifr_name);
|
||||||
|
if (qse_wcstombs (cfg->name, &wl, ifr.ifr_name, &ml) <= -1) goto oops;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
x = get_nwifcfg (s, cfg, &ifr);
|
||||||
|
|
||||||
|
if (x >= 0) get_moreinfo (s, cfg, &ifr);
|
||||||
|
|
||||||
|
oops:
|
||||||
QSE_CLOSE (s);
|
QSE_CLOSE (s);
|
||||||
return x;
|
return x;
|
||||||
#endif
|
#endif
|
||||||
|
@ -519,7 +519,7 @@ static int fnc_getnwifcfg (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
qse_char_t addr[128];
|
qse_char_t addr[128];
|
||||||
qse_char_t mask[128];
|
qse_char_t mask[128];
|
||||||
qse_char_t ethw[32];
|
qse_char_t ethw[32];
|
||||||
qse_awk_val_map_data_t md[6];
|
qse_awk_val_map_data_t md[7];
|
||||||
qse_awk_val_t* retv;
|
qse_awk_val_t* retv;
|
||||||
|
|
||||||
QSE_MEMSET (md, 0, QSE_SIZEOF(md));
|
QSE_MEMSET (md, 0, QSE_SIZEOF(md));
|
||||||
@ -555,6 +555,14 @@ static int fnc_getnwifcfg (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
cfg.ethw[0], cfg.ethw[1], cfg.ethw[2], cfg.ethw[3], cfg.ethw[4], cfg.ethw[5]);
|
cfg.ethw[0], cfg.ethw[1], cfg.ethw[2], cfg.ethw[3], cfg.ethw[4], cfg.ethw[5]);
|
||||||
md[4].vptr = ethw;
|
md[4].vptr = ethw;
|
||||||
|
|
||||||
|
if (cfg.flags & (QSE_NWIFCFG_LINKUP | QSE_NWIFCFG_LINKDOWN))
|
||||||
|
{
|
||||||
|
md[5].key.ptr = QSE_T("link");
|
||||||
|
md[5].key.len = 4;
|
||||||
|
md[5].type = QSE_AWK_VAL_MAP_DATA_STR;
|
||||||
|
md[5].vptr = (cfg.flags & QSE_NWIFCFG_LINKUP)? QSE_T("up"): QSE_T("down");
|
||||||
|
}
|
||||||
|
|
||||||
retv = qse_awk_rtx_makemapvalwithdata (rtx, md);
|
retv = qse_awk_rtx_makemapvalwithdata (rtx, md);
|
||||||
if (retv == QSE_NULL) return -1;
|
if (retv == QSE_NULL) return -1;
|
||||||
|
|
||||||
|
@ -14,6 +14,9 @@ static void print_nwifcfg (qse_nwifcfg_t* ptr)
|
|||||||
{
|
{
|
||||||
qse_char_t tmp[128];
|
qse_char_t tmp[128];
|
||||||
|
|
||||||
|
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 "));
|
||||||
qse_printf (QSE_T("[%s] ifindex=[%u] "), ptr->name, ptr->index);
|
qse_printf (QSE_T("[%s] ifindex=[%u] "), ptr->name, ptr->index);
|
||||||
|
|
||||||
qse_nwadtostr (&ptr->addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
qse_nwadtostr (&ptr->addr, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
||||||
@ -26,6 +29,11 @@ static void print_nwifcfg (qse_nwifcfg_t* ptr)
|
|||||||
qse_nwadtostr (&ptr->bcast, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
qse_nwadtostr (&ptr->bcast, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
||||||
qse_printf (QSE_T("bcast=[%s] "), tmp);
|
qse_printf (QSE_T("bcast=[%s] "), tmp);
|
||||||
}
|
}
|
||||||
|
if (ptr->flags & QSE_NWIFCFG_PTOP)
|
||||||
|
{
|
||||||
|
qse_nwadtostr (&ptr->ptop, tmp, QSE_COUNTOF(tmp), QSE_NWADTOSTR_ALL);
|
||||||
|
qse_printf (QSE_T("ptop=[%s] "), tmp);
|
||||||
|
}
|
||||||
|
|
||||||
qse_printf (QSE_T("mtu=[%d] "), (int)ptr->mtu);
|
qse_printf (QSE_T("mtu=[%d] "), (int)ptr->mtu);
|
||||||
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]);
|
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]);
|
||||||
|
Loading…
Reference in New Issue
Block a user