added qse_prefixtoip4ad()/qse_prefixtoip6ad().

added more code to qse_getnwifcfg(). 
renamed qse_ipad4_t and qse_ipad6_to to qse_ip4ad_t and qse_ip6ad_t respectively
This commit is contained in:
hyung-hwan 2012-11-18 15:19:51 +00:00
parent 105c862230
commit a55545b8ae
14 changed files with 692 additions and 283 deletions

68
qse/configure vendored
View File

@ -17320,7 +17320,7 @@ fi
done
for ac_header in sys/socket.h sys/sockio.h ifaddrs.h
for ac_header in sys/sysctl.h sys/socket.h sys/sockio.h ifaddrs.h
do :
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"
@ -17333,26 +17333,29 @@ fi
done
for ac_header in net/if.h
for ac_header in net/if.h net/if_dl.h
do :
ac_fn_c_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" "#include <sys/socket.h>
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "
#include <sys/types.h>
#include <sys/socket.h>
"
if test "x$ac_cv_header_net_if_h" = xyes; then :
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_NET_IF_H 1
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
done
for ac_header in net/if_dl.h
for ac_header in sys/stropts.h sys/macstat.h
do :
ac_fn_c_check_header_compile "$LINENO" "net/if_dl.h" "ac_cv_header_net_if_dl_h" "#include <sys/socket.h>
"
if test "x$ac_cv_header_net_if_dl_h" = xyes; then :
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"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_NET_IF_DL_H 1
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
@ -18642,7 +18645,6 @@ _ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct ifreq" "ifr_mtu" "ac_cv_member_struct_ifreq_ifr_mtu" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
@ -18659,6 +18661,50 @@ _ACEOF
fi
ac_fn_c_check_type "$LINENO" "struct lifconf" "ac_cv_type_struct_lifconf" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_type_struct_lifconf" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_LIFCONF 1
_ACEOF
fi
ac_fn_c_check_type "$LINENO" "struct lifreq" "ac_cv_type_struct_lifreq" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_type_struct_lifreq" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_LIFREQ 1
_ACEOF
fi
ac_fn_c_check_type "$LINENO" "struct if_laddrreq" "ac_cv_type_struct_if_laddrreq" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_type_struct_if_laddrreq" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_IF_LADDRREQ 1
_ACEOF
fi
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.

View File

