added QSE_GLOB_TOLERANT

enhanced check for __int128_t
added qse_getnwifcfg()
added qse_skad_t, qse_skadtonwad(), qse_nwadtoskad()
added more checks to configure.ac
This commit is contained in:
hyung-hwan 2012-11-16 16:46:49 +00:00
parent b94dd042c5
commit 034d3e9c04
26 changed files with 1541 additions and 275 deletions

View File

@ -489,6 +489,7 @@ static int expand_wildcard (int argc, qse_char_t* argv[], int glob, xarg_t* xarg
if (glob)
{
x = qse_glob (argv[i], collect_into_xarg, xarg,
QSE_GLOB_TOLERANT |
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_GLOB_NOESCAPE | QSE_GLOB_PERIOD | QSE_GLOB_IGNORECASE,
#else
@ -816,7 +817,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
/* the remaining arguments are input console file names */
if (expand_wildcard (argc - opt.ind, &argv[opt.ind], do_glob, &arg->icf) <= -1)
{
print_error (QSE_T("out of memory\n"));
print_error (QSE_T("failed to expand wildcard\n"));
goto oops;
}
}

View File

@ -653,7 +653,12 @@ static int expand_wildcards (int argc, qse_char_t* argv[], int glob, xarg_t* xar
if (glob)
{
x = qse_glob (argv[i], collect_into_xarg, xarg,
QSE_GLOB_TOLERANT |
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
QSE_GLOB_NOESCAPE | QSE_GLOB_PERIOD | QSE_GLOB_IGNORECASE,
#else
QSE_GLOB_PERIOD,
#endif
xarg->mmgr
);

271
qse/configure vendored
View File

@ -17307,7 +17307,7 @@ fi
done
for ac_header in sys/resource.h sys/wait.h sys/syscall.h sys/sendfile.h sys/epoll.h
for ac_header in sys/resource.h sys/wait.h sys/syscall.h sys/sendfile.h sys/epoll.h sys/ioctl.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"
@ -17320,7 +17320,7 @@ fi
done
for ac_header in sys/ioctl.h net/if.h
for ac_header in 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,6 +17333,32 @@ fi
done
for ac_header in net/if.h
do :
ac_fn_c_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" "#include <sys/socket.h>
"
if test "x$ac_cv_header_net_if_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_NET_IF_H 1
_ACEOF
fi
done
for ac_header in net/if_dl.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 :
cat >>confdefs.h <<_ACEOF
#define HAVE_NET_IF_DL_H 1
_ACEOF
fi
done
for ac_header in uci.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "uci.h" "ac_cv_header_uci_h" "$ac_includes_default"
@ -17508,18 +17534,6 @@ _ACEOF
fi
done
for ac_func in if_nametoindex if_indextoname
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
@ -17673,6 +17687,22 @@ then
fi
OLDLIBS="$LIBS"
LIBS="$SOCKET_LIBS $LIBS"
for ac_func in if_nametoindex if_indextoname getifaddrs
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
LIBS="$OLDLIBS"
for ac_func in sendfile sendfile64 sendfilev sendfilev64
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@ -18598,6 +18628,37 @@ _ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct ifreq" "ifr_ifindex" "ac_cv_member_struct_ifreq_ifr_ifindex" "#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
"
if test "x$ac_cv_member_struct_ifreq_ifr_ifindex" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_IFREQ_IFR_IFINDEX 1
_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
#include <net/if.h>
#endif
"
if test "x$ac_cv_member_struct_ifreq_ifr_mtu" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_IFREQ_IFR_MTU 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]];'.
@ -19441,6 +19502,177 @@ _ACEOF
if test "${platform_win32}" == "yes"
then
# 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]];'.
# This bug is HP SR number 8606223364.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_in" >&5
$as_echo_n "checking size of struct sockaddr_in... " >&6; }
if ${ac_cv_sizeof_struct_sockaddr_in+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_in))" "ac_cv_sizeof_struct_sockaddr_in" "
#include <winsock2.h>
#include <ws2tcpip.h>
"; then :
else
if test "$ac_cv_type_struct_sockaddr_in" = yes; then
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "cannot compute sizeof (struct sockaddr_in)
See \`config.log' for more details" "$LINENO" 5; }
else
ac_cv_sizeof_struct_sockaddr_in=0
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_in" >&5
$as_echo "$ac_cv_sizeof_struct_sockaddr_in" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_STRUCT_SOCKADDR_IN $ac_cv_sizeof_struct_sockaddr_in
_ACEOF
# 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]];'.
# This bug is HP SR number 8606223364.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_in6" >&5
$as_echo_n "checking size of struct sockaddr_in6... " >&6; }
if ${ac_cv_sizeof_struct_sockaddr_in6+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_in6))" "ac_cv_sizeof_struct_sockaddr_in6" "
#include <winsock2.h>
#include <ws2tcpip.h>
"; then :
else
if test "$ac_cv_type_struct_sockaddr_in6" = yes; then
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "cannot compute sizeof (struct sockaddr_in6)
See \`config.log' for more details" "$LINENO" 5; }
else
ac_cv_sizeof_struct_sockaddr_in6=0
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_in6" >&5
$as_echo "$ac_cv_sizeof_struct_sockaddr_in6" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_STRUCT_SOCKADDR_IN6 $ac_cv_sizeof_struct_sockaddr_in6
_ACEOF
else
# 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]];'.
# This bug is HP SR number 8606223364.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_in" >&5
$as_echo_n "checking size of struct sockaddr_in... " >&6; }
if ${ac_cv_sizeof_struct_sockaddr_in+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_in))" "ac_cv_sizeof_struct_sockaddr_in" "
#include <sys/socket.h>
#include <netinet/in.h>
"; then :
else
if test "$ac_cv_type_struct_sockaddr_in" = yes; then
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "cannot compute sizeof (struct sockaddr_in)
See \`config.log' for more details" "$LINENO" 5; }
else
ac_cv_sizeof_struct_sockaddr_in=0
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_in" >&5
$as_echo "$ac_cv_sizeof_struct_sockaddr_in" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_STRUCT_SOCKADDR_IN $ac_cv_sizeof_struct_sockaddr_in
_ACEOF
# 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]];'.
# This bug is HP SR number 8606223364.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_in6" >&5
$as_echo_n "checking size of struct sockaddr_in6... " >&6; }
if ${ac_cv_sizeof_struct_sockaddr_in6+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_in6))" "ac_cv_sizeof_struct_sockaddr_in6" "
#include <sys/socket.h>
#include <netinet/in.h>
"; then :
else
if test "$ac_cv_type_struct_sockaddr_in6" = yes; then
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error 77 "cannot compute sizeof (struct sockaddr_in6)
See \`config.log' for more details" "$LINENO" 5; }
else
ac_cv_sizeof_struct_sockaddr_in6=0
fi
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_in6" >&5
$as_echo "$ac_cv_sizeof_struct_sockaddr_in6" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_STRUCT_SOCKADDR_IN6 $ac_cv_sizeof_struct_sockaddr_in6
_ACEOF
fi
if test ${ac_cv_sizeof___int128_t} -gt 0
then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
__int128_t x = 0; x %= 10;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
else
ac_cv_sizeof___int128_t=0
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
cat >>confdefs.h <<_ACEOF
#define QSE_SIZEOF_CHAR ${ac_cv_sizeof_char}
@ -19549,6 +19781,17 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
cat >>confdefs.h <<_ACEOF
#define QSE_SIZEOF_STRUCT_SOCKADDR_IN ${ac_cv_sizeof_struct_sockaddr_in}
_ACEOF
cat >>confdefs.h <<_ACEOF
#define QSE_SIZEOF_STRUCT_SOCKADDR_IN6 ${ac_cv_sizeof_struct_sockaddr_in6}
_ACEOF
qse_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`"
qse_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`"
qse_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`"

View File

