* changed the QSE_NWAD_LOCAL address format. it must be prefixed with @.
* fixed conversion error of a QSE_NWAD_LOCAL address to a string
This commit is contained in:
parent
117b1d3618
commit
39ab9d0320
@ -229,6 +229,12 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad)
|
||||
goto oops;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_char_t buf[512];
|
||||
qse_nwadtostr (bindnwad, buf, QSE_COUNTOF(buf), QSE_NWADTOSTR_ALL);
|
||||
qse_printf (QSE_T("binding address: %s\n"), buf);
|
||||
}
|
||||
|
||||
bind_ok:
|
||||
#if defined(IPPROTO_SCTP)
|
||||
|
@ -36,6 +36,8 @@ typedef enum qse_nwad_type_t qse_nwad_type_t;
|
||||
|
||||
typedef struct qse_nwad_t qse_nwad_t;
|
||||
|
||||
#define QSE_NWAD_LOCAL_MAX_PATH 128
|
||||
|
||||
struct qse_nwad_t
|
||||
{
|
||||
qse_nwad_type_t type;
|
||||
@ -61,7 +63,7 @@ struct qse_nwad_t
|
||||
/* note: 128 is chosen based on common path length in existing
|
||||
* systems. most systems have different sizes. some
|
||||
* trailers may get truncated, when itconverted to skad. */
|
||||
qse_char_t path[128];
|
||||
qse_char_t path[QSE_NWAD_LOCAL_MAX_PATH];
|
||||
} local;
|
||||
} u;
|
||||
};
|
||||
|
@ -109,15 +109,15 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad)
|
||||
|
||||
if (p >= end) return -1;
|
||||
|
||||
if (*p == QSE_MT('/'))
|
||||
if (*p == QSE_MT('@') && len >= 2)
|
||||
{
|
||||
/* support the absolute path only */
|
||||
/* the string begins with @. it's a local name */
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_mbsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len);
|
||||
qse_mbsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), p + 1, len - 1);
|
||||
#else
|
||||
qse_size_t mbslen = len;
|
||||
qse_size_t mbslen = len - 1;
|
||||
qse_size_t wcslen = QSE_COUNTOF(tmpad.u.local.path) - 1;
|
||||
if (qse_mbsntowcsn (str, &mbslen, tmpad.u.local.path, &wcslen) <= -1) return -1;
|
||||
if (qse_mbsntowcsn (p + 1, &mbslen, tmpad.u.local.path, &wcslen) <= -1) return -1;
|
||||
tmpad.u.local.path[wcslen] = QSE_WT('\0');
|
||||
#endif
|
||||
|
||||
@ -291,20 +291,19 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad)
|
||||
|
||||
if (p >= end) return -1;
|
||||
|
||||
if (*p == QSE_WT('/'))
|
||||
if (*p == QSE_WT('@') && len >= 2)
|
||||
{
|
||||
/* support the absolute path only */
|
||||
/* the string begins with @. it's a local name */
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_size_t wcslen = len;
|
||||
qse_size_t wcslen = len - 1;
|
||||
qse_size_t mbslen = QSE_COUNTOF(tmpad.u.local.path) - 1;
|
||||
if (qse_wcsntombsn (str, &wcslen, tmpad.u.local.path, &mbslen) <= -1) return -1;
|
||||
if (qse_wcsntombsn (p + 1, &wcslen, tmpad.u.local.path, &mbslen) <= -1) return -1;
|
||||
tmpad.u.local.path[mbslen] = QSE_MT('\0');
|
||||
#else
|
||||
qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len);
|
||||
qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), p + 1, len - 1);
|
||||
#endif
|
||||
|
||||
tmpad.type = QSE_NWAD_LOCAL;
|
||||
qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -558,13 +557,21 @@ qse_size_t qse_nwadtombs (
|
||||
case QSE_NWAD_LOCAL:
|
||||
if (flags & QSE_NWADTOMBS_ADDR)
|
||||
{
|
||||
if (xlen + 1 >= len) goto done;
|
||||
buf[xlen++] = QSE_MT('@');
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
xlen = qse_mbsxcpy (buf, len, nwad->u.local.path)
|
||||
if (xlen + 1 >= len) goto done;
|
||||
xlen += qse_mbsxcpy (&buf[xlen], len - xlen, nwad->u.local.path)
|
||||
#else
|
||||
qse_size_t wcslen, mbslen = len;
|
||||
qse_wcstombs (nwad->u.local.path, &wcslen, buf, &mbslen);
|
||||
/* i don't care about conversion errors */
|
||||
xlen = mbslen;
|
||||
if (xlen + 1 >= len) goto done;
|
||||
else
|
||||
{
|
||||
qse_size_t wcslen, mbslen = len - xlen;
|
||||
qse_wcstombs (nwad->u.local.path, &wcslen, &buf[xlen], &mbslen);
|
||||
/* i don't care about conversion errors */
|
||||
xlen += mbslen;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -679,13 +686,21 @@ qse_size_t qse_nwadtowcs (
|
||||
case QSE_NWAD_LOCAL:
|
||||
if (flags & QSE_NWADTOMBS_ADDR)
|
||||
{
|
||||
if (xlen + 1 >= len) goto done;
|
||||
buf[xlen++] = QSE_WT('@');
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_size_t wcslen = len, mbslen;
|
||||
qse_mbstowcs (nwad->u.local.path, &mbslen, buf, &wcslen);
|
||||
/* i don't care about conversion errors */
|
||||
xlen = wcslen;
|
||||
if (xlen + 1 >= len) goto done;
|
||||
else
|
||||
{
|
||||
qse_size_t wcslen = len - xlen, mbslen;
|
||||
qse_mbstowcs (nwad->u.local.path, &mbslen, &buf[xlen], &wcslen);
|
||||
/* i don't care about conversion errors */
|
||||
xlen += wcslen;
|
||||
}
|
||||
#else
|
||||
xlen = qse_wcsxcpy (buf, len, nwad->u.local.path);
|
||||
if (xlen + 1 >= len) goto done;
|
||||
xlen += qse_wcsxcpy (&buf[xlen], len - xlen, nwad->u.local.path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user