@ -102,9 +102,11 @@ AC_HEADER_STDC
AC_CHECK_HEADERS([stddef.h wchar.h wctype.h errno.h signal.h fcntl.h dirent.h])
AC_CHECK_HEADERS([time.h sys/time.h utime.h spawn.h execinfo.h ucontext.h])
AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/syscall.h sys/sendfile.h sys/epoll.h sys/ioctl.h])
AC_CHECK_HEADERS([sys/socket.h sys/sockio.h ifaddrs.h])
AC_CHECK_HEADERS([net/if.h], [], [], [#include <sys/socket.h>])
AC_CHECK_HEADERS([net/if_dl.h], [], [], [#include <sys/socket.h>])
AC_CHECK_HEADERS([sys/sysctl.h sys/socket.h sys/sockio.h ifaddrs.h])
AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
#include <sys/types.h>
#include <sys/socket.h>])
AC_CHECK_HEADERS([sys/stropts.h sys/macstat.h])
AC_CHECK_HEADERS([uci.h])
dnl check data types
@ -253,13 +255,14 @@ AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
AC_CHECK_MEMBERS([struct ifreq.ifr_ifindex], [], [],
AC_CHECK_MEMBERS([struct ifreq.ifr_ifindex, struct ifreq.ifr_mtu], [], [],
[#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif])
AC_CHECK_MEMBERS([struct ifreq.ifr_mtu], [], [],
AC_CHECK_TYPES([struct lifconf, struct lifreq, struct if_laddrreq], [], [],
[#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H

View File

@ -25,15 +25,15 @@
#include <qse/macros.h>
typedef struct qse_ipad_t qse_ipad_t;
typedef struct qse_ipad4_t qse_ipad4_t;
typedef struct qse_ipad6_t qse_ipad6_t;
typedef struct qse_ip4ad_t qse_ip4ad_t;
typedef struct qse_ip6ad_t qse_ip6ad_t;
#include <qse/pack1.h>
struct qse_ipad4_t
struct qse_ip4ad_t
{
qse_uint32_t value;
};
struct qse_ipad6_t
struct qse_ip6ad_t
{
qse_uint8_t value[16];
};
@ -43,93 +43,115 @@ struct qse_ipad6_t
extern "C" {
#endif
int qse_mbstoipad4 (
int qse_mbstoip4ad (
const qse_mchar_t* mbs,
qse_ipad4_t* ipad
qse_ip4ad_t* ipad
);
int qse_mbsntoipad4 (
int qse_mbsntoip4ad (
const qse_mchar_t* mbs,
qse_size_t len,
qse_ipad4_t* ipad
qse_ip4ad_t* ipad
);
int qse_wcstoipad4 (
int qse_wcstoip4ad (
const qse_wchar_t* wcs,
qse_ipad4_t* ipad
qse_ip4ad_t* ipad
);
int qse_wcsntoipad4 (
int qse_wcsntoip4ad (
const qse_wchar_t* wcs,
qse_size_t len,
qse_ipad4_t* ipad
qse_ip4ad_t* ipad
);
qse_size_t qse_ipad4tombs (
const qse_ipad4_t* ipad,
qse_size_t qse_ip4adtombs (
const qse_ip4ad_t* ipad,
qse_mchar_t* mbs,
qse_size_t len
);
qse_size_t qse_ipad4towcs (
const qse_ipad4_t* ipad,
qse_size_t qse_ip4adtowcs (
const qse_ip4ad_t* ipad,
qse_wchar_t* wcs,
qse_size_t len
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strtoipad4(ptr,ipad) qse_mbstoipad4(ptr,ipad)
# define qse_strntoipad4(ptr,len,ipad) qse_mbsntoipad4(ptr,len,ipad)
# define qse_ipad4tostr(ipad,ptr,len) qse_ipad4tombs(ipad,ptr,len)
# define qse_strtoip4ad(ptr,ipad) qse_mbstoip4ad(ptr,ipad)
# define qse_strntoip4ad(ptr,len,ipad) qse_mbsntoip4ad(ptr,len,ipad)
# define qse_ip4adtostr(ipad,ptr,len) qse_ip4adtombs(ipad,ptr,len)
#else
# define qse_strtoipad4(ptr,ipad) qse_wcstoipad4(ptr,ipad)
# define qse_strntoipad4(ptr,len,ipad) qse_wcsntoipad4(ptr,len,ipad)
# define qse_ipad4tostr(ipad,ptr,len) qse_ipad4towcs(ipad,ptr,len)
# define qse_strtoip4ad(ptr,ipad) qse_wcstoip4ad(ptr,ipad)
# define qse_strntoip4ad(ptr,len,ipad) qse_wcsntoip4ad(ptr,len,ipad)
# define qse_ip4adtostr(ipad,ptr,len) qse_ip4adtowcs(ipad,ptr,len)
#endif
int qse_mbstoipad6 (
int qse_mbstoip6ad (
const qse_mchar_t* mbs,
qse_ipad6_t* ipad
qse_ip6ad_t* ipad
);
int qse_mbsntoipad6 (
int qse_mbsntoip6ad (
const qse_mchar_t* mbs,
qse_size_t len,
qse_ipad6_t* ipad
qse_ip6ad_t* ipad
);
int qse_wcstoipad6 (
int qse_wcstoip6ad (
const qse_wchar_t* wcs,
qse_ipad6_t* ipad
qse_ip6ad_t* ipad
);
int qse_wcsntoipad6 (
int qse_wcsntoip6ad (
const qse_wchar_t* wcs,
qse_size_t len,
qse_ipad6_t* ipad
qse_ip6ad_t* ipad
);
qse_size_t qse_ipad6tombs (
const qse_ipad6_t* ipad,
qse_size_t qse_ip6adtombs (
const qse_ip6ad_t* ipad,
qse_mchar_t* mbs,
qse_size_t len
);
qse_size_t qse_ipad6towcs (
const qse_ipad6_t* ipad,
qse_size_t qse_ip6adtowcs (
const qse_ip6ad_t* ipad,
qse_wchar_t* wcs,
qse_size_t len
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strtoipad6(ptr,ipad) qse_mbstoipad6(ptr,ipad)
# define qse_strntoipad6(ptr,len,ipad) qse_mbsntoipad6(ptr,len,ipad)
# define qse_ipad6tostr(ipad,ptr,len) qse_ipad6tombs(ipad,ptr,len)
# define qse_strtoip6ad(ptr,ipad) qse_mbstoip6ad(ptr,ipad)
# define qse_strntoip6ad(ptr,len,ipad) qse_mbsntoip6ad(ptr,len,ipad)
# define qse_ip6adtostr(ipad,ptr,len) qse_ip6adtombs(ipad,ptr,len)
#else
# define qse_strtoipad6(ptr,ipad) qse_wcstoipad6(ptr,ipad)
# define qse_strntoipad6(ptr,len,ipad) qse_wcsntoipad6(ptr,len,ipad)
# define qse_ipad6tostr(ipad,ptr,len) qse_ipad6towcs(ipad,ptr,len)
#endif
# define qse_strtoip6ad(ptr,ipad) qse_wcstoip6ad(ptr,ipad)
# define qse_strntoip6ad(ptr,len,ipad) qse_wcsntoip6ad(ptr,len,ipad)
# define qse_ip6adtostr(ipad,ptr,len) qse_ip6adtowcs(ipad,ptr,len)
#endif
/*
* The qse_prefixtoip4ad() function converts the prefix length
* to an IPv4 address mask. The prefix length @a prefix must be
* between 0 and 32 inclusive.
* @return 0 on success, -1 on failure
*/
int qse_prefixtoip4ad (
int prefix,
qse_ip4ad_t* ipad
);
/*
* The qse_prefixtoip4ad() function converts the prefix length
* to an IPv6 address mask. The prefix length @a prefix must be
* between 0 and 128 inclusive.
* @return 0 on success, -1 on failure
*/
int qse_prefixtoip6ad (
int prefix,
qse_ip6ad_t* ipad
);
#ifdef __cplusplus
}

View File

@ -42,13 +42,13 @@ struct qse_nwad_t
struct
{
qse_uint16_t port;
qse_ipad4_t addr;
qse_ip4ad_t addr;
} in4;
struct
{
qse_uint16_t port;
qse_ipad6_t addr;
qse_ip6ad_t addr;
qse_uint32_t scope;
} in6;
} u;
@ -73,6 +73,7 @@ typedef struct qse_skad_t qse_skad_t;
struct qse_skad_t
{
/* TODO: is this large enough?? */
#if (QSE_SIZEOF_STRUCT_SOCKADDR_IN > 0) && \
(QSE_SIZEOF_STRUCT_SOCKADDR_IN >= QSE_SIZEOF_STRUCT_SOCKADDR_IN6)
qse_uint8_t data[QSE_SIZEOF_STRUCT_SOCKADDR_IN];

View File

@ -44,40 +44,50 @@ enum qse_nwifcfg_type_t
typedef enum qse_nwifcfg_type_t qse_nwifcfg_type_t;
struct qse_nwifcfg_t
{
qse_nwifcfg_type_t type;
qse_char_t name[64];
qse_nwifcfg_type_t type; /* in */
qse_char_t name[64]; /* in/out */
unsigned int index; /* in/out */
/* ---------------- */
int flags; /* out */
int mtu; /* out */
qse_nwad_t addr; /* out */
qse_nwad_t mask; /* out */
qse_nwad_t ptop; /* out */
qse_nwad_t bcast; /* out */
/* ---------------- */
/* TODO: add hwaddr?? */
int flags;
unsigned int index;
qse_nwad_t addr;
qse_nwad_t mask;
qse_nwad_t ptop;
qse_nwad_t bcast;
int mtu;
/* i support ethernet only currently */
qse_uint8_t ethw[6]; /* out */
};
#ifdef __cplusplus
extern "C" {
#endif
unsigned int qse_nwifmbstoindex (
const qse_mchar_t* ptr
);
unsigned int qse_nwifwcstoindex (
const qse_wchar_t* ptr
);
unsigned int qse_nwifmbsntoindex (
int qse_nwifmbstoindex (
const qse_mchar_t* ptr,
qse_size_t len
unsigned int* index
);
unsigned int qse_nwifwcsntoindex (
int qse_nwifwcstoindex (
const qse_wchar_t* ptr,
qse_size_t len
unsigned int* index
);
int qse_nwifmbsntoindex (
const qse_mchar_t* ptr,
qse_size_t len,
unsigned int* index
);
int qse_nwifwcsntoindex (
const qse_wchar_t* ptr,
qse_size_t len,
unsigned int* index
);
int qse_nwifindextombs (
@ -93,15 +103,19 @@ int qse_nwifindextowcs (
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_nwifstrtoindex(ptr) qse_nwifmbstoindex(ptr)
# define qse_nwifstrntoindex(ptr,len) qse_nwifmbsntoindex(ptr,len)
# define qse_nwifindextostr(index,buf,len) qse_nwifindextombs(index,buf,len)
# define qse_nwifstrtoindex(ptr,index) qse_nwifmbstoindex(ptr,index)
# define qse_nwifstrntoindex(ptr,len,index) qse_nwifmbsntoindex(ptr,len,index)
# define qse_nwifindextostr(index,buf,len) qse_nwifindextombs(index,buf,len)
#else
# define qse_nwifstrtoindex(ptr) qse_nwifwcstoindex(ptr)
# define qse_nwifstrntoindex(ptr,len) qse_nwifwcsntoindex(ptr,len)
# define qse_nwifindextostr(index,buf,len) qse_nwifindextowcs(index,buf,len)
# define qse_nwifstrtoindex(ptr,index) qse_nwifwcstoindex(ptr,index)
# define qse_nwifstrntoindex(ptr,len,index) qse_nwifwcsntoindex(ptr,len,index)
# define qse_nwifindextostr(index,buf,len) qse_nwifindextowcs(index,buf,len)
#endif
int qse_getnwifcfg (
qse_nwifcfg_t* cfg
);
#ifdef __cplusplus
}
#endif

View File

@ -392,6 +392,15 @@
/* Define to 1 if `ifr_mtu' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_MTU
/* Define to 1 if the system has the type `struct if_laddrreq'. */
#undef HAVE_STRUCT_IF_LADDRREQ
/* Define to 1 if the system has the type `struct lifconf'. */
#undef HAVE_STRUCT_LIFCONF
/* Define to 1 if the system has the type `struct lifreq'. */
#undef HAVE_STRUCT_LIFREQ
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
@ -426,6 +435,9 @@
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/macstat.h> header file. */
#undef HAVE_SYS_MACSTAT_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
@ -445,9 +457,15 @@
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/stropts.h> header file. */
#undef HAVE_SYS_STROPTS_H
/* Define to 1 if you have the <sys/syscall.h> header file. */
#undef HAVE_SYS_SYSCALL_H
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#undef HAVE_SYS_SYSCTL_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H

View File

@ -663,12 +663,12 @@ qse_fs_ent_t* qse_fs_read (qse_fs_t* fs, int flags)
fs->ent.time.create.nsec = st.st_birthtimespec.tv_nsec;
#endif
fs->ent.time.access.sec = st.st_atimspec.tv_sec;
fs->ent.time.access.nsec = st.st_atimspec.tv_nsec;
fs->ent.time.modify.sec = st.st_mtimspec.tv_sec;
fs->ent.time.modify.nsec = st.st_mtimspec.tv_nsec;
fs->ent.time.change.sec = st.st_ctimspec.tv_sec;
fs->ent.time.change.nsec = st.st_ctimspec.tv_nsec;
fs->ent.time.access.sec = st.st_atimespec.tv_sec;
fs->ent.time.access.nsec = st.st_atimespec.tv_nsec;
fs->ent.time.modify.sec = st.st_mtimespec.tv_sec;
fs->ent.time.modify.nsec = st.st_mtimespec.tv_nsec;
fs->ent.time.change.sec = st.st_ctimespec.tv_sec;
fs->ent.time.change.nsec = st.st_ctimespec.tv_nsec;
#else
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
fs->ent.time.create.sec = st.st_birthtime;

View File

@ -41,12 +41,12 @@
#include "mem.h"
#if 0
const qse_ipad4_t qse_ipad4_any =
const qse_ip4ad_t qse_ip4ad_any =
{
0 /* 0.0.0.0 */
};
const qse_ipad4_t qse_ipad4_loopback =
const qse_ip4ad_t qse_ip4ad_loopback =
{
#if defined(QSE_ENDIAN_BIG)
0x7F000001u /* 127.0.0.1 */
@ -57,18 +57,18 @@ const qse_ipad4_t qse_ipad4_loopback =
#endif
};
const qse_ipad6_t qse_ipad6_any =
const qse_ip6ad_t qse_ip6ad_any =
{
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* :: */
};
const qse_ipad6_t qse_ipad6_loopback =
const qse_ip6ad_t qse_ip6ad_loopback =
{
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } /* ::1 */
};
#endif
static int str_to_ipad4 (int mbs, const void* str, qse_size_t len, qse_ipad4_t* ipad)
static int str_to_ip4ad (int mbs, const void* str, qse_size_t len, qse_ip4ad_t* ipad)
{
const void* end;
int dots = 0, digits = 0;
@ -119,24 +119,24 @@ static int str_to_ipad4 (int mbs, const void* str, qse_size_t len, qse_ipad4_t*
return 0;
}
int qse_mbstoipad4 (const qse_mchar_t* str, qse_ipad4_t* ipad)
int qse_mbstoip4ad (const qse_mchar_t* str, qse_ip4ad_t* ipad)
{
return str_to_ipad4 (1, str, qse_mbslen(str), ipad);
return str_to_ip4ad (1, str, qse_mbslen(str), ipad);
}
int qse_wcstoipad4 (const qse_wchar_t* str, qse_ipad4_t* ipad)
int qse_wcstoip4ad (const qse_wchar_t* str, qse_ip4ad_t* ipad)
{
return str_to_ipad4 (0, str, qse_wcslen(str), ipad);
return str_to_ip4ad (0, str, qse_wcslen(str), ipad);
}
int qse_mbsntoipad4 (const qse_mchar_t* str, qse_size_t len, qse_ipad4_t* ipad)
int qse_mbsntoip4ad (const qse_mchar_t* str, qse_size_t len, qse_ip4ad_t* ipad)
{
return str_to_ipad4 (1, str, len, ipad);
return str_to_ip4ad (1, str, len, ipad);
}
int qse_wcsntoipad4 (const qse_wchar_t* str, qse_size_t len, qse_ipad4_t* ipad)
int qse_wcsntoip4ad (const qse_wchar_t* str, qse_size_t len, qse_ip4ad_t* ipad)
{
return str_to_ipad4 (0, str, len, ipad);
return str_to_ip4ad (0, str, len, ipad);
}
#define __BTOA(type_t,b,p,end) \
@ -164,8 +164,8 @@ int qse_wcsntoipad4 (const qse_wchar_t* str, qse_size_t len, qse_ipad4_t* ipad)
*p++ = '.'; \
} while (0)
qse_size_t qse_ipad4tombs (
const qse_ipad4_t* ipad, qse_mchar_t* buf, qse_size_t size)
qse_size_t qse_ip4adtombs (
const qse_ip4ad_t* ipad, qse_mchar_t* buf, qse_size_t size)
{
qse_byte_t b;
qse_mchar_t* p, * end;
@ -196,8 +196,8 @@ qse_size_t qse_ipad4tombs (
return p - buf;
}
qse_size_t qse_ipad4towcs (
const qse_ipad4_t* ipad, qse_wchar_t* buf, qse_size_t size)
qse_size_t qse_ip4adtowcs (
const qse_ip4ad_t* ipad, qse_wchar_t* buf, qse_size_t size)
{
qse_byte_t b;
qse_wchar_t* p, * end;
@ -228,14 +228,14 @@ qse_size_t qse_ipad4towcs (
return p - buf;
}
int qse_mbstoipad6 (const qse_mchar_t* src, qse_ipad6_t* ipad)
int qse_mbstoip6ad (const qse_mchar_t* src, qse_ip6ad_t* ipad)
{
return qse_mbsntoipad6 (src, qse_mbslen(src), ipad);
return qse_mbsntoip6ad (src, qse_mbslen(src), ipad);
}
int qse_mbsntoipad6 (const qse_mchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
int qse_mbsntoip6ad (const qse_mchar_t* src, qse_size_t len, qse_ip6ad_t* ipad)
{
qse_ipad6_t tmp;
qse_ip6ad_t tmp;
qse_uint8_t* tp, * endp, * colonp;
const qse_mchar_t* curtok;
qse_mchar_t ch;
@ -305,10 +305,10 @@ int qse_mbsntoipad6 (const qse_mchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
continue;
}
if (ch == QSE_MT('.') && ((tp + QSE_SIZEOF(qse_ipad4_t)) <= endp) &&
qse_mbsntoipad4(curtok, src_end - curtok, (qse_ipad4_t*)tp) == 0)
if (ch == QSE_MT('.') && ((tp + QSE_SIZEOF(qse_ip4ad_t)) <= endp) &&
qse_mbsntoip4ad(curtok, src_end - curtok, (qse_ip4ad_t*)tp) == 0)
{
tp += QSE_SIZEOF(qse_ipad4_t);
tp += QSE_SIZEOF(qse_ip4ad_t);
saw_xdigit = 0;
break;
}
@ -346,14 +346,14 @@ int qse_mbsntoipad6 (const qse_mchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
}
int qse_wcstoipad6 (const qse_wchar_t* src, qse_ipad6_t* ipad)
int qse_wcstoip6ad (const qse_wchar_t* src, qse_ip6ad_t* ipad)
{
return qse_wcsntoipad6 (src, qse_wcslen(src), ipad);
return qse_wcsntoip6ad (src, qse_wcslen(src), ipad);
}
int qse_wcsntoipad6 (const qse_wchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
int qse_wcsntoip6ad (const qse_wchar_t* src, qse_size_t len, qse_ip6ad_t* ipad)
{
qse_ipad6_t tmp;
qse_ip6ad_t tmp;
qse_uint8_t* tp, * endp, * colonp;
const qse_wchar_t* curtok;
qse_wchar_t ch;
@ -423,10 +423,10 @@ int qse_wcsntoipad6 (const qse_wchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
continue;
}
if (ch == QSE_WT('.') && ((tp + QSE_SIZEOF(qse_ipad4_t)) <= endp) &&
qse_wcsntoipad4(curtok, src_end - curtok, (qse_ipad4_t*)tp) == 0)
if (ch == QSE_WT('.') && ((tp + QSE_SIZEOF(qse_ip4ad_t)) <= endp) &&
qse_wcsntoip4ad(curtok, src_end - curtok, (qse_ip4ad_t*)tp) == 0)
{
tp += QSE_SIZEOF(qse_ipad4_t);
tp += QSE_SIZEOF(qse_ip4ad_t);
saw_xdigit = 0;
break;
}
@ -463,8 +463,8 @@ int qse_wcsntoipad6 (const qse_wchar_t* src, qse_size_t len, qse_ipad6_t* ipad)
return 0;
}
qse_size_t qse_ipad6tombs (
const qse_ipad6_t* ipad, qse_mchar_t* buf, qse_size_t size)
qse_size_t qse_ip6adtombs (
const qse_ip6ad_t* ipad, qse_mchar_t* buf, qse_size_t size)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
@ -544,9 +544,9 @@ qse_size_t qse_ipad6tombs (
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
{
qse_ipad4_t ipad4;
QSE_MEMCPY (&ipad4.value, ipad->value+12, QSE_SIZEOF(ipad4.value));
tp += qse_ipad4tombs (&ipad4, tp, QSE_COUNTOF(tmp) - (tp - tmp));
qse_ip4ad_t ip4ad;
QSE_MEMCPY (&ip4ad.value, ipad->value+12, QSE_SIZEOF(ip4ad.value));
tp += qse_ip4adtombs (&ip4ad, tp, QSE_COUNTOF(tmp) - (tp - tmp));
break;
}
@ -565,8 +565,8 @@ qse_size_t qse_ipad6tombs (
#undef IP6ADDR_NWORDS
}
qse_size_t qse_ipad6towcs (
const qse_ipad6_t* ipad, qse_wchar_t* buf, qse_size_t size)
qse_size_t qse_ip6adtowcs (
const qse_ip6ad_t* ipad, qse_wchar_t* buf, qse_size_t size)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
@ -646,9 +646,9 @@ qse_size_t qse_ipad6towcs (
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
{
qse_ipad4_t ipad4;
QSE_MEMCPY (&ipad4.value, ipad->value+12, QSE_SIZEOF(ipad4.value));
tp += qse_ipad4towcs (&ipad4, tp, QSE_COUNTOF(tmp) - (tp - tmp));
qse_ip4ad_t ip4ad;
QSE_MEMCPY (&ip4ad.value, ipad->value+12, QSE_SIZEOF(ip4ad.value));
tp += qse_ip4adtowcs (&ip4ad, tp, QSE_COUNTOF(tmp) - (tp - tmp));
break;
}
@ -667,3 +667,62 @@ qse_size_t qse_ipad6towcs (
#undef IP6ADDR_NWORDS
}
int qse_prefixtoip4ad (int prefix, qse_ip4ad_t* ipad)
{
static qse_uint32_t tab[] =
{
0x00000000,
0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF
};
if (prefix < 0 || prefix > QSE_SIZEOF(*ipad) * 8) return -1;
ipad->value = qse_hton32(tab[prefix]);
return 0;
/*
int p, k;
qse_uint32_t mask = 0;
for (k = 24; prefix > 0; k -= 8)
{
p = (prefix >= 8)? 0: (8 - prefix);
mask |= ((0xFF << p) & 0xFF) << k;
prefix -= 8;
}
ipad->value = qse_hton32(mask);
return 0;
*/
}
int qse_prefixtoip6ad (int prefix, qse_ip6ad_t* ipad)
{
int i;
if (prefix < 0 || prefix > QSE_SIZEOF(*ipad) * 8) return -1;
QSE_MEMSET (ipad, 0, QSE_SIZEOF(*ipad));
for (i = 0; ; i++)
{
if (prefix > 8)
{
ipad->value[i] = 0xFF;
prefix -= 8;
}
else
{
ipad->value[i] = 0xFF << (8 - prefix);
break;
}
}
return 0;
}

View File

@ -104,16 +104,17 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad)
{
/* interface name as a scope id? */
const qse_mchar_t* stmp = p;
unsigned int index;
do p++; while (p < end && *p != QSE_MT(']'));
tmpad.u.in6.scope = qse_nwifmbsntoindex (stmp, p - stmp);
if (tmpad.u.in6.scope <= 0) return -1;
if (qse_nwifmbsntoindex (stmp, p - stmp, &index) <= -1) return -1;
tmpad.u.in6.scope = index;
}
if (p >= end || *p != QSE_MT(']')) return -1;
}
p++; /* skip ] */
if (qse_mbsntoipad6 (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1) return -1;
if (qse_mbsntoip6ad (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1) return -1;
tmpad.type = QSE_NWAD_IN6;
}
else
@ -123,7 +124,7 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad)
while (p < end && *p != QSE_MT(':')) p++;
tmp.len = p - tmp.ptr;
if (qse_mbsntoipad4 (tmp.ptr, tmp.len, &tmpad.u.in4.addr) <= -1)
if (qse_mbsntoip4ad (tmp.ptr, tmp.len, &tmpad.u.in4.addr) <= -1)
{
if (p >= end || *p != QSE_MT(':')) return -1;
@ -133,7 +134,7 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad)
while (p < end && *p != QSE_MT('%')) p++;
tmp.len = p - tmp.ptr;
if (qse_mbsntoipad6 (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1)
if (qse_mbsntoip6ad (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1)
return -1;
if (p < end && *p == QSE_MT('%'))
@ -166,9 +167,10 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad)
{
/* interface name as a scope id? */
const qse_mchar_t* stmp = p;
unsigned int index;
do p++; while (p < end);
tmpad.u.in6.scope = qse_nwifmbsntoindex (stmp, p - stmp);
if (tmpad.u.in6.scope <= 0) return -1;
if (qse_nwifmbsntoindex (stmp, p - stmp, &index) <= -1) return -1;
tmpad.u.in6.scope = index;
}
}
@ -268,16 +270,17 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad)
{
/* interface name as a scope id? */
const qse_wchar_t* stmp = p;
unsigned int index;
do p++; while (p < end && *p != QSE_WT(']'));
tmpad.u.in6.scope = qse_nwifwcsntoindex (stmp, p - stmp);
if (tmpad.u.in6.scope <= 0) return -1;
if (qse_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
tmpad.u.in6.scope = index;
}
if (p >= end || *p != QSE_WT(']')) return -1;
}
p++; /* skip ] */
if (qse_wcsntoipad6 (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1) return -1;
if (qse_wcsntoip6ad (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1) return -1;
tmpad.type = QSE_NWAD_IN6;
}
else
@ -287,7 +290,7 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad)
while (p < end && *p != QSE_WT(':')) p++;
tmp.len = p - tmp.ptr;
if (qse_wcsntoipad4 (tmp.ptr, tmp.len, &tmpad.u.in4.addr) <= -1)
if (qse_wcsntoip4ad (tmp.ptr, tmp.len, &tmpad.u.in4.addr) <= -1)
{
if (p >= end || *p != QSE_WT(':')) return -1;
@ -297,7 +300,7 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad)
while (p < end && *p != QSE_WT('%')) p++;
tmp.len = p - tmp.ptr;
if (qse_wcsntoipad6 (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1)
if (qse_wcsntoip6ad (tmp.ptr, tmp.len, &tmpad.u.in6.addr) <= -1)
return -1;
if (p < end && *p == QSE_WT('%'))
@ -330,9 +333,10 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad)
{
/* interface name as a scope id? */
const qse_wchar_t* stmp = p;
unsigned int index;
do p++; while (p < end);
tmpad.u.in6.scope = qse_nwifwcsntoindex (stmp, p - stmp);
if (tmpad.u.in6.scope <= 0) return -1;
if (qse_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
tmpad.u.in6.scope = index;
}
}
@ -387,7 +391,7 @@ qse_size_t qse_nwadtombs (
if (flags & QSE_NWADTOMBS_ADDR)
{
if (xlen + 1 >= len) goto done;
xlen += qse_ipad4tombs (&nwad->u.in4.addr, buf, len);
xlen += qse_ip4adtombs (&nwad->u.in4.addr, buf, len);
}
if (flags & QSE_NWADTOMBS_PORT)
@ -428,7 +432,7 @@ qse_size_t qse_nwadtombs (
{
if (xlen + 1 >= len) goto done;
xlen += qse_ipad6tombs (&nwad->u.in6.addr, &buf[xlen], len - xlen);
xlen += qse_ip6adtombs (&nwad->u.in6.addr, &buf[xlen], len - xlen);
if (nwad->u.in6.scope != 0)
{
@ -495,7 +499,7 @@ qse_size_t qse_nwadtowcs (
if (flags & QSE_NWADTOWCS_ADDR)
{
if (xlen + 1 >= len) goto done;
xlen += qse_ipad4towcs (&nwad->u.in4.addr, buf, len);
xlen += qse_ip4adtowcs (&nwad->u.in4.addr, buf, len);
}
if (flags & QSE_NWADTOWCS_PORT)
@ -535,7 +539,7 @@ qse_size_t qse_nwadtowcs (
if (flags & QSE_NWADTOWCS_ADDR)
{
if (xlen + 1 >= len) goto done;
xlen += qse_ipad6towcs (&nwad->u.in6.addr, &buf[xlen], len - xlen);
xlen += qse_ip6adtowcs (&nwad->u.in6.addr, &buf[xlen], len - xlen);
if (nwad->u.in6.scope != 0)
{

View File

@ -47,15 +47,26 @@
# if defined(HAVE_NET_IF_H)
# include <net/if.h>
# endif
# if defined(HAVE_NET_IF_DL_H)
# include <net/if_dl.h>
# endif
# if defined(HAVE_SYS_SOCKIO_H)
# include <sys/sockio.h>
# endif
# if defined(HAVE_IFADDRS_H)
# include <ifaddrs.h>
# endif
# if defined(HAVE_SYS_SYSCTL_H)
# include <sys/sysctl.h>
# endif
# if defined(HAVE_SYS_STROPTS_H)
# include <sys/stropts.h> /* stream options */
# endif
# if defined(HAVE_SYS_MACSTAT_H)
# include <sys/macstat.h>
# endif
#endif
/*
#if defined(HAVE_NET_IF_DL_H)
@ -79,7 +90,8 @@
*/
#if defined(SIOCGLIFCONF)
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFNUM) && \
defined(HAVE_STRUCT_LIFCONF) && defined(HAVE_STRUCT_LIFREQ)
static int get_nwifs (qse_mmgr_t* mmgr, int s, int f, qse_xptl_t* nwifs)
{
struct lifnum ifn;
@ -259,47 +271,194 @@ void qse_freenwifcfg (qse_nwifcfg_t* cfg)
static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
{
#if defined(SIOCGLIFADDR)
struct lifreq ifrbuf;
#if defined(SIOCGLIFADDR) && defined(SIOCGLIFINDEX) && \
defined(HAVE_STRUCT_LIFCONF) && defined(HAVE_STRUCT_LIFREQ)
/* opensolaris */
struct lifreq lifrbuf;
qse_size_t ml, wl;
QSE_MEMSET (&lifrbuf, 0, QSE_SIZEOF(lifrbuf));
#if defined(QSE_CHAR_IS_MCHAR)
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;
cfg->index = lifrbuf.lifr_index;
if (ioctl (s, SIOCGLIFFLAGS, &lifrbuf) <= -1) return -1;
cfg->flags = 0;
if (lifrbuf.lifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
if (lifrbuf.lifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
if (lifrbuf.lifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
if (lifrbuf.lifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
if (ioctl (s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1;
cfg->mtu = lifrbuf.lifr_mtu;
if (ioctl (s, SIOCGLIFADDR, &lifrbuf) <= -1) return -1;
qse_skadtonwad (&lifrbuf.lifr_addr, &cfg->addr);
if (ioctl (s, SIOCGLIFNETMASK, &lifrbuf) <= -1) return -1;
qse_skadtonwad (&lifrbuf.lifr_addr, &cfg->mask);
if (cfg->flags & QSE_NWIFCFG_BCAST)
{
if (ioctl (s, SIOCGLIFBRDADDR, &lifrbuf) <= -1) return -1;
qse_skadtonwad (&lifrbuf.lifr_broadaddr, &cfg->bcast);
}
else QSE_MEMSET (&cfg->bcast, 0, QSE_SIZEOF(cfg->bcast));
if (cfg->flags & QSE_NWIFCFG_PTOP)
{
if (ioctl (s, SIOCGLIFDSTADDR, &lifrbuf) <= -1) return -1;
qse_skadtonwad (&lifrbuf.lifr_dstaddr, &cfg->ptop);
}
else QSE_MEMSET (&cfg->ptop, 0, QSE_SIZEOF(cfg->ptop));
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
#if defined(SIOCGENADDR)
{
struct ifreq ifrbuf;
QSE_MEMSET (&ifrbuf, 0, QSE_SIZEOF(ifrbuf));
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));
}
/* TODO: try DLPI if SIOCGENADDR fails... */
}
#endif
return 0;
#elif defined(SIOCGLIFADDR) && defined(HAVE_STRUCT_IF_LADDRREQ) && !defined(SIOCGLIFINDEX)
/* freebsd */
struct ifreq ifrbuf;
struct if_laddrreq iflrbuf;
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 (ifrbuf.lifr_name, QSE_SIZEOF(ifrbuf.lifr_name), cfg->name);
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(ifrbuf.lifr_name);
if (qse_wcstombs (cfg->name, &wl, ifrbuf.lifr_name, &ml) <= -1) return -1;
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 (ioctl (s, SIOCGLIFINDEX, &ifrbuf) <= -1) return -1;
cfg->index = ifrbuf.lifr_index;
#if defined(SIOCGIFINDEX)
if (ioctl (s, SIOCGIFINDEX, &ifrbuf) <= -1) return -1;
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
cfg->index = ifrbuf.ifr_ifindex;
#else
cfg->index = ifrbuf.ifr_index;
#endif
#else
cfg->index = 0;
#endif
if (ioctl (s, SIOCGIFFLAGS, &ifrbuf) <= -1) return -1;
cfg->flags = 0;
if (ifrbuf.ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
if (ifrbuf.ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
if (ifrbuf.ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
if (ifrbuf.ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
if (ioctl (s, SIOCGIFMTU, &ifrbuf) <= -1) return -1;
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
cfg->mtu = ifrbuf.ifr_mtu;
#else
/* well, this is a bit dirty. but since all these are unions,
* the name must not really matter. some OSes just omitts defining
* the MTU field */
cfg->mtu = ifrbuf.ifr_metric;
#endif
if (ioctl (s, SIOCGLIFADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_addr, &cfg->addr);
if (ioctl (s, SIOCGLIFNETMASK, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_addr, &cfg->mask);
if (ioctl (s, SIOCGLIFMTU, &ifrbuf) <= -1) return -1;
cfg->mtu = ifrbuf.lifr_mtu;
if (ioctl (s, SIOCGLIFFLAGS, &ifrbuf) <= -1) return -1;
if (ifrbuf.lifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
if (ifrbuf.lifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
if (ifrbuf.lifr_flags & IFF_BROADCAST)
if (cfg->type == QSE_NWIFCFG_IN6)
{
if (ioctl (s, SIOCGLIFBRDADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_broadaddr, &cfg->bcast);
cfg->flags |= QSE_NWIFCFG_BCAST;
if (ioctl (s, SIOCGLIFADDR, &iflrbuf) <= -1) return -1;
qse_skadtonwad (&iflrbuf.addr, &cfg->addr);
QSE_MEMSET (&cfg->mask, 0, QSE_SIZEOF(cfg->mask));
cfg->mask.type = QSE_NWAD_IN6;
qse_prefixtoip6ad (iflrbuf.prefixlen, &cfg->mask.u.in6.addr);
QSE_MEMSET (&cfg->bcast, 0, QSE_SIZEOF(cfg->bcast));
if (cfg->flags & QSE_NWIFCFG_PTOP)
qse_skadtonwad (&iflrbuf.dstaddr, &cfg->ptop);
else QSE_MEMSET (&cfg->ptop, 0, QSE_SIZEOF(cfg->ptop));
}
if (ifrbuf.lifr_flags & IFF_POINTOPOINT)
else
{
if (ioctl (s, SIOCGLIFDSTADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_dstaddr, &cfg->ptop);
cfg->flags |= QSE_NWIFCFG_PTOP;
if (ioctl (s, SIOCGIFADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
if (cfg->flags & QSE_NWIFCFG_BCAST)
{
if (ioctl (s, SIOCGIFBRDADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_broadaddr, &cfg->bcast);
}
else QSE_MEMSET (&cfg->bcast, 0, QSE_SIZEOF(cfg->bcast));
if (cfg->flags & QSE_NWIFCFG_PTOP)
{
if (ioctl (s, SIOCGIFDSTADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_dstaddr, &cfg->ptop);
}
else QSE_MEMSET (&cfg->ptop, 0, QSE_SIZEOF(cfg->ptop));
}
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
#if defined(CTL_NET) && defined(AF_ROUTE) && defined(AF_LINK)
{
int mib[6];
size_t len;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
mib[5] = cfg->index;
if (sysctl (mib, QSE_COUNTOF(mib), QSE_NULL, &len, QSE_NULL, 0) >= 0)
{
qse_mmgr_t* mmgr = QSE_MMGR_GETDFL();
void* buf;
buf = QSE_MMGR_ALLOC (mmgr, len);
if (buf)
{
if (sysctl (mib, QSE_COUNTOF(mib), buf, &len, QSE_NULL, 0) >= 0)
{
struct sockaddr_dl* sadl;
sadl = ((struct if_msghdr*)buf + 1);
/* i don't really care if it's really ethernet
* so long as the data is long enough */
if (sadl->sdl_alen >= QSE_COUNTOF(cfg->ethw))
QSE_MEMCPY (cfg->ethw, LLADDR(sadl), QSE_SIZEOF(cfg->ethw));
}
QSE_MMGR_FREE (mmgr, buf);
}
}
}
#endif
return 0;
#elif defined(SIOCGIFADDR)
@ -325,6 +484,23 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
#else
cfg->index = 0;
#endif
if (ioctl (s, SIOCGIFFLAGS, &ifrbuf) <= -1) return -1;
cfg->flags = 0;
if (ifrbuf.ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
if (ifrbuf.ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
if (ifrbuf.ifr_flags & IFF_BROADCAST) cfg->flags |= QSE_NWIFCFG_BCAST;
if (ifrbuf.ifr_flags & IFF_POINTOPOINT) cfg->flags |= QSE_NWIFCFG_PTOP;
if (ioctl (s, SIOCGIFMTU, &ifrbuf) <= -1) return -1;
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
cfg->mtu = ifrbuf.ifr_mtu;
#else
/* well, this is a bit dirty. but since all these are unions,
* the name must not really matter. SCO just omits defining
* the MTU field, and uses ifr_metric instead */
cfg->mtu = ifrbuf.ifr_metric;
#endif
if (ioctl (s, SIOCGIFADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
@ -332,34 +508,53 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
if (ioctl (s, SIOCGIFMTU, &ifrbuf) <= -1) return -1;
#if defined(HAVE_STRUCT_IFREQ_IFR_MTU)
cfg->mtu = ifrbuf.ifr_mtu;
#else
/* well, this is a bit dirty. but since all these are unions,
* the name must not really matter. some OSes just omitts defining
* the MTU field */
cfg->mtu = ifrbuf.ifr_metric;
#endif
if (ioctl (s, SIOCGIFFLAGS, &ifrbuf) <= -1) return -1;
if (ifrbuf.ifr_flags & IFF_UP) cfg->flags |= QSE_NWIFCFG_UP;
if (ifrbuf.ifr_flags & IFF_RUNNING) cfg->flags |= QSE_NWIFCFG_RUNNING;
if (ifrbuf.ifr_flags & IFF_BROADCAST)
if (cfg->flags & QSE_NWIFCFG_BCAST)
{
if (ioctl (s, SIOCGIFBRDADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_broadaddr, &cfg->bcast);
cfg->flags |= QSE_NWIFCFG_BCAST;
}
else QSE_MEMSET (&cfg->bcast, 0, QSE_SIZEOF(cfg->bcast));
if (ifrbuf.ifr_flags & IFF_POINTOPOINT)
if (cfg->flags & QSE_NWIFCFG_PTOP)
{
if (ioctl (s, SIOCGIFDSTADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_dstaddr, &cfg->ptop);
cfg->flags |= QSE_NWIFCFG_PTOP;
}
else QSE_MEMSET (&cfg->ptop, 0, QSE_SIZEOF(cfg->ptop));
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
#if defined(SIOCGIFHWADDR)
if (ioctl (s, SIOCGIFHWADDR, &ifrbuf) >= 0)
{
QSE_MEMCPY (cfg->ethw, ifrbuf.ifr_hwaddr.sa_data, QSE_SIZEOF(cfg->ethw));
}
#elif defined(MACIOC_GETADDR)
{
/* sco openserver
* use the streams interface to get the hardware address.
*/
int strfd;
qse_mchar_t devname[QSE_COUNTOF(ifrbuf.ifr_name) + 5 + 1] = QSE_MT("/dev/");
qse_mbscpy (&devname[5], ifrbuf.ifr_name);
if ((strfd = QSE_OPEN (devname, O_RDONLY, 0)) >= 0)
{
qse_uint8_t buf[QSE_SIZEOF(cfg->ethw)];
struct strioctl strioc;
strioc.ic_cmd = MACIOC_GETADDR;
strioc.ic_timout = -1;
strioc.ic_len = QSE_SIZEOF (buf);
strioc.ic_dp = buf;
if (ioctl (strfd, I_STR, (char *) &strioc) >= 0)
{
QSE_MEMCPY (cfg->ethw, buf, QSE_SIZEOF(cfg->ethw));
}
QSE_CLOSE (strfd);
}
}
#endif
return 0;
#else
@ -386,5 +581,10 @@ int qse_getnwifcfg (qse_nwifcfg_t* cfg)
}
if (s <= -1) return -1;
if (cfg->name[0] == QSE_T('\0')&& cfg->index >= 1)
{
/* TODO: support lookup by ifindex */
}
return get_nwifcfg (s, cfg);
}

View File

@ -46,9 +46,7 @@
# endif
#endif
#if !defined(SIOCGIFINDEX) && !defined(SIOCGIFNAME) && \
!defined(HAVE_IF_NAMETOINDEX) && !defined(HAVE_IF_INDEXTONAME) && \
defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
#if defined(_SCO_DS)
static int get_sco_ifconf (struct ifconf* ifc)
{
/* SCO doesn't have have any IFINDEX thing.
@ -97,17 +95,17 @@ static QSE_INLINE void free_sco_ifconf (struct ifconf* ifc)
#endif
unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
int qse_nwifmbstoindex (const qse_mchar_t* ptr, unsigned int* index)
{
#if defined(_WIN32)
/* TODO: */
return 0u;
return -1;
#elif defined(__OS2__)
/* TODO: */
return 0u;
return -1;
#elif defined(__DOS__)
/* TODO: */
return 0u;
return -1;
#elif defined(SIOCGIFINDEX)
int h, x;
@ -115,35 +113,45 @@ unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
struct ifreq ifr;
h = socket (AF_INET, SOCK_DGRAM, 0);
if (h <= -1) return 0u;
if (h <= -1) return -1;
QSE_MEMSET (&ifr, 0, QSE_SIZEOF(ifr));
len = qse_mbsxcpy (ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), ptr);
if (ptr[len] != QSE_MT('\0')) return 0u; /* name too long */
if (ptr[len] != QSE_MT('\0')) return -1; /* name too long */
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
if (x >= 0)
{
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
*index = ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
*index = ifr.ifr_index;
#endif
}
return x;
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t len;
unsigned int tmpidx;
len = qse_mbsxcpy (tmp, QSE_COUNTOF(tmp), ptr);
if (ptr[len] != QSE_MT('\0')) return 0u; /* name too long */
return if_nametoindex (tmp);
if (ptr[len] != QSE_MT('\0')) return -1; /* name too long */
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
tmpidx = if_nametoindex (tmp);
if (tmpidx == 0) return -1;
*index = tmpidx;
return 0;
#elif defined(_SCO_DS)
struct ifconf ifc;
int num, i;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
@ -151,60 +159,72 @@ unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
if (qse_mbscmp (ptr, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
*index = i + 1;
return 0;
}
}
free_sco_ifconf (&ifc);
return 0u;
return -1;
#else
return 0u;
return -1;
#endif
}
unsigned int qse_nwifmbsntoindex (const qse_mchar_t* ptr, qse_size_t len)
int qse_nwifmbsntoindex (const qse_mchar_t* ptr, qse_size_t len, unsigned int* index)
{
#if defined(_WIN32)
/* TODO: */
return 0u;
return -1;
#elif defined(__OS2__)
/* TODO: */
return 0u;
return -1;
#elif defined(__DOS__)
/* TODO: */
return 0u;
return -1;
#elif defined(SIOCGIFINDEX)
int h, x;
struct ifreq ifr;
h = socket (AF_INET, SOCK_DGRAM, 0);
if (h <= -1) return 0u;
if (h <= -1) return -1;
QSE_MEMSET (&ifr, 0, QSE_SIZEOF(ifr));
if (qse_mbsxncpy (ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), ptr, len) < len) return 0u; /* name too long */
if (qse_mbsxncpy (ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), ptr, len) < len) return -1; /* name too long */
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
if (x >= 0)
{
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
*index = ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
*index = ifr.ifr_index;
#endif
}
return x;
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
if (qse_mbsxncpy (tmp, QSE_COUNTOF(tmp), ptr, len) < len) return 0u; /* name too long */
return if_nametoindex (tmp);
unsigned int tmpidx;
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
if (qse_mbsxncpy (tmp, QSE_COUNTOF(tmp), ptr, len) < len) return -1;
tmpidx = if_nametoindex (tmp);
if (tmpidx == 0) return -1;
*index = tmpidx;
return 0;
#elif defined(_SCO_DS)
struct ifconf ifc;
int num, i;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
@ -212,29 +232,30 @@ unsigned int qse_nwifmbsntoindex (const qse_mchar_t* ptr, qse_size_t len)
if (qse_mbsxcmp (ptr, len, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
*index = i + 1;
return 0;
}
}
free_sco_ifconf (&ifc);
return 0u;
return -1;
#else
return 0u;
return -1;
#endif
}
unsigned int qse_nwifwcstoindex (const qse_wchar_t* ptr)
int qse_nwifwcstoindex (const qse_wchar_t* ptr, unsigned int* index)
{
#if defined(_WIN32)
/* TODO: */
return 0u;
return -1;
#elif defined(__OS2__)
/* TODO: */
return 0u;
return -1;
#elif defined(__DOS__)
/* TODO: */
return 0u;
return -1;
#elif defined(SIOCGIFINDEX)
int h, x;
@ -242,28 +263,37 @@ unsigned int qse_nwifwcstoindex (const qse_wchar_t* ptr)
qse_size_t wl, ml;
h = socket (AF_INET, SOCK_DGRAM, 0);
if (h <= -1) return 0u;
if (h <= -1) return -1;
ml = QSE_COUNTOF(ifr.ifr_name);
if (qse_wcstombs (ptr, &wl, ifr.ifr_name, &ml) <= -1) return 0u;
if (qse_wcstombs (ptr, &wl, ifr.ifr_name, &ml) <= -1) return -1;
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
if (x >= 0)
{
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
*index = ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
*index = ifr.ifr_index;
#endif
}
return x;
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
unsigned int tmpidx;
ml = QSE_COUNTOF(tmp);
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return 0u;
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return -1;
return if_nametoindex (tmp);
tmpidx = if_nametoindex (tmp);
if (tmpidx == 0) return -1;
*index = tmpidx;
return 0;
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
@ -273,9 +303,9 @@ unsigned int qse_nwifwcstoindex (const qse_wchar_t* ptr)
qse_size_t wl, ml;
ml = QSE_COUNTOF(tmp);
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return 0u;
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return -1;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
@ -283,29 +313,30 @@ unsigned int qse_nwifwcstoindex (const qse_wchar_t* ptr)
if (qse_mbscmp (tmp, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
*index = i + 1;
return 0;
}
}
free_sco_ifconf (&ifc);
return 0u;
return -1;
#else
return 0u;
return -1;
#endif
}
unsigned int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len)
int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len, unsigned int* index)
{
#if defined(_WIN32)
/* TODO: */
return 0u;
return -1;
#elif defined(__OS2__)
/* TODO: */
return 0u;
return -1;
#elif defined(__DOS__)
/* TODO: */
return 0u;
return -1;
#elif defined(SIOCGIFINDEX)
int h, x;
@ -313,29 +344,39 @@ unsigned int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len)
qse_size_t wl, ml;
h = socket (AF_INET, SOCK_DGRAM, 0);
if (h <= -1) return 0u;
if (h <= -1) return -1;
wl = len; ml = QSE_COUNTOF(ifr.ifr_name) - 1;
if (qse_wcsntombsn (ptr, &wl, ifr.ifr_name, &ml) <= -1) return 0;
if (qse_wcsntombsn (ptr, &wl, ifr.ifr_name, &ml) <= -1) return -1;
ifr.ifr_name[ml] = QSE_MT('\0');
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
if (x >= 0)
{
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
*index = ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
*index = ifr.ifr_index;
#endif
}
return x;
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
unsigned int tmpidx;
wl = len; ml = QSE_COUNTOF(tmp) - 1;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return 0u;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return -1;
tmp[ml] = QSE_MT('\0');
return if_nametoindex (tmp);
tmpidx = if_nametoindex (tmp);
if (tmpidx == 0) return -1;
*index = tmpidx;
return 0;
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
@ -344,7 +385,7 @@ unsigned int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len)
qse_size_t wl, ml;
wl = len; ml = QSE_COUNTOF(tmp) - 1;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return 0u;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return -1;
tmp[ml] = QSE_MT('\0');
if (get_sco_ifconf (&ifc) <= -1) return -1;
@ -355,14 +396,15 @@ unsigned int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len)
if (qse_mbscmp (tmp, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
*index = i + 1;
return 0;
}
}
free_sco_ifconf (&ifc);
return 0u;
return -1;
#else
return 0u;
return -1;
#endif
}

View File

@ -8,9 +8,9 @@
# include <windows.h>
#endif
static int test_ipad4 (void)
static int test_ip4ad (void)
{
qse_ipad4_t ipad4;
qse_ip4ad_t ip4ad;
qse_char_t buf[32];
qse_mchar_t mbsbuf[32];
qse_wchar_t wcsbuf[32];
@ -51,13 +51,13 @@ static int test_ipad4 (void)
for (i = 0; i < QSE_COUNTOF(ipstr); i++)
{
if (qse_strtoipad4 (ipstr[i], &ipad4) <= -1)
if (qse_strtoip4ad (ipstr[i], &ip4ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %s\n"), ipstr[i]);
}
else
{
qse_ipad4tostr (&ipad4, buf, QSE_COUNTOF(buf));
qse_ip4adtostr (&ip4ad, buf, QSE_COUNTOF(buf));
qse_printf (QSE_T("Converted [%s] to [%s]\n"), ipstr[i], buf);
}
}
@ -65,13 +65,13 @@ static int test_ipad4 (void)
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_mbs); i++)
{
if (qse_mbstoipad4 (ipstr_mbs[i], &ipad4) <= -1)
if (qse_mbstoip4ad (ipstr_mbs[i], &ip4ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %hs\n"), ipstr_mbs[i]);
}
else
{
qse_ipad4tombs (&ipad4, mbsbuf, QSE_COUNTOF(mbsbuf));
qse_ip4adtombs (&ip4ad, mbsbuf, QSE_COUNTOF(mbsbuf));
qse_printf (QSE_T("Converted [%hs] to [%hs]\n"), ipstr[i], mbsbuf);
}
}
@ -79,13 +79,13 @@ static int test_ipad4 (void)
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_wcs); i++)
{
if (qse_wcstoipad4 (ipstr_wcs[i], &ipad4) <= -1)
if (qse_wcstoip4ad (ipstr_wcs[i], &ip4ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %ls\n"), ipstr_wcs[i]);
}
else
{
qse_ipad4towcs (&ipad4, wcsbuf, QSE_COUNTOF(wcsbuf));
qse_ip4adtowcs (&ip4ad, wcsbuf, QSE_COUNTOF(wcsbuf));
qse_printf (QSE_T("Converted [%ls] to [%ls]\n"), ipstr[i], wcsbuf);
}
}
@ -93,9 +93,9 @@ static int test_ipad4 (void)
return 0;
}
static int test_ipad6 (void)
static int test_ip6ad (void)
{
qse_ipad6_t ipad6;
qse_ip6ad_t ip6ad;
qse_char_t buf[32];
qse_mchar_t mbsbuf[32];
qse_wchar_t wcsbuf[32];
@ -136,13 +136,13 @@ static int test_ipad6 (void)
for (i = 0; i < QSE_COUNTOF(ipstr); i++)
{
if (qse_strtoipad6 (ipstr[i], &ipad6) <= -1)
if (qse_strtoip6ad (ipstr[i], &ip6ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %s\n"), ipstr[i]);
}
else
{
qse_ipad6tostr (&ipad6, buf, QSE_COUNTOF(buf));
qse_ip6adtostr (&ip6ad, buf, QSE_COUNTOF(buf));
qse_printf (QSE_T("Converted [%s] to [%s]\n"), ipstr[i], buf);
}
}
@ -150,13 +150,13 @@ static int test_ipad6 (void)
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_mbs); i++)
{
if (qse_mbstoipad6 (ipstr_mbs[i], &ipad6) <= -1)
if (qse_mbstoip6ad (ipstr_mbs[i], &ip6ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %hs\n"), ipstr_mbs[i]);
}
else
{
qse_ipad6tombs (&ipad6, mbsbuf, QSE_COUNTOF(mbsbuf));
qse_ip6adtombs (&ip6ad, mbsbuf, QSE_COUNTOF(mbsbuf));
qse_printf (QSE_T("Converted [%hs] to [%hs]\n"), ipstr_mbs[i], mbsbuf);
}
}
@ -164,13 +164,13 @@ static int test_ipad6 (void)
qse_printf (QSE_T("-------------------\n"));
for (i = 0; i < QSE_COUNTOF(ipstr_wcs); i++)
{
if (qse_wcstoipad6 (ipstr_wcs[i], &ipad6) <= -1)
if (qse_wcstoip6ad (ipstr_wcs[i], &ip6ad) <= -1)
{
qse_printf (QSE_T("Failed to convert %ls\n"), ipstr_wcs[i]);
}
else
{
qse_ipad6towcs (&ipad6, wcsbuf, QSE_COUNTOF(wcsbuf));
qse_ip6adtowcs (&ip6ad, wcsbuf, QSE_COUNTOF(wcsbuf));
qse_printf (QSE_T("Converted [%ls] to [%ls]\n"), ipstr_wcs[i], wcsbuf);
}
}
@ -180,9 +180,9 @@ static int test_ipad6 (void)
static int test_main (int argc, qse_char_t* argv[])
{
test_ipad4 ();
test_ip4ad ();
qse_printf (QSE_T("==============\n"));
test_ipad6 ();
test_ip6ad ();
return 0;
}

View File

@ -35,7 +35,7 @@ static int test_main (int argc, qse_char_t* argv[])
{
qse_char_t name[100];
unsigned int index;
int i;
unsigned int i;
for (i = 1; ;i++)
{
@ -45,8 +45,7 @@ static int test_main (int argc, qse_char_t* argv[])
break;
}
index = qse_nwifstrtoindex (name);
if (index == 0)
if (qse_nwifstrtoindex (name, &index) <= -1)
{
qse_printf (QSE_T("ifname %s failed\n"), name);
break;
@ -54,11 +53,11 @@ static int test_main (int argc, qse_char_t* argv[])
if (i != index)
{
qse_printf (QSE_T("index mismatch %d %d %s\n"), i, index, name);
qse_printf (QSE_T("index mismatch %u %u %s\n"), i, index, name);
break;
}
qse_printf (QSE_T("OK %d %s\n"), index, name);
qse_printf (QSE_T("OK %u %s\n"), index, name);
}
qse_printf (QSE_T("================================================\n"));

View File

@ -28,6 +28,7 @@ static void print_nwifcfg (qse_nwifcfg_t* ptr)
}
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("\n"));
}