@ -101,8 +101,10 @@ dnl check header files.
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])
AC_CHECK_HEADERS([sys/ioctl.h net/if.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([uci.h])
dnl check data types
@ -126,7 +128,6 @@ AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([fdopendir])
AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([if_nametoindex if_indextoname])
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
@ -164,6 +165,11 @@ then
fi
AC_SUBST(SOCKET_LIBS)
OLDLIBS="$LIBS"
LIBS="$SOCKET_LIBS $LIBS"
AC_CHECK_FUNCS([if_nametoindex if_indextoname getifaddrs])
LIBS="$OLDLIBS"
dnl check if sendfile and its variants exist in the standard c library
dnl it inspects the existence of each missing function in the sendfile library.
AC_CHECK_FUNCS([sendfile sendfile64 sendfilev sendfilev64])
@ -247,6 +253,19 @@ 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], [], [],
[#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], [], [],
[#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif])
dnl check the size of primitive data types
AC_CHECK_SIZEOF(char,,[[]])
AC_CHECK_SIZEOF(short,,[[]])
@ -277,6 +296,42 @@ AC_CHECK_SIZEOF(off64_t)
AC_CHECK_SIZEOF(mbstate_t,,[#include <wchar.h>])
AX_CHECK_NUMVALOF(MB_LEN_MAX,[32],[#include <limits.h>])
if test "${platform_win32}" == "yes"
then
AC_CHECK_SIZEOF(struct sockaddr_in,,[
#include <winsock2.h>
#include <ws2tcpip.h>])
AC_CHECK_SIZEOF(struct sockaddr_in6,, [
#include <winsock2.h>
#include <ws2tcpip.h>])
else
AC_CHECK_SIZEOF(struct sockaddr_in,,[
#include <sys/socket.h>
#include <netinet/in.h>])
AC_CHECK_SIZEOF(struct sockaddr_in6,, [
#include <sys/socket.h>
#include <netinet/in.h>])
fi
dnl gcc 3.4.3 on opensolaris x86 gave this warning without -msse or
dnl something similar.
dnl SSE vector argument without SSE enabled changes the ABI
dnl it also ended with an internal compiler error while compiling
dnl some expressions like 'v % base' where v is of the __int128_t type.
dnl so i've added this check to determine if the compiler has
dnl proper support for __int128_t.
dnl
dnl Changing ac_cv_sizeof___int128_t here doesn't corret SIZEOF___INT128_T
dnl since it's already generated. It only affects QSE_SIZEOF___INT128_T below.
if test ${ac_cv_sizeof___int128_t} -gt 0
then
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [__int128_t x = 0; x %= 10;])],
[],
[ac_cv_sizeof___int128_t=0]
)
fi
AC_DEFINE_UNQUOTED(QSE_SIZEOF_CHAR, ${ac_cv_sizeof_char}, [sizeof(char)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_SHORT, ${ac_cv_sizeof_short}, [sizeof(short)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_INT, ${ac_cv_sizeof_int}, [sizeof(int)])
@ -301,6 +356,9 @@ AC_DEFINE_UNQUOTED(QSE_SIZEOF_OFF64_T, ${ac_cv_sizeof_off64_t}, [sizeof(off64_t)
AC_DEFINE_UNQUOTED(QSE_SIZEOF_MBSTATE_T, ${ac_cv_sizeof_mbstate_t}, [sizeof(mbstate_t)])
AC_DEFINE_UNQUOTED(QSE_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)])
qse_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`"
qse_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`"
qse_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`"

View File

@ -45,7 +45,10 @@ enum qse_glob_flags_t
/** Perform case-insensitive matching.
* This option is always on in Win32/OS2/DOS. */
QSE_GLOB_IGNORECASE = (1 << 2)
QSE_GLOB_IGNORECASE = (1 << 2),
/** Make the function to be more fault-resistent */
QSE_GLOB_TOLERANT = (1 << 3)
};
#ifdef __cplusplus

View File

@ -37,7 +37,6 @@ typedef struct qse_nwad_t qse_nwad_t;
struct qse_nwad_t
{
qse_nwad_type_t type;
union
{
struct
@ -70,6 +69,21 @@ enum qse_nwadtostr_flag_t
#define QSE_NWADTOWCS_ALL QSE_NWADTOSTR_ALL
};
typedef struct qse_skad_t qse_skad_t;
struct qse_skad_t
{
#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];
#elif (QSE_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) && \
(QSE_SIZEOF_STRUCT_SOCKADDR_IN6 >= QSE_SIZEOF_STRUCT_SOCKADDR_IN)
qse_uint8_t data[QSE_SIZEOF_STRUCT_SOCKADDR_IN6];
#else
/* no sockaddr_xxx is available */
qse_uint8_t data[QSE_SIZEOF(qse_nwad_t)];
#endif
};
#ifdef __cplusplus
extern "C" {
@ -126,6 +140,20 @@ qse_size_t qse_nwadtowcs (
# define qse_nwadtostr(nwad,ptr,len,flags) qse_nwadtowcs(nwad,ptr,len,flags)
#endif
int qse_skadtonwad (
const qse_skad_t* skad,
qse_nwad_t* nwad
);
int qse_nwadtoskad (
const qse_nwad_t* nwad,
qse_skad_t* skad
);
int qse_skadfamily (
const qse_skad_t* skad
);
#ifdef __cplusplus
}
#endif

View File

@ -23,6 +23,40 @@
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/nwad.h>
typedef struct qse_nwifcfg_t qse_nwifcfg_t;
enum qse_nwifcfg_flag_t
{
QSE_NWIFCFG_UP = (1 << 0),
QSE_NWIFCFG_RUNNING = (1 << 1),
QSE_NWIFCFG_BCAST = (1 << 2),
QSE_NWIFCFG_PTOP = (1 << 3)
};
enum qse_nwifcfg_type_t
{
QSE_NWIFCFG_IN4,
QSE_NWIFCFG_IN6
};
typedef enum qse_nwifcfg_type_t qse_nwifcfg_type_t;
struct qse_nwifcfg_t
{
qse_nwifcfg_type_t type;
qse_char_t name[64];
/* 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;
};
#ifdef __cplusplus
extern "C" {
@ -46,13 +80,13 @@ unsigned int qse_nwifwcsntoindex (
qse_size_t len
);
qse_size_t qse_nwifindextombs (
int qse_nwifindextombs (
unsigned int index,
qse_mchar_t* buf,
qse_size_t len
);
qse_size_t qse_nwifindextowcs (
int qse_nwifindextowcs (
unsigned int index,
qse_wchar_t* buf,
qse_size_t len

View File

@ -82,6 +82,10 @@
# define QSE_MBLEN_MAX 8
#
# define QSE_CHAR_IS_WCHAR
#
# /* these two have only to be large enough */
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN 32
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN6 64
#else
# error Define the size of various data types.
#endif

View File

@ -138,6 +138,10 @@ _M_X64 x64 platform
# define QSE_MBLEN_MAX 8
#
# define QSE_CHAR_IS_WCHAR
#
# /* these two have only to be large enough */
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN 32
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN6 64
#else
# error Define the size of various data types.
#endif

View File

@ -59,6 +59,10 @@
# define QSE_MBLEN_MAX 8
#
# define QSE_CHAR_IS_WCHAR
#
# /* these two have only to be large enough */
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN 32
# define QSE_SIZEOF_STRUCT_SOCKADDR_IN6 64
#else
# error Define the size of various data types.
#endif

View File

@ -167,9 +167,15 @@
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
/* Define to 1 if you have the `getifaddrs' function. */
#undef HAVE_GETIFADDRS
/* Define to 1 if you have the `gettid' function. */
#undef HAVE_GETTID
/* Define to 1 if you have the <ifaddrs.h> header file. */
#undef HAVE_IFADDRS_H
/* Define to 1 if you have the `if_indextoname' function. */
#undef HAVE_IF_INDEXTONAME
@ -254,6 +260,9 @@
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the <net/if_dl.h> header file. */
#undef HAVE_NET_IF_DL_H
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
@ -377,6 +386,12 @@
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#undef HAVE_STRUCT_DIRENT_D_TYPE
/* Define to 1 if `ifr_ifindex' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_IFINDEX
/* Define to 1 if `ifr_mtu' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_MTU
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
@ -421,6 +436,12 @@
/* Define to 1 if you have the <sys/sendfile.h> header file. */
#undef HAVE_SYS_SENDFILE_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
@ -643,6 +664,12 @@
/* sizeof(short) */
#undef QSE_SIZEOF_SHORT
/* sizeof(struct sockaddr_in) */
#undef QSE_SIZEOF_STRUCT_SOCKADDR_IN
/* sizeof(struct sockaddr_in6) */
#undef QSE_SIZEOF_STRUCT_SOCKADDR_IN6
/* sizeof(void*) */
#undef QSE_SIZEOF_VOID_P
@ -706,6 +733,12 @@
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of `struct sockaddr_in', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_IN
/* The size of `struct sockaddr_in6', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_IN6
/* The size of `void *', as computed by sizeof. */
#undef SIZEOF_VOID_P

View File

@ -346,7 +346,7 @@ typedef enum qse_tri_t qse_tri_t;
# define QSE_HAVE_UINT128_T
typedef __int128 qse_int128_t;
typedef unsigned __int128 qse_uint128_t;
#elif QSE_SIZEOF___INT128_T == 16
#elif (QSE_SIZEOF___INT128_T == 16)
# define QSE_HAVE_INT128_T
# define QSE_HAVE_UINT128_T
typedef __int128_t qse_int128_t;

View File

@ -49,7 +49,9 @@ libqsecmn_la_SOURCES = \
mem.c \
mux.c \
nwad.c \
nwad-skad.c \
nwif.c \
nwif-cfg.c \
nwio.c \
oht.c \
opt.c \

View File

@ -90,33 +90,34 @@ libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \
alg-sort.c assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c \
fma.c fmt.c fs.c fs-err.c fs-move.c glob.c hton.c ipad.c lda.c \
main.c mbwc.c mbwc-str.c mem.c mux.c nwad.c nwif.c nwio.c \
oht.c opt.c path-basename.c path-canon.c pio.c pma.c rbt.c \
rex.c sio.c sll.c slmb.c stdio.c str-beg.c str-cat.c str-chr.c \
str-cnv.c str-cmp.c str-cpy.c str-del.c str-dup.c str-dynm.c \
str-dynw.c str-end.c str-excl.c str-fcpy.c str-fnmat.c \
str-incl.c str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c \
str-rot.c str-set.c str-spl.c str-spn.c str-str.c str-subst.c \
str-tok.c str-trm.c str-word.c task.c time.c tio.c tre.c \
tre-ast.c tre-compile.c tre-match-backtrack.c \
tre-match-parallel.c tre-parse.c tre-stack.c uri.c utf8.c \
xma.c cp949.c cp950.c
main.c mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c \
nwif-cfg.c nwio.c oht.c opt.c path-basename.c path-canon.c \
pio.c pma.c rbt.c rex.c sio.c sll.c slmb.c stdio.c str-beg.c \
str-cat.c str-chr.c str-cnv.c str-cmp.c str-cpy.c str-del.c \
str-dup.c str-dynm.c str-dynw.c str-end.c str-excl.c \
str-fcpy.c str-fnmat.c str-incl.c str-len.c str-pac.c \
str-pbrk.c str-put.c str-rev.c str-rot.c str-set.c str-spl.c \
str-spn.c str-str.c str-subst.c str-tok.c str-trm.c str-word.c \
task.c time.c tio.c tre.c tre-ast.c tre-compile.c \
tre-match-backtrack.c tre-match-parallel.c tre-parse.c \
tre-stack.c uri.c utf8.c xma.c cp949.c cp950.c
@INCLUDE_MORE_CMGRS_TRUE@am__objects_1 = cp949.lo cp950.lo
am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
alg-sort.lo assert.lo chr.lo dir.lo dll.lo env.lo gdl.lo \
htb.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \
hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo \
mux.lo nwad.lo nwif.lo nwio.lo oht.lo opt.lo path-basename.lo \
path-canon.lo pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo \
slmb.lo stdio.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo \
str-cmp.lo str-cpy.lo str-del.lo str-dup.lo str-dynm.lo \
str-dynw.lo str-end.lo str-excl.lo str-fcpy.lo str-fnmat.lo \
str-incl.lo str-len.lo str-pac.lo str-pbrk.lo str-put.lo \
str-rev.lo str-rot.lo str-set.lo str-spl.lo str-spn.lo \
str-str.lo str-subst.lo str-tok.lo str-trm.lo str-word.lo \
task.lo time.lo tio.lo tre.lo tre-ast.lo tre-compile.lo \
tre-match-backtrack.lo tre-match-parallel.lo tre-parse.lo \
tre-stack.lo uri.lo utf8.lo xma.lo $(am__objects_1)
mux.lo nwad.lo nwad-skad.lo nwif.lo nwif-cfg.lo nwio.lo oht.lo \
opt.lo path-basename.lo path-canon.lo pio.lo pma.lo rbt.lo \
rex.lo sio.lo sll.lo slmb.lo stdio.lo str-beg.lo str-cat.lo \
str-chr.lo str-cnv.lo str-cmp.lo str-cpy.lo str-del.lo \
str-dup.lo str-dynm.lo str-dynw.lo str-end.lo str-excl.lo \
str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo str-pac.lo \
str-pbrk.lo str-put.lo str-rev.lo str-rot.lo str-set.lo \
str-spl.lo str-spn.lo str-str.lo str-subst.lo str-tok.lo \
str-trm.lo str-word.lo task.lo time.lo tio.lo tre.lo \
tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
tre-match-parallel.lo tre-parse.lo tre-stack.lo uri.lo utf8.lo \
xma.lo $(am__objects_1)
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -352,16 +353,17 @@ noinst_HEADERS = \
libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \
assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c fma.c fmt.c \
fs.c fs-err.c fs-move.c glob.c hton.c ipad.c lda.c main.c \
mbwc.c mbwc-str.c mem.c mux.c nwad.c nwif.c nwio.c oht.c opt.c \
path-basename.c path-canon.c pio.c pma.c rbt.c rex.c sio.c \
sll.c slmb.c stdio.c str-beg.c str-cat.c str-chr.c str-cnv.c \
str-cmp.c str-cpy.c str-del.c str-dup.c str-dynm.c str-dynw.c \
str-end.c str-excl.c str-fcpy.c str-fnmat.c str-incl.c \
str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c \
str-set.c str-spl.c str-spn.c str-str.c str-subst.c str-tok.c \
str-trm.c str-word.c task.c time.c tio.c tre.c tre-ast.c \
tre-compile.c tre-match-backtrack.c tre-match-parallel.c \
tre-parse.c tre-stack.c uri.c utf8.c xma.c $(am__append_1)
mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c \
nwif-cfg.c nwio.c oht.c opt.c path-basename.c path-canon.c \
pio.c pma.c rbt.c rex.c sio.c sll.c slmb.c stdio.c str-beg.c \
str-cat.c str-chr.c str-cnv.c str-cmp.c str-cpy.c str-del.c \
str-dup.c str-dynm.c str-dynw.c str-end.c str-excl.c \
str-fcpy.c str-fnmat.c str-incl.c str-len.c str-pac.c \
str-pbrk.c str-put.c str-rev.c str-rot.c str-set.c str-spl.c \
str-spn.c str-str.c str-subst.c str-tok.c str-trm.c str-word.c \
task.c time.c tio.c tre.c tre-ast.c tre-compile.c \
tre-match-backtrack.c tre-match-parallel.c tre-parse.c \
tre-stack.c uri.c utf8.c xma.c $(am__append_1)
libqsecmn_la_LDFLAGS = -L$(libdir) -version-info 1:0:0 -no-undefined
libqsecmn_la_LIBADD = $(SOCKET_LIBS)
@ENABLE_CXX_TRUE@libqsecmnxx_la_SOURCES = \
@ -475,7 +477,9 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mux.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwad-skad.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwad.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwif-cfg.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwif.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oht.Plo@am__quote@

View File

@ -74,6 +74,7 @@ struct glob_t
void* cbctx;
qse_mmgr_t* mmgr;
int flags;
qse_str_t path;
qse_str_t tbuf; /* temporary buffer */
@ -417,7 +418,11 @@ entry:
qse_str_setlen (&g->path, tmp2);
x = qse_dir_read (dp, &ent);
if (x <= -1) goto oops;
if (x <= -1)
{
if (g->flags & QSE_GLOB_TOLERANT) break;
else goto oops;
}
if (x == 0) break;
if (qse_str_cat (&g->path, ent.name) == (qse_size_t)-1) goto oops;
@ -545,6 +550,7 @@ int qse_glob (const qse_char_t* pattern, qse_glob_cbimpl_t cbimpl, void* cbctx,
g.cbimpl = cbimpl;
g.cbctx = cbctx;
g.mmgr = mmgr;
g.flags = flags;
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
g.fnmat_flags |= QSE_STRFNMAT_IGNORECASE;

167
qse/lib/cmn/nwad-skad.c Normal file
View File

@ -0,0 +1,167 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/nwad.h>
#include "mem.h"
#if defined(_WIN32)
# include <winsock2.h>
# include <ws2tcpip.h> /* sockaddr_in6 */
# include <windows.h>
#elif defined(__OS2__)
# include <types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# pragma library("tcpip32.lib")
#elif defined(__DOS__)
/* TODO: consider watt-32 */
#else
# include <sys/socket.h>
# include <netinet/in.h>
#endif
union sockaddr_t
{
#if defined(AF_INET) || defined(AF_INET6)
#if defined(AF_INET)
struct sockaddr_in in4;
#endif
#if defined(AF_INET6)
struct sockaddr_in6 in6;
#endif
#else
int dummy;
#endif
};
typedef union sockaddr_t sockaddr_t;
#if defined(AF_INET)
# define FAMILY(x) (((struct sockaddr_in*)(x))->sin_family)
#elif defined(AF_INET6)
# define FAMILY(x) (((struct sockaddr_in6*)(x))->sin6_family)
#else
# define FAMILY(x) (-1)
#endif
static QSE_INLINE int skad_to_nwad (const sockaddr_t* skad, qse_nwad_t* nwad)
{
int addrsize = -1;
switch (FAMILY(skad))
{
#if defined(AF_INET)
case AF_INET:
{
struct sockaddr_in* in;
in = (struct sockaddr_in*)skad;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (nwad, 0, QSE_SIZEOF(*nwad));
nwad->type = QSE_NWAD_IN4;
nwad->u.in4.addr.value = in->sin_addr.s_addr;
nwad->u.in4.port = in->sin_port;
break;
}
#endif
#if defined(AF_INET6)
case AF_INET6:
{
struct sockaddr_in6* in;
in = (struct sockaddr_in6*)skad;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (nwad, 0, QSE_SIZEOF(*nwad));
nwad->type = QSE_NWAD_IN6;
QSE_MEMCPY (&nwad->u.in6.addr, &in->sin6_addr, QSE_SIZEOF(nwad->u.in6.addr));
nwad->u.in6.scope = in->sin6_scope_id;
nwad->u.in6.port = in->sin6_port;
break;
}
#endif
default:
break;
}
return addrsize;
}
static QSE_INLINE int nwad_to_skad (const qse_nwad_t* nwad, sockaddr_t* skad)
{
int addrsize = -1;
switch (nwad->type)
{
case QSE_NWAD_IN4:
{
#if defined(AF_INET)
struct sockaddr_in* in;
in = (struct sockaddr_in*)skad;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
in->sin_family = AF_INET;
in->sin_addr.s_addr = nwad->u.in4.addr.value;
in->sin_port = nwad->u.in4.port;
#endif
break;
}
case QSE_NWAD_IN6:
{
#if defined(AF_INET6)
struct sockaddr_in6* in;
in = (struct sockaddr_in6*)skad;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
in->sin6_family = AF_INET6;
QSE_MEMCPY (&in->sin6_addr, &nwad->u.in6.addr, QSE_SIZEOF(nwad->u.in6.addr));
in->sin6_scope_id = nwad->u.in6.scope;
in->sin6_port = nwad->u.in6.port;
#endif
break;
}
}
return addrsize;
}
int qse_skadtonwad (const qse_skad_t* skad, qse_nwad_t* nwad)
{
QSE_ASSERT (QSE_SIZEOF(*skad) >= QSE_SIZEOF(sockaddr_t));
return skad_to_nwad ((const sockaddr_t*)skad, nwad);
}
int qse_nwadtoskad (const qse_nwad_t* nwad, qse_skad_t* skad)
{
QSE_ASSERT (QSE_SIZEOF(*skad) >= QSE_SIZEOF(sockaddr_t));
return nwad_to_skad (nwad, (sockaddr_t*)skad);
}
int qse_skadfamily (const qse_skad_t* skad)
{
QSE_ASSERT (QSE_SIZEOF(*skad) >= QSE_SIZEOF(sockaddr_t));
return FAMILY(skad);
}

View File

@ -440,7 +440,7 @@ qse_size_t qse_nwadtombs (
if (xlen + 1 >= len) goto done;
tmp = qse_nwifindextombs (nwad->u.in6.scope, &buf[xlen], len - xlen);
if (tmp <= 0)
if (tmp <= -1)
{
xlen += qse_fmtuintmaxtombs (
&buf[xlen], len - xlen,
@ -547,7 +547,7 @@ qse_size_t qse_nwadtowcs (
if (xlen + 1 >= len) goto done;
tmp = qse_nwifindextowcs (nwad->u.in6.scope, &buf[xlen], len - xlen);
if (tmp <= 0)
if (tmp <= -1)
{
xlen += qse_fmtuintmaxtowcs (
&buf[xlen], len - xlen,

390
qse/lib/cmn/nwif-cfg.c Normal file
View File

@ -0,0 +1,390 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it uheadr the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/nwif.h>
#include <qse/cmn/str.h>
#include <qse/cmn/mbwc.h>
#include "mem.h"
#if defined(_WIN32)
# include <winsock2.h>
# include <ws2tcpip.h>
# include <iphlpapi.h>
#elif defined(__OS2__)
# include <types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <tcpustd.h>
# include <sys/ioctl.h>
# include <nerrno.h>
# pragma library("tcpip32.lib")
#elif defined(__DOS__)
/* TODO: */
#else
# include "syscall.h"
# include <sys/socket.h>
# include <netinet/in.h>
# if defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
# endif
# if defined(HAVE_NET_IF_H)
# include <net/if.h>
# endif
# if defined(HAVE_SYS_SOCKIO_H)
# include <sys/sockio.h>
# endif
# if defined(HAVE_IFADDRS_H)
# include <ifaddrs.h>
# endif
#endif
/*
#if defined(HAVE_NET_IF_DL_H)
# include <net/if_dl.h>
#endif
#ifndef SIOCGLIFHWADDR
#define SIOCGLIFHWADDR _IOWR('i', 192, struct lifreq)
#endif
struct lifreq lif;
memset(&lif, 0, sizeof(lif));
strlcpy(lif.lifr_name, ifname, sizeof(lif.lifr_name));
if (ioctl(sock, SIOCGLIFHWADDR, &lif) != -1) {
struct sockaddr_dl *sp;
sp = (struct sockaddr_dl *)&lif.lifr_addr;
memcpy(buf, &sp->sdl_data[0], sp->sdl_alen);
return sp->sdl_alen;
}
*/
#if defined(SIOCGLIFCONF)
static int get_nwifs (qse_mmgr_t* mmgr, int s, int f, qse_xptl_t* nwifs)
{
struct lifnum ifn;
struct lifconf ifc;
qse_xptl_t b;
qse_size_t ifcount;
ifcount = 0;
b.ptr = QSE_NULL;
b.len = 0;
do
{
ifn.lifn_family = f;
ifn.lifn_flags = 0;
if (ioctl (s, SIOCGLIFNUM, &ifn) <= -1) goto oops;
if (b.ptr)
{
/* b.ptr won't be QSE_NULL when retrying */
if (ifn.lifn_count <= ifcount) break;
}
/* +1 for extra space to leave empty
* if SIOCGLIFCONF returns the same number of
* intefaces as SIOCLIFNUM */
b.len = (ifn.lifn_count + 1) * QSE_SIZEOF(struct lifreq);
b.ptr = QSE_MMGR_ALLOC (mmgr, b.len);
if (b.ptr == QSE_NULL) goto oops;
ifc.lifc_family = f;
ifc.lifc_flags = 0;
ifc.lifc_len = b.len;
ifc.lifc_buf = b.ptr;
if (ioctl (s, SIOCGLIFCONF, &ifc) <= -1) goto oops;
ifcount = ifc.lifc_len / QSE_SIZEOF(struct lifreq);
}
while (ifcount > ifn.lifn_count);
/* the while condition above is for checking if
* the buffer got full. when it's full, there is a chance
* that there are more interfaces. */
nwifs->ptr = b.ptr;
nwifs->len = ifcount;
return 0;
oops:
if (b.ptr) QSE_MMGR_FREE (mmgr, b.ptr);
return -1;
}
#endif
#if 0
static void free_nwifcfg (qse_mmgr_t* mmgr, qse_nwifcfg_node_t* cfg)
{
qse_nwifcfg_node_t* cur;
while (cfg)
{
cur = cfg;
cfg = cur->next;
if (cur->name) QSE_MMGR_FREE (mmgr, cur->name);
QSE_MMGR_FREE (mmgr, cur);
}
}
int qse_getnwifcfg (qse_nwifcfg_t* cfg)
{
#if defined(SIOCGLIFCONF)
struct lifreq* ifr, ifrbuf;
qse_size_t i;
int s, f;
int s4 = -1;
int s6 = -1;
qse_xptl_t nwifs = { QSE_NULL, 0 };
qse_nwifcfg_node_t* head = QSE_NULL;
qse_nwifcfg_node_t* tmp;
QSE_ASSERT (cfg->mmgr != QSE_NULL);
#if defined(AF_INET) || defined(AF_INET6)
#if defined(AF_INET)
s4 = socket (AF_INET, SOCK_DGRAM, 0);
if (s4 <= -1) goto oops;
#endif
#if defined(AF_INET6)
s6 = socket (AF_INET6, SOCK_DGRAM, 0);
if (s6 <= -1) goto oops;
#endif
#else
/* no implementation */
goto oops;
#endif
if (get_nwifs (cfg->mmgr, s4, AF_UNSPEC, &nwifs) <= -1) goto oops;
ifr = nwifs.ptr;
for (i = 0; i < nwifs.len; i++, ifr++)
{
f = ifr->lifr_addr.ss_family;
if (f == AF_INET) s = s4;
else if (f == AF_INET6) s = s6;
else continue;
tmp = QSE_MMGR_ALLOC (cfg->mmgr, QSE_SIZEOF(*tmp));
if (tmp == QSE_NULL) goto oops;
QSE_MEMSET (tmp, 0, QSE_SIZEOF(*tmp));
tmp->next = head;
head = tmp;
#if defined(QSE_CHAR_IS_MCHAR)
head->name = qse_mbsdup (ifr->lifr_name, cfg->mmgr);
#else
head->name = qse_mbstowcsdup (ifr->lifr_name, QSE_NULL, cfg->mmgr);
#endif
if (head->name == QSE_NULL) goto oops;
qse_skadtonwad (&ifr->lifr_addr, &head->addr);
qse_mbsxcpy (ifrbuf.lifr_name, QSE_SIZEOF(ifrbuf.lifr_name), ifr->lifr_name);
if (ioctl (s, SIOCGLIFFLAGS, &ifrbuf) <= -1) goto oops;
if (ifrbuf.lifr_flags & IFF_UP) head->flags |= QSE_NWIFCFG_UP;
if (ifrbuf.lifr_flags & IFF_BROADCAST)
{
if (ioctl (s, SIOCGLIFBRDADDR, &ifrbuf) <= -1) goto oops;
qse_skadtonwad (&ifrbuf.lifr_addr, &head->bcast);
head->flags |= QSE_NWIFCFG_BCAST;
}
if (ifrbuf.lifr_flags & IFF_POINTOPOINT)
{
if (ioctl (s, SIOCGLIFDSTADDR, &ifrbuf) <= -1) goto oops;
qse_skadtonwad (&ifrbuf.lifr_addr, &head->ptop);
head->flags |= QSE_NWIFCFG_PTOP;
}
if (ioctl (s, SIOCGLIFINDEX, &ifrbuf) <= -1) goto oops;
head->index = ifrbuf.lifr_index;
if (ioctl (s, SIOCGLIFNETMASK, &ifrbuf) <= -1) goto oops;
qse_skadtonwad (&ifrbuf.lifr_addr, &head->mask);
}
QSE_MMGR_FREE (cfg->mmgr, nwifs.ptr);
close (s6);
close (s4);
cfg->list = head;
return 0;
oops:
if (head) free_nwifcfg (cfg->mmgr, head);
if (nwifs.ptr) QSE_MMGR_FREE (cfg->mmgr, nwifs.ptr);
if (s6 >= 0) close (s6);
if (s4 >= 0) close (s4);
return -1;
#else
/* TODO */
return QSE_NULL;
#endif
}
void qse_freenwifcfg (qse_nwifcfg_t* cfg)
{
free_nwifcfg (cfg->mmgr, cfg->list);
cfg->list = QSE_NULL;
}
#endif
static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
{
#if defined(SIOCGLIFADDR)
struct lifreq ifrbuf;
qse_size_t ml, wl;
QSE_MEMSET (&ifrbuf, 0, QSE_SIZEOF(ifrbuf));
#if defined(QSE_CHAR_IS_MCHAR)
qse_mbsxcpy (ifrbuf.lifr_name, QSE_SIZEOF(ifrbuf.lifr_name), cfg->name);
#else
ml = QSE_COUNTOF(ifrbuf.lifr_name);
if (qse_wcstombs (cfg->name, &wl, ifrbuf.lifr_name, &ml) <= -1) return -1;
#endif
if (ioctl (s, SIOCGLIFINDEX, &ifrbuf) <= -1) return -1;
cfg->index = ifrbuf.lifr_index;
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 (ioctl (s, SIOCGLIFBRDADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_broadaddr, &cfg->bcast);
cfg->flags |= QSE_NWIFCFG_BCAST;
}
if (ifrbuf.lifr_flags & IFF_POINTOPOINT)
{
if (ioctl (s, SIOCGLIFDSTADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.lifr_dstaddr, &cfg->ptop);
cfg->flags |= QSE_NWIFCFG_PTOP;
}
return 0;
#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 (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, 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 (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 (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 (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));
return 0;
#else
/* TODO */
return -1;
#endif
}
int qse_getnwifcfg (qse_nwifcfg_t* cfg)
{
int s = -1;
if (cfg->type == QSE_NWIFCFG_IN4)
{
#if defined(AF_INET)
s = socket (AF_INET, SOCK_DGRAM, 0);
#endif
}
else if (cfg->type == QSE_NWIFCFG_IN6)
{
#if defined(AF_INET6)
s = socket (AF_INET6, SOCK_DGRAM, 0);
#endif
}
if (s <= -1) return -1;
return get_nwifcfg (s, cfg);
}

View File

@ -38,11 +38,65 @@
# if defined(HAVE_NET_IF_H)
# include <net/if.h>
# endif
# if defined(HAVE_SYS_SOCKIO_H)
# include <sys/sockio.h>
# endif
# if !defined(IF_NAMESIZE)
# define IF_NAMESIZE 63
# endif
#endif
#if !defined(SIOCGIFINDEX) && !defined(SIOCGIFNAME) && \
!defined(HAVE_IF_NAMETOINDEX) && !defined(HAVE_IF_INDEXTONAME) && \
defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
static int get_sco_ifconf (struct ifconf* ifc)
{
/* SCO doesn't have have any IFINDEX thing.
* i emultate it using IFCONF */
int h, num;
struct ifreq* ifr;
h = socket (AF_INET, SOCK_DGRAM, 0);
if (h <= -1) return -1;
ifc->ifc_len = 0;
ifc->ifc_buf = QSE_NULL;
#if defined(SIOCGIFANUM)
if (ioctl (h, SIOCGIFANUM, &num) <= -1) goto oops;
#else
if (ioctl (h, SIOCGIFNUM, &num) <= -1) goto oops;
#endif
/* sco needs reboot when you add an network interface.
* it should be safe not to consider the case when the interface
* is added after SIOCGIFANUM above.
* another thing to note is that SIOCGIFCONF ends with segfault
* if the buffer is not large enough unlike some other OSes
* like opensolaris which truncates the configuration. */
ifc->ifc_len = num * QSE_SIZEOF(*ifr);
ifc->ifc_buf = QSE_MMGR_ALLOC (QSE_MMGR_GETDFL(), ifc->ifc_len);
if (ifc->ifc_buf == QSE_NULL) goto oops;
if (ioctl (h, SIOCGIFCONF, ifc) <= -1) goto oops;
QSE_CLOSE (h); h = -1;
return 0;
oops:
if (ifc->ifc_buf) QSE_MMGR_FREE (QSE_MMGR_GETDFL(), ifc->ifc_buf);
if (h >= 0) QSE_CLOSE (h);
return -1;
}
static QSE_INLINE void free_sco_ifconf (struct ifconf* ifc)
{
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), ifc->ifc_buf);
}
#endif
unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
{
#if defined(_WIN32)
@ -70,7 +124,11 @@ unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
#endif
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
@ -80,6 +138,26 @@ unsigned int qse_nwifmbstoindex (const qse_mchar_t* ptr)
if (ptr[len] != QSE_MT('\0')) return 0u; /* name too long */
return if_nametoindex (tmp);
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
int num, i;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (qse_mbscmp (ptr, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
}
}
free_sco_ifconf (&ifc);
return 0u;
#else
return 0u;
#endif
@ -110,13 +188,37 @@ unsigned int qse_nwifmbsntoindex (const qse_mchar_t* ptr, qse_size_t len)
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
#endif
#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);
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
int num, i;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (qse_mbsxcmp (ptr, len, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
}
}
free_sco_ifconf (&ifc);
return 0u;
#else
return 0u;
#endif
@ -143,22 +245,51 @@ unsigned int qse_nwifwcstoindex (const qse_wchar_t* ptr)
if (h <= -1) return 0u;
ml = QSE_COUNTOF(ifr.ifr_name);
if (qse_wcstombs (ptr, &wl, ifr.ifr_name, &ml) <= -1) return 0;
if (qse_wcstombs (ptr, &wl, ifr.ifr_name, &ml) <= -1) return 0u;
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
#endif
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
ml = QSE_COUNTOF(tmp);
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return 0;
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return 0u;
return if_nametoindex (tmp);
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
int num, i;
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
ml = QSE_COUNTOF(tmp);
if (qse_wcstombs (ptr, &wl, tmp, &ml) <= -1) return 0u;
if (get_sco_ifconf (&ifc) <= -1) return 0u;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (qse_mbscmp (tmp, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
}
}
free_sco_ifconf (&ifc);
return 0u;
#else
return 0u;
#endif
@ -191,33 +322,63 @@ unsigned int qse_nwifwcsntoindex (const qse_wchar_t* ptr, qse_size_t len)
x = ioctl (h, SIOCGIFINDEX, &ifr);
QSE_CLOSE (h);
#if defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
return (x <= -1)? 0u: ifr.ifr_ifindex;
#else
return (x <= -1)? 0u: ifr.ifr_index;
#endif
#elif defined(HAVE_IF_NAMETOINDEX)
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
wl = len; ml = QSE_COUNTOF(tmp) - 1;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return 0;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return 0u;
tmp[ml] = QSE_MT('\0');
return if_nametoindex (tmp);
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
int num, i;
qse_mchar_t tmp[IF_NAMESIZE + 1];
qse_size_t wl, ml;
wl = len; ml = QSE_COUNTOF(tmp) - 1;
if (qse_wcsntombsn (ptr, &wl, tmp, &ml) <= -1) return 0u;
tmp[ml] = QSE_MT('\0');
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (qse_mbscmp (tmp, ifc.ifc_req[i].ifr_name) == 0)
{
free_sco_ifconf (&ifc);
return i + 1;
}
}
free_sco_ifconf (&ifc);
return 0u;
#else
return 0u;
#endif
}
qse_size_t qse_nwifindextombs (unsigned int index, qse_mchar_t* buf, qse_size_t len)
/* ---------------------------------------------------------- */
int qse_nwifindextombs (unsigned int index, qse_mchar_t* buf, qse_size_t len)
{
#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(SIOCGIFNAME)
@ -225,36 +386,61 @@ qse_size_t qse_nwifindextombs (unsigned int index, qse_mchar_t* buf, qse_size_t
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 defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
ifr.ifr_ifindex = index;
#else
ifr.ifr_index = index;
#endif
x = ioctl (h, SIOCGIFNAME, &ifr);
QSE_CLOSE (h);
return (x <= -1)? 0: qse_mbsxcpy (buf, len, ifr.ifr_name);
return (x <= -1)? -1: qse_mbsxcpy (buf, len, ifr.ifr_name);
#elif defined(HAVE_IF_INDEXTONAME)
qse_mchar_t tmp[IF_NAMESIZE + 1];
if (if_indextoname (index, tmp) == QSE_NULL) return 0;
if (if_indextoname (index, tmp) == QSE_NULL) return -1;
return qse_mbsxcpy (buf, len, tmp);
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
qse_size_t ml;
int num;
if (index <= 0) return -1;
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
if (index > num)
{
free_sco_ifconf (&ifc);
return -1;
}
ml = qse_mbsxcpy (buf, len, ifc.ifc_req[index - 1].ifr_name);
free_sco_ifconf (&ifc);
return ml;
#else
return 0;
return -1;
#endif
}
qse_size_t qse_nwifindextowcs (unsigned int index, qse_wchar_t* buf, qse_size_t len)
int qse_nwifindextowcs (unsigned int index, qse_wchar_t* buf, qse_size_t len)
{
#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(SIOCGIFNAME)
@ -263,20 +449,24 @@ qse_size_t qse_nwifindextowcs (unsigned int index, qse_wchar_t* buf, qse_size_t
qse_size_t wl, ml;
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 defined(HAVE_STRUCT_IFREQ_IFR_IFINDEX)
ifr.ifr_ifindex = index;
#else
ifr.ifr_index = index;
#endif
x = ioctl (h, SIOCGIFNAME, &ifr);
QSE_CLOSE (h);
if (x <= -1) return 0;
if (x <= -1) return -1;
wl = len;
x = qse_mbstowcs (ifr.ifr_name, &ml, buf, &wl);
if (x == -2 && wl > 1) buf[wl - 1] = QSE_WT('\0');
else if (x != 0) return 0;
else if (x != 0) return -1;
return wl;
#elif defined(HAVE_IF_INDEXTONAME)
@ -284,13 +474,38 @@ qse_size_t qse_nwifindextowcs (unsigned int index, qse_wchar_t* buf, qse_size_t
qse_size_t ml, wl;
int x;
if (if_indextoname (index, tmp) == QSE_NULL) return 0;
if (if_indextoname (index, tmp) == QSE_NULL) return -1;
wl = len;
x = qse_mbstowcs (tmp, &ml, buf, &wl);
if (x == -2 && wl > 1) buf[wl - 1] = QSE_WT('\0');
else if (x != 0) return 0;
else if (x != 0) return -1;
return wl;
#elif defined(SIOCGIFCONF) && (defined(SIOCGIFANUM) || defined(SIOCGIFNUM))
struct ifconf ifc;
qse_size_t wl, ml;
int num, x;
if (index <= 0) return -1;
if (get_sco_ifconf (&ifc) <= -1) return -1;
num = ifc.ifc_len / QSE_SIZEOF(struct ifreq);
if (index > num)
{
free_sco_ifconf (&ifc);
return -1;
}
wl = len;
x = qse_mbstowcs (ifc.ifc_req[index - 1].ifr_name, &ml, buf, &wl);
free_sco_ifconf (&ifc);
if (x == -2 && wl > 1) buf[wl - 1] = QSE_WT('\0');
else if (x != 0) return -1;
return wl;
#else
return 0;
return -1;
#endif
}

View File

@ -55,63 +55,8 @@ static qse_ssize_t socket_output (
static qse_ssize_t socket_input (
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
#if defined(AF_INET)
union sockaddr_t
{
struct sockaddr_in in4;
#if defined(AF_INET6) && !defined(__OS2__)
struct sockaddr_in6 in6;
#endif
};
#endif
#define TMOUT_ENABLED(tmout) (tmout.sec >= 0 && tmout.nsec >= 0)
static int nwad_to_sockaddr (const qse_nwad_t* nwad, int* family, void* addr)
{
int addrsize = -1;
switch (nwad->type)
{
case QSE_NWAD_IN4:
{
#if defined(AF_INET)
struct sockaddr_in* in;
in = (struct sockaddr_in*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
*family = AF_INET;
in->sin_family = AF_INET;
in->sin_addr.s_addr = nwad->u.in4.addr.value;
in->sin_port = nwad->u.in4.port;
#endif
break;
}
case QSE_NWAD_IN6:
{
#if defined(AF_INET6) && !defined(__OS2__)
struct sockaddr_in6* in;
in = (struct sockaddr_in6*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
*family = AF_INET6;
in->sin6_family = AF_INET6;
memcpy (&in->sin6_addr, &nwad->u.in6.addr, QSE_SIZEOF(nwad->u.in6.addr));
in->sin6_scope_id = nwad->u.in6.scope;
in->sin6_port = nwad->u.in6.port;
#endif
break;
}
}
return addrsize;
}
#if defined(_WIN32)
static qse_nwio_errnum_t syserr_to_errnum (DWORD e)
{
@ -361,16 +306,13 @@ int qse_nwio_init (
qse_nwio_t* nwio, qse_mmgr_t* mmgr, const qse_nwad_t* nwad,
int flags, const qse_nwio_tmout_t* tmout)
{
#if defined(AF_INET)
union sockaddr_t addr;
#endif
qse_skad_t addr;
#if defined(HAVE_SOCKLEN_T)
socklen_t addrlen;
#else
int addrlen;
#endif
int family, type;
int tmp;
int family, type, tmp;
QSE_MEMSET (nwio, 0, QSE_SIZEOF(*nwio));
nwio->mmgr = mmgr;
@ -385,8 +327,7 @@ int qse_nwio_init (
nwio->tmout.a.sec = -1;
}
#if defined(AF_INET)
tmp = nwad_to_sockaddr (nwad, &family, &addr);
tmp = qse_nwadtoskad (nwad, &addr);
if (tmp <= -1)
{
nwio->errnum = QSE_NWIO_EINVAL;
@ -394,6 +335,8 @@ int qse_nwio_init (
}
addrlen = tmp;
#if defined(SOCK_STREAM) && defined(SOCK_DGRAM)
if (flags & QSE_NWIO_TCP) type = SOCK_STREAM;
else if (flags & QSE_NWIO_UDP) type = SOCK_DGRAM;
else
@ -403,6 +346,8 @@ int qse_nwio_init (
return -1;
}
family = qse_skadfamily (&addr);
#if defined(_WIN32)
nwio->handle = socket (family, type, 0);
if (nwio->handle == INVALID_SOCKET)
@ -703,10 +648,12 @@ int qse_nwio_init (
}
else
{
int orgfl, xret;
int xret;
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
int orgfl;
orgfl = fcntl (nwio->handle, F_GETFL, 0);
if (orgfl <= -1 ||
fcntl (nwio->handle, F_SETFL, orgfl | O_NONBLOCK) <= -1)
@ -714,12 +661,9 @@ int qse_nwio_init (
nwio->errnum = syserr_to_errnum (errno);
goto oops;
}
}
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (TMOUT_ENABLED(nwio->tmout.c) && (flags & QSE_NWIO_TCP))
{
if ((xret <= -1 && errno != EINPROGRESS) ||
fcntl (nwio->handle, F_SETFL, orgfl) <= -1)
{
@ -750,6 +694,7 @@ int qse_nwio_init (
}
else
{
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (xret <= -1)
{
nwio->errnum = syserr_to_errnum (errno);
@ -907,7 +852,7 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
if (nwio->status & STATUS_UDP_CONNECT)
{
union sockaddr_t addr;
qse_skad_t addr;
int addrlen;
addrlen = QSE_SIZEOF(addr);
@ -951,7 +896,7 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
if (nwio->status & STATUS_UDP_CONNECT)
{
union sockaddr_t addr;
qse_skad_t addr;
int addrlen;
addrlen = QSE_SIZEOF(addr);
@ -1002,7 +947,7 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
reread:
if (nwio->status & STATUS_UDP_CONNECT)
{
union sockaddr_t addr;
qse_skad_t addr;
#if defined(HAVE_SOCKLEN_T)
socklen_t addrlen;
#else

View File

@ -436,107 +436,13 @@ void* qse_httpd_getxtnstd (qse_httpd_t* httpd)
/* ------------------------------------------------------------------- */
union sockaddr_t
{
struct sockaddr_in in4;
#if defined(AF_INET6)
struct sockaddr_in6 in6;
#endif
};
typedef union sockaddr_t sockaddr_t;
#define SOCKADDR_FAMILY(x) (((struct sockaddr_in*)(x))->sin_family)
static int sockaddr_to_nwad (const sockaddr_t* addr, qse_nwad_t* nwad)
{
int addrsize = -1;
switch (SOCKADDR_FAMILY(addr))
{
case AF_INET:
{
struct sockaddr_in* in;
in = (struct sockaddr_in*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (nwad, 0, QSE_SIZEOF(*nwad));
nwad->type = QSE_NWAD_IN4;
nwad->u.in4.addr.value = in->sin_addr.s_addr;
nwad->u.in4.port = in->sin_port;
break;
}
#if defined(AF_INET6)
case AF_INET6:
{
struct sockaddr_in6* in;
in = (struct sockaddr_in6*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (nwad, 0, QSE_SIZEOF(*nwad));
nwad->type = QSE_NWAD_IN6;
QSE_MEMCPY (&nwad->u.in6.addr, &in->sin6_addr, QSE_SIZEOF(nwad->u.in6.addr));
nwad->u.in6.scope = in->sin6_scope_id;
nwad->u.in6.port = in->sin6_port;
break;
}
#endif
}
return addrsize;
}
static int nwad_to_sockaddr (const qse_nwad_t* nwad, sockaddr_t* addr)
{
int addrsize = -1;
switch (nwad->type)
{
case QSE_NWAD_IN4:
{
struct sockaddr_in* in;
in = (struct sockaddr_in*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
in->sin_family = AF_INET;
in->sin_addr.s_addr = nwad->u.in4.addr.value;
in->sin_port = nwad->u.in4.port;
break;
}
case QSE_NWAD_IN6:
{
#if defined(AF_INET6)
struct sockaddr_in6* in;
in = (struct sockaddr_in6*)addr;
addrsize = QSE_SIZEOF(*in);
QSE_MEMSET (in, 0, addrsize);
in->sin6_family = AF_INET6;
QSE_MEMCPY (&in->sin6_addr, &nwad->u.in6.addr, QSE_SIZEOF(nwad->u.in6.addr));
in->sin6_scope_id = nwad->u.in6.scope;
in->sin6_port = nwad->u.in6.port;
#endif
break;
}
}
return addrsize;
}
/* ------------------------------------------------------------------- */
static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
int fd = -1, flag;
sockaddr_t addr;
qse_skad_t addr;
int addrsize;
addrsize = nwad_to_sockaddr (&server->nwad, &addr);
addrsize = qse_nwadtoskad (&server->nwad, &addr);
if (addrsize <= -1)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
@ -667,7 +573,7 @@ static void server_close (qse_httpd_t* httpd, qse_httpd_server_t* server)
static int server_accept (
qse_httpd_t* httpd, qse_httpd_server_t* server, qse_httpd_client_t* client)
{
sockaddr_t addr;
qse_skad_t addr;
#if defined(HAVE_SOCKLEN_T)
socklen_t addrlen;
@ -704,7 +610,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: too many client?\n"));
if (flag >= 0) fcntl (fd, F_SETFL, flag | O_NONBLOCK);
#endif
if (sockaddr_to_nwad (&addr, &client->remote_addr) <= -1)
if (qse_skadtonwad (&addr, &client->remote_addr) <= -1)
{
/* TODO: logging */
client->remote_addr = server->nwad;
@ -712,7 +618,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: too many client?\n"));
addrlen = QSE_SIZEOF(addr);
if (getsockname (fd, (struct sockaddr*)&addr, &addrlen) <= -1 ||
sockaddr_to_nwad (&addr, &client->local_addr) <= -1)
qse_skadtonwad (&addr, &client->local_addr) <= -1)
{
/* TODO: logging */
client->local_addr = server->nwad;
@ -725,7 +631,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: too many client?\n"));
addrlen = QSE_SIZEOF(addr);
if (getsockopt (fd, SOL_IP, SO_ORIGINAL_DST, (char*)&addr, &addrlen) <= -1 ||
sockaddr_to_nwad (&addr, &client->orgdst_addr) <= -1)
qse_skadtonwad (&addr, &client->orgdst_addr) <= -1)
{
client->orgdst_addr = client->local_addr;
}
@ -751,7 +657,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: too many client?\n"));
static int peer_open (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
{
sockaddr_t connaddr, bindaddr;
qse_skad_t connaddr, bindaddr;
int connaddrsize, bindaddrsize;
int connected = 1;
#if defined(_WIN32)
@ -768,8 +674,8 @@ static int peer_open (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
int flag;
#endif
connaddrsize = nwad_to_sockaddr (&peer->nwad, &connaddr);
bindaddrsize = nwad_to_sockaddr (&peer->local, &bindaddr);
connaddrsize = qse_nwadtoskad (&peer->nwad, &connaddr);
bindaddrsize = qse_nwadtoskad (&peer->local, &bindaddr);
if (connaddrsize <= -1 || bindaddrsize <= -1)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
@ -1239,15 +1145,12 @@ static void file_close (qse_httpd_t* httpd, qse_ubi_t handle)
#if defined(_WIN32)
/* TODO: */
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return -1;
#elif defined(__OS2__)
/* TODO: */
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return -1;
#elif defined(__DOS__)
/* TODO: */
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
return -1;
#else
qse_printf (QSE_T("closing file %d\n"), handle.i);
QSE_CLOSE (handle.i);
@ -1386,7 +1289,15 @@ static int dir_read (qse_httpd_t* httpd, qse_ubi_t handle, qse_httpd_dirent_t* d
static void client_close (
qse_httpd_t* httpd, qse_httpd_client_t* client)
{
#if defined(_WIN32)
/* TODO: */
#elif defined(__OS2__)
/* TODO: */
#elif defined(__DOS__)
/* TODO: */
#else
QSE_CLOSE (client->handle.i);
#endif
}
static void client_shutdown (
@ -2075,7 +1986,6 @@ auth_ok:
#if defined(_WIN32)
/* TODO */
#elif defined(__OS2__)
/* TODO */
#elif defined(__DOS__)
@ -2099,7 +2009,16 @@ auth_ok:
return -1;
}
#if defined(_WIN32)
/* TODO */
#elif defined(__OS2__)
/* TODO */
#elif defined(__DOS__)
/* TODO */
#else
if (QSE_STAT (tpath, &st) == 0 && S_ISREG(st.st_mode))
#endif
{
/* the index file is found */
QSE_MMGR_FREE (httpd->mmgr, xpath);

View File

@ -384,7 +384,7 @@ static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
Sleep ((DWORD)QSE_SEC_TO_MSEC(lv));
rx = 0;
#elif defined(__OS2__)
DosSleep ((ULONG)(QSE_SEC_TO_MSEC(lv));
DosSleep ((ULONG)QSE_SEC_TO_MSEC(lv));
rx = 0;
#elif defined(__DOS__)
rx = sleep (lv);

View File

@ -25,6 +25,8 @@ bin_PROGRAMS = \
mbwc01 \
mbwc02 \
nwad01 \
nwif01 \
nwif02 \
oht \
path01 \
pio \

View File

@ -38,11 +38,12 @@ bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \
fio02$(EXEEXT) fma$(EXEEXT) fmt01$(EXEEXT) fmt02$(EXEEXT) \
fs01$(EXEEXT) htb$(EXEEXT) glob01$(EXEEXT) ipad01$(EXEEXT) \
lda$(EXEEXT) main01$(EXEEXT) main02$(EXEEXT) mbwc01$(EXEEXT) \
mbwc02$(EXEEXT) nwad01$(EXEEXT) oht$(EXEEXT) path01$(EXEEXT) \
pio$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) rbt$(EXEEXT) \
sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) \
slmb01$(EXEEXT) str01$(EXEEXT) task01$(EXEEXT) time$(EXEEXT) \
tre01$(EXEEXT) uri01$(EXEEXT) xma$(EXEEXT)
mbwc02$(EXEEXT) nwad01$(EXEEXT) nwif01$(EXEEXT) \
nwif02$(EXEEXT) oht$(EXEEXT) path01$(EXEEXT) pio$(EXEEXT) \
pma$(EXEEXT) rex01$(EXEEXT) rbt$(EXEEXT) sio01$(EXEEXT) \
sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) slmb01$(EXEEXT) \
str01$(EXEEXT) task01$(EXEEXT) time$(EXEEXT) tre01$(EXEEXT) \
uri01$(EXEEXT) xma$(EXEEXT)
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
subdir = samples/cmn
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@ -135,6 +136,14 @@ am_nwad01_OBJECTS = nwad01.$(OBJEXT)
nwad01_OBJECTS = $(am_nwad01_OBJECTS)
nwad01_LDADD = $(LDADD)
nwad01_DEPENDENCIES = $(am__DEPENDENCIES_2)
nwif01_SOURCES = nwif01.c
nwif01_OBJECTS = nwif01.$(OBJEXT)
nwif01_LDADD = $(LDADD)
nwif01_DEPENDENCIES = $(am__DEPENDENCIES_2)
nwif02_SOURCES = nwif02.c
nwif02_OBJECTS = nwif02.$(OBJEXT)
nwif02_LDADD = $(LDADD)
nwif02_DEPENDENCIES = $(am__DEPENDENCIES_2)
am_oht_OBJECTS = oht.$(OBJEXT)
oht_OBJECTS = $(am_oht_OBJECTS)
oht_LDADD = $(LDADD)
@ -221,23 +230,23 @@ SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(glob01_SOURCES) $(htb_SOURCES) $(ipad01_SOURCES) \
$(lda_SOURCES) $(main01_SOURCES) $(main02_SOURCES) \
$(mbwc01_SOURCES) $(mbwc02_SOURCES) $(nwad01_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) task01.c $(time_SOURCES) \
$(tre01_SOURCES) uri01.c $(xma_SOURCES)
$(mbwc01_SOURCES) $(mbwc02_SOURCES) $(nwad01_SOURCES) nwif01.c \
nwif02.c $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) \
$(pma_SOURCES) $(rbt_SOURCES) $(rex01_SOURCES) \
$(sio01_SOURCES) $(sio02_SOURCES) $(sio03_SOURCES) \
$(sll_SOURCES) $(slmb01_SOURCES) $(str01_SOURCES) task01.c \
$(time_SOURCES) $(tre01_SOURCES) uri01.c $(xma_SOURCES)
DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
$(glob01_SOURCES) $(htb_SOURCES) $(ipad01_SOURCES) \
$(lda_SOURCES) $(main01_SOURCES) $(main02_SOURCES) \
$(mbwc01_SOURCES) $(mbwc02_SOURCES) $(nwad01_SOURCES) \
$(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) $(pma_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) task01.c $(time_SOURCES) \
$(tre01_SOURCES) uri01.c $(xma_SOURCES)
$(mbwc01_SOURCES) $(mbwc02_SOURCES) $(nwad01_SOURCES) nwif01.c \
nwif02.c $(oht_SOURCES) $(path01_SOURCES) $(pio_SOURCES) \
$(pma_SOURCES) $(rbt_SOURCES) $(rex01_SOURCES) \
$(sio01_SOURCES) $(sio02_SOURCES) $(sio03_SOURCES) \
$(sll_SOURCES) $(slmb01_SOURCES) $(str01_SOURCES) task01.c \
$(time_SOURCES) $(tre01_SOURCES) uri01.c $(xma_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -583,6 +592,12 @@ mbwc02$(EXEEXT): $(mbwc02_OBJECTS) $(mbwc02_DEPENDENCIES) $(EXTRA_mbwc02_DEPENDE
nwad01$(EXEEXT): $(nwad01_OBJECTS) $(nwad01_DEPENDENCIES) $(EXTRA_nwad01_DEPENDENCIES)
@rm -f nwad01$(EXEEXT)
$(LINK) $(nwad01_OBJECTS) $(nwad01_LDADD) $(LIBS)
nwif01$(EXEEXT): $(nwif01_OBJECTS) $(nwif01_DEPENDENCIES) $(EXTRA_nwif01_DEPENDENCIES)
@rm -f nwif01$(EXEEXT)
$(LINK) $(nwif01_OBJECTS) $(nwif01_LDADD) $(LIBS)
nwif02$(EXEEXT): $(nwif02_OBJECTS) $(nwif02_DEPENDENCIES) $(EXTRA_nwif02_DEPENDENCIES)
@rm -f nwif02$(EXEEXT)
$(LINK) $(nwif02_OBJECTS) $(nwif02_LDADD) $(LIBS)
oht$(EXEEXT): $(oht_OBJECTS) $(oht_DEPENDENCIES) $(EXTRA_oht_DEPENDENCIES)
@rm -f oht$(EXEEXT)
$(LINK) $(oht_OBJECTS) $(oht_LDADD) $(LIBS)
@ -659,6 +674,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc02.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwad01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwif01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwif02.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oht.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/path01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Po@am__quote@

90
qse/samples/cmn/nwif01.c Normal file
View File

@ -0,0 +1,90 @@
#include <qse/cmn/nwif.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/str.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static void print_nwifcfg (qse_nwifcfg_t* ptr)
{
qse_char_t tmp[128];
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);
}
qse_printf (QSE_T("mtu=[%d] "), (int)ptr->mtu);
qse_printf (QSE_T("\n"));
}
static int test_main (int argc, qse_char_t* argv[])
{
qse_char_t name[100];
unsigned int index;
int i;
for (i = 1; ;i++)
{
if (qse_nwifindextostr (i, name, QSE_COUNTOF(name)) <= -1)
{
qse_printf (QSE_T("ifindex %d failed\n"), i);
break;
}
index = qse_nwifstrtoindex (name);
if (index == 0)
{
qse_printf (QSE_T("ifname %s failed\n"), name);
break;
}
if (i != index)
{
qse_printf (QSE_T("index mismatch %d %d %s\n"), i, index, name);
break;
}
qse_printf (QSE_T("OK %d %s\n"), index, name);
}
qse_printf (QSE_T("================================================\n"));
return 0;
}
int qse_main (int argc, qse_achar_t* argv[])
{
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOutputCP (CP_UTF8);*/
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif
return qse_runmain (argc, argv, test_main);
}

92
qse/samples/cmn/nwif02.c Normal file
View File

@ -0,0 +1,92 @@
#include <qse/cmn/nwif.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/main.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/str.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static void print_nwifcfg (qse_nwifcfg_t* ptr)
{
qse_char_t tmp[128];
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);
}
qse_printf (QSE_T("mtu=[%d] "), (int)ptr->mtu);
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[])
{
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOutputCP (CP_UTF8);*/
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif
return qse_runmain (argc, argv, test_main);
}