added qse_clearnwad()

enhanced qse_getnwifcfg() a bit.
added uci::adddeltapath.
This commit is contained in:
hyung-hwan 2012-11-19 14:32:38 +00:00
parent c65caeed9d
commit 1157af0b8a
5 changed files with 136 additions and 66 deletions

View File

@ -95,6 +95,15 @@ int qse_nwadequal (
const qse_nwad_t* y
);
/**
* The qse_clearnwad() function zeros out the address
* for the address @a type.
*/
void qse_clearnwad (
qse_nwad_t* nwad,
qse_nwad_type_t type
);
int qse_mbstonwad (
const qse_mchar_t* mbs,
qse_nwad_t* nwad

View File

@ -37,8 +37,8 @@ enum qse_nwifcfg_flag_t
enum qse_nwifcfg_type_t
{
QSE_NWIFCFG_IN4,
QSE_NWIFCFG_IN6
QSE_NWIFCFG_IN4 = QSE_NWAD_IN4,
QSE_NWIFCFG_IN6 = QSE_NWAD_IN6
};
typedef enum qse_nwifcfg_type_t qse_nwifcfg_type_t;

View File

@ -46,6 +46,12 @@ int qse_nwadequal (const qse_nwad_t* x, const qse_nwad_t* y)
}
}
void qse_clearnwad (qse_nwad_t* nwad, qse_nwad_type_t type)
{
QSE_MEMSET (nwad, 0, QSE_SIZEOF(*nwad));
nwad->type = type;
}
int qse_mbstonwad (const qse_mchar_t* str, qse_nwad_t* nwad)
{
return qse_mbsntonwad (str, qse_mbslen(str), nwad);

View File

@ -299,26 +299,28 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
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);
qse_clearnwad (&cfg->addr, cfg->type);
qse_clearnwad (&cfg->mask, cfg->type);
qse_clearnwad (&cfg->bcast, cfg->type);
qse_clearnwad (&cfg->ptop, cfg->type);
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
if (ioctl (s, SIOCGLIFNETMASK, &lifrbuf) <= -1) return -1;
qse_skadtonwad (&lifrbuf.lifr_addr, &cfg->mask);
if (ioctl (s, SIOCGLIFADDR, &lifrbuf) >= 0)
qse_skadtonwad (&lifrbuf.lifr_addr, &cfg->addr);
if (cfg->flags & QSE_NWIFCFG_BCAST)
if (ioctl (s, SIOCGLIFNETMASK, &lifrbuf) >= 0)
qse_skadtonwad (&lifrbuf.lifr_addr, &cfg->mask);
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
ioctl (s, SIOCGLIFBRDADDR, &lifrbuf) >= 0)
{
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 ((cfg->flags & QSE_NWIFCFG_PTOP) &&
ioctl (s, SIOCGLIFDSTADDR, &lifrbuf) >= 0)
{
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)
{
@ -385,44 +387,46 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
cfg->mtu = ifrbuf.ifr_metric;
#endif
qse_clearnwad (&cfg->addr, cfg->type);
qse_clearnwad (&cfg->mask, cfg->type);
qse_clearnwad (&cfg->bcast, cfg->type);
qse_clearnwad (&cfg->ptop, cfg->type);
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
if (cfg->type == QSE_NWIFCFG_IN6)
{
if (ioctl (s, SIOCGLIFADDR, &iflrbuf) <= -1) return -1;
qse_skadtonwad (&iflrbuf.addr, &cfg->addr);
if (ioctl (s, SIOCGLIFADDR, &iflrbuf) >= 0)
{
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);
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 (cfg->flags & QSE_NWIFCFG_PTOP)
qse_skadtonwad (&iflrbuf.dstaddr, &cfg->ptop);
}
}
else
{
if (ioctl (s, SIOCGIFADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
if (ioctl (s, SIOCGIFADDR, &ifrbuf) >= 0)
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, SIOCGIFNETMASK, &ifrbuf) >= 0)
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
if (cfg->flags & QSE_NWIFCFG_BCAST)
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
ioctl (s, SIOCGIFBRDADDR, &ifrbuf) >= 0)
{
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 ((cfg->flags & QSE_NWIFCFG_PTOP) &&
ioctl (s, SIOCGIFDSTADDR, &ifrbuf) >= 0)
{
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];
@ -502,27 +506,30 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
cfg->mtu = ifrbuf.ifr_metric;
#endif
if (ioctl (s, SIOCGIFADDR, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
qse_clearnwad (&cfg->addr, cfg->type);
qse_clearnwad (&cfg->mask, cfg->type);
qse_clearnwad (&cfg->bcast, cfg->type);
qse_clearnwad (&cfg->ptop, cfg->type);
QSE_MEMSET (cfg->ethw, 0, QSE_SIZEOF(cfg->ethw));
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) <= -1) return -1;
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
if (ioctl (s, SIOCGIFADDR, &ifrbuf) >= 0)
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->addr);
if (cfg->flags & QSE_NWIFCFG_BCAST)
if (ioctl (s, SIOCGIFNETMASK, &ifrbuf) >= 0)
qse_skadtonwad (&ifrbuf.ifr_addr, &cfg->mask);
if ((cfg->flags & QSE_NWIFCFG_BCAST) &&
ioctl (s, SIOCGIFBRDADDR, &ifrbuf) >= 0)
{
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 ((cfg->flags & QSE_NWIFCFG_PTOP) &&
ioctl (s, SIOCGIFDSTADDR, &ifrbuf) >= 0)
{
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(SIOCGIFHWADDR)
if (ioctl (s, SIOCGIFHWADDR, &ifrbuf) >= 0)
{
@ -546,9 +553,7 @@ static int get_nwifcfg (int s, qse_nwifcfg_t* cfg)
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);
}

View File

@ -411,6 +411,18 @@ static int setsavedir_byid (
return -x;
}
static int adddeltapath_byid (
qse_awk_rtx_t* rtx, uctx_list_t* list, qse_long_t id, qse_mchar_t* path)
{
int x = UCI_ERR_INVAL;
if (id >= 0 && id < list->map.high && list->map.tab[id])
{
x = uci_add_delta_path (list->map.tab[id]->ctx, path);
}
return -x;
}
static int getsection_byid (
qse_awk_rtx_t* rtx, uctx_list_t* list, qse_long_t id,
@ -1147,6 +1159,43 @@ static int fnc_uci_setsavedir (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi
return 0;
}
static int fnc_uci_adddeltapath (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
uctx_list_t* list;
qse_awk_val_t* retv;
qse_long_t id;
int ret;
list = rtx_to_list (rtx, fi);
ret = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
if (ret <= -1) ret = -UCI_ERR_INVAL;
else
{
qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item)
{
ret = adddeltapath_byid (rtx, list, id, item);
qse_awk_rtx_freemem (rtx, item);
}
else ret = -UCI_ERR_MEM;
}
if (ret <= -1)
{
list->errnum = -ret;
ret = -1;
}
retv = qse_awk_rtx_makeintval (rtx, ret);
if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv);
return 0;
}
static int fnc_uci_getoption (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
uctx_list_t* list;
@ -1228,24 +1277,25 @@ struct fnctab_t
static fnctab_t fnctab[] =
{
{ QSE_T("addlist"), { { 2, 2, QSE_NULL }, fnc_uci_addlist, 0 } },
{ QSE_T("addsection"), { { 3, 3, QSE_NULL }, fnc_uci_addsection, 0 } },
{ QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_uci_close, 0 } },
{ QSE_T("commit"), { { 2, 2, QSE_NULL }, fnc_uci_commit, 0 } },
{ QSE_T("delete"), { { 2, 2, QSE_NULL }, fnc_uci_delete, 0 } },
{ QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_uci_errno, 0 } },
{ QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_uci_errstr, 0 } },
{ QSE_T("getoption"), { { 2, 2, QSE_NULL }, fnc_uci_getoption, 0 } },
{ QSE_T("getsection"), { { 2, 2, QSE_NULL }, fnc_uci_getsection, 0 } },
{ QSE_T("load"), { { 2, 2, QSE_NULL }, fnc_uci_load, 0 } },
{ QSE_T("open"), { { 0, 0, QSE_NULL }, fnc_uci_open, 0 } },
{ QSE_T("rename"), { { 2, 2, QSE_NULL }, fnc_uci_rename, 0 } },
{ QSE_T("revert"), { { 2, 2, QSE_NULL }, fnc_uci_revert, 0 } },
{ QSE_T("save"), { { 2, 2, QSE_NULL }, fnc_uci_save, 0 } },
{ QSE_T("set"), { { 2, 2, QSE_NULL }, fnc_uci_set, 0 } },
{ QSE_T("setconfdir"), { { 2, 2, QSE_NULL }, fnc_uci_setconfdir, 0 } },
{ QSE_T("setsavedir"), { { 2, 2, QSE_NULL }, fnc_uci_setsavedir, 0 } },
{ QSE_T("unload"), { { 1, 1, QSE_NULL }, fnc_uci_unload, 0 } }
{ QSE_T("adddeltapath"), { { 2, 2, QSE_NULL }, fnc_uci_adddeltapath, 0 } },
{ QSE_T("addlist"), { { 2, 2, QSE_NULL }, fnc_uci_addlist, 0 } },
{ QSE_T("addsection"), { { 3, 3, QSE_NULL }, fnc_uci_addsection, 0 } },
{ QSE_T("close"), { { 1, 1, QSE_NULL }, fnc_uci_close, 0 } },
{ QSE_T("commit"), { { 2, 2, QSE_NULL }, fnc_uci_commit, 0 } },
{ QSE_T("delete"), { { 2, 2, QSE_NULL }, fnc_uci_delete, 0 } },
{ QSE_T("errno"), { { 0, 0, QSE_NULL }, fnc_uci_errno, 0 } },
{ QSE_T("errstr"), { { 0, 1, QSE_NULL }, fnc_uci_errstr, 0 } },
{ QSE_T("getoption"), { { 2, 2, QSE_NULL }, fnc_uci_getoption, 0 } },
{ QSE_T("getsection"), { { 2, 2, QSE_NULL }, fnc_uci_getsection, 0 } },
{ QSE_T("load"), { { 2, 2, QSE_NULL }, fnc_uci_load, 0 } },
{ QSE_T("open"), { { 0, 0, QSE_NULL }, fnc_uci_open, 0 } },
{ QSE_T("rename"), { { 2, 2, QSE_NULL }, fnc_uci_rename, 0 } },
{ QSE_T("revert"), { { 2, 2, QSE_NULL }, fnc_uci_revert, 0 } },
{ QSE_T("save"), { { 2, 2, QSE_NULL }, fnc_uci_save, 0 } },
{ QSE_T("set"), { { 2, 2, QSE_NULL }, fnc_uci_set, 0 } },
{ QSE_T("setconfdir"), { { 2, 2, QSE_NULL }, fnc_uci_setconfdir, 0 } },
{ QSE_T("setsavedir"), { { 2, 2, QSE_NULL }, fnc_uci_setsavedir, 0 } },
{ QSE_T("unload"), { { 1, 1, QSE_NULL }, fnc_uci_unload, 0 } }
};
/* ------------------------------------------------------------------------ */