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:
2012-11-18 15:19:51 +00:00
parent 105c862230
commit a55545b8ae
14 changed files with 692 additions and 283 deletions

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