shortened ETHADDR to ETHAD, and the like

This commit is contained in:
hyung-hwan 2021-07-22 03:23:07 +00:00
parent b2790a4355
commit e3ac950c50
4 changed files with 71 additions and 71 deletions

View File

@ -417,27 +417,27 @@ static int setup_arp_tester (mio_t* mio)
} }
//mio_bcstrtoifindex (mio, "enp0s25.3", &ifindex); //mio_bcstrtoifindex (mio, "enp0s25.3", &ifindex);
//mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethaddr_t*)"\xFF\xFF\xFF\xFF\xFF\xFF"); //mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethad_t*)"\xFF\xFF\xFF\xFF\xFF\xFF");
//mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF"); //mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethad_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
//mio_bcstrtoifindex (mio, "eno1", &ifindex); //mio_bcstrtoifindex (mio, "eno1", &ifindex);
//mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF"); //mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethad_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
mio_bcstrtoifindex (mio, "bce0", &ifindex); mio_bcstrtoifindex (mio, "bce0", &ifindex);
mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF"); mio_skad_init_for_eth (&ethdst, ifindex, (mio_ethad_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
memset (&etharp, 0, MIO_SIZEOF(etharp)); memset (&etharp, 0, MIO_SIZEOF(etharp));
memcpy (etharp.ethhdr.source, "\xB8\x6B\x23\x9C\x10\x76", MIO_ETHADDR_LEN); memcpy (etharp.ethhdr.source, "\xB8\x6B\x23\x9C\x10\x76", MIO_ETHAD_LEN);
//memcpy (etharp.ethhdr.dest, "\xFF\xFF\xFF\xFF\xFF\xFF", MIO_ETHADDR_LEN); //memcpy (etharp.ethhdr.dest, "\xFF\xFF\xFF\xFF\xFF\xFF", MIO_ETHAD_LEN);
memcpy (etharp.ethhdr.dest, "\xAA\xBB\xFF\xCC\xDD\xFF", MIO_ETHADDR_LEN); memcpy (etharp.ethhdr.dest, "\xAA\xBB\xFF\xCC\xDD\xFF", MIO_ETHAD_LEN);
etharp.ethhdr.proto = MIO_CONST_HTON16(MIO_ETHHDR_PROTO_ARP); etharp.ethhdr.proto = MIO_CONST_HTON16(MIO_ETHHDR_PROTO_ARP);
etharp.arphdr.htype = MIO_CONST_HTON16(MIO_ARPHDR_HTYPE_ETH); etharp.arphdr.htype = MIO_CONST_HTON16(MIO_ARPHDR_HTYPE_ETH);
etharp.arphdr.ptype = MIO_CONST_HTON16(MIO_ARPHDR_PTYPE_IP4); etharp.arphdr.ptype = MIO_CONST_HTON16(MIO_ARPHDR_PTYPE_IP4);
etharp.arphdr.hlen = MIO_ETHADDR_LEN; etharp.arphdr.hlen = MIO_ETHAD_LEN;
etharp.arphdr.plen = MIO_IP4ADDR_LEN; etharp.arphdr.plen = MIO_IP4AD_LEN;
etharp.arphdr.opcode = MIO_CONST_HTON16(MIO_ARPHDR_OPCODE_REQUEST); etharp.arphdr.opcode = MIO_CONST_HTON16(MIO_ARPHDR_OPCODE_REQUEST);
memcpy (etharp.arppld.sha, "\xB8\x6B\x23\x9C\x10\x76", MIO_ETHADDR_LEN); memcpy (etharp.arppld.sha, "\xB8\x6B\x23\x9C\x10\x76", MIO_ETHAD_LEN);
if (mio_dev_sck_write(sck, &etharp, MIO_SIZEOF(etharp), MIO_NULL, &ethdst) <= -1) if (mio_dev_sck_write(sck, &etharp, MIO_SIZEOF(etharp), MIO_NULL, &ethdst) <= -1)
//if (mio_dev_sck_write (sck, &etharp.arphdr, MIO_SIZEOF(etharp) - MIO_SIZEOF(etharp.ethhdr), MIO_NULL, &ethaddr) <= -1) //if (mio_dev_sck_write (sck, &etharp.arphdr, MIO_SIZEOF(etharp) - MIO_SIZEOF(etharp.ethhdr), MIO_NULL, &ethaddr) <= -1)

View File

@ -49,8 +49,8 @@
struct MIO_PACKED mio_ethhdr_t struct MIO_PACKED mio_ethhdr_t
{ {
mio_uint8_t dest[MIO_ETHADDR_LEN]; mio_uint8_t dest[MIO_ETHAD_LEN];
mio_uint8_t source[MIO_ETHADDR_LEN]; mio_uint8_t source[MIO_ETHAD_LEN];
mio_uint16_t proto; mio_uint16_t proto;
}; };
typedef struct mio_ethhdr_t mio_ethhdr_t; typedef struct mio_ethhdr_t mio_ethhdr_t;
@ -68,10 +68,10 @@ typedef struct mio_arphdr_t mio_arphdr_t;
/* arp payload for ipv4 over ethernet */ /* arp payload for ipv4 over ethernet */
struct MIO_PACKED mio_etharp_t struct MIO_PACKED mio_etharp_t
{ {
mio_uint8_t sha[MIO_ETHADDR_LEN]; /* source hardware address */ mio_uint8_t sha[MIO_ETHAD_LEN]; /* source hardware address */
mio_uint8_t spa[MIO_IP4ADDR_LEN]; /* source protocol address */ mio_uint8_t spa[MIO_IP4AD_LEN]; /* source protocol address */
mio_uint8_t tha[MIO_ETHADDR_LEN]; /* target hardware address */ mio_uint8_t tha[MIO_ETHAD_LEN]; /* target hardware address */
mio_uint8_t tpa[MIO_IP4ADDR_LEN]; /* target protocol address */ mio_uint8_t tpa[MIO_IP4AD_LEN]; /* target protocol address */
}; };
typedef struct mio_etharp_t mio_etharp_t; typedef struct mio_etharp_t mio_etharp_t;

View File

@ -66,37 +66,37 @@ typedef struct mio_skad_t mio_skad_t;
#define MIO_SKAD_TO_BCSTR_ADDR MIO_SKAD_TO_OOCSTR_ADDR #define MIO_SKAD_TO_BCSTR_ADDR MIO_SKAD_TO_OOCSTR_ADDR
#define MIO_SKAD_TO_BCSTR_PORT MIO_SKAD_TO_OOCSTR_PORT #define MIO_SKAD_TO_BCSTR_PORT MIO_SKAD_TO_OOCSTR_PORT
#define MIO_IP4ADDR_STRLEN (15) /* not including the terminating '\0' */ #define MIO_IP4AD_STRLEN (15) /* not including the terminating '\0' */
#define MIO_IP6ADDR_STRLEN (45) /* not including the terminating '\0'. pure IPv6 address, not including the scope(e.g. %10, %eth0) */ #define MIO_IP6AD_STRLEN (45) /* not including the terminating '\0'. pure IPv6 address, not including the scope(e.g. %10, %eth0) */
/* size large enough to hold the ip address plus port number. /* size large enough to hold the ip address plus port number.
* [IPV6ADDR%SCOPE]:PORT -> 9 for [] % : and PORT * [IPV6ADDR%SCOPE]:PORT -> 9 for [] % : and PORT
* Let's reserve 16 for SCOPE and not include the terminting '\0' * Let's reserve 16 for SCOPE and not include the terminting '\0'
*/ */
#define MIO_SKAD_IP_STRLEN (MIO_IP6ADDR_STRLEN + 25) #define MIO_SKAD_IP_STRLEN (MIO_IP6AD_STRLEN + 25)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
#define MIO_ETHADDR_LEN (6) #define MIO_ETHAD_LEN (6)
#define MIO_IP4ADDR_LEN (4) #define MIO_IP4AD_LEN (4)
#define MIO_IP6ADDR_LEN (16) #define MIO_IP6AD_LEN (16)
#include <mio-pac1.h> #include <mio-pac1.h>
struct MIO_PACKED mio_ethaddr_t struct MIO_PACKED mio_ethad_t
{ {
mio_uint8_t v[MIO_ETHADDR_LEN]; mio_uint8_t v[MIO_ETHAD_LEN];
}; };
typedef struct mio_ethaddr_t mio_ethaddr_t; typedef struct mio_ethad_t mio_ethad_t;
struct MIO_PACKED mio_ip4ad_t struct MIO_PACKED mio_ip4ad_t
{ {
mio_uint8_t v[MIO_IP4ADDR_LEN]; mio_uint8_t v[MIO_IP4AD_LEN];
}; };
typedef struct mio_ip4ad_t mio_ip4ad_t; typedef struct mio_ip4ad_t mio_ip4ad_t;
struct MIO_PACKED mio_ip6ad_t struct MIO_PACKED mio_ip6ad_t
{ {
mio_uint8_t v[MIO_IP6ADDR_LEN]; mio_uint8_t v[MIO_IP6AD_LEN];
}; };
typedef struct mio_ip6ad_t mio_ip6ad_t; typedef struct mio_ip6ad_t mio_ip6ad_t;
#include <mio-upac.h> #include <mio-upac.h>
@ -170,7 +170,7 @@ MIO_EXPORT void mio_skad_init_for_ip_with_bytes (
MIO_EXPORT void mio_skad_init_for_eth ( MIO_EXPORT void mio_skad_init_for_eth (
mio_skad_t* skad, mio_skad_t* skad,
int ifindex, int ifindex,
mio_ethaddr_t* ethaddr mio_ethad_t* ethad
); );
MIO_EXPORT int mio_skad_family ( MIO_EXPORT int mio_skad_family (
@ -199,14 +199,14 @@ MIO_EXPORT int mio_equal_skads (
int strict int strict
); );
MIO_EXPORT mio_oow_t mio_ipaddr_bytes_to_ucstr ( MIO_EXPORT mio_oow_t mio_ipad_bytes_to_ucstr (
const mio_uint8_t* iptr, const mio_uint8_t* iptr,
mio_oow_t ilen, mio_oow_t ilen,
mio_uch_t* buf, mio_uch_t* buf,
mio_oow_t blen mio_oow_t blen
); );
MIO_EXPORT mio_oow_t mio_ipaddr_bytes_to_bcstr ( MIO_EXPORT mio_oow_t mio_ipad_bytes_to_bcstr (
const mio_uint8_t* iptr, const mio_uint8_t* iptr,
mio_oow_t ilen, mio_oow_t ilen,
mio_bch_t* buf, mio_bch_t* buf,
@ -214,14 +214,14 @@ MIO_EXPORT mio_oow_t mio_ipaddr_bytes_to_bcstr (
); );
MIO_EXPORT int mio_uchars_to_ipaddr_bytes ( MIO_EXPORT int mio_uchars_to_ipad_bytes (
const mio_uch_t* str, const mio_uch_t* str,
mio_oow_t slen, mio_oow_t slen,
mio_uint8_t* buf, mio_uint8_t* buf,
mio_oow_t blen mio_oow_t blen
); );
MIO_EXPORT int mio_bchars_to_ipaddr_bytes ( MIO_EXPORT int mio_bchars_to_ipad_bytes (
const mio_bch_t* str, const mio_bch_t* str,
mio_oow_t slen, mio_oow_t slen,
mio_uint8_t* buf, mio_uint8_t* buf,

View File

@ -859,11 +859,11 @@ static mio_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, mio_uch_t* buf, mi
* to use pointer overlays. All the world's not a VAX. * to use pointer overlays. All the world's not a VAX.
*/ */
#define IP6ADDR_NWORDS (MIO_SIZEOF(ipad->s6_addr) / MIO_SIZEOF(mio_uint16_t)) #define IP6AD_NWORDS (MIO_SIZEOF(ipad->s6_addr) / MIO_SIZEOF(mio_uint16_t))
mio_uch_t tmp[MIO_COUNTOF("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp; mio_uch_t tmp[MIO_COUNTOF("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp;
struct { int base, len; } best, cur; struct { int base, len; } best, cur;
mio_uint16_t words[IP6ADDR_NWORDS]; mio_uint16_t words[IP6AD_NWORDS];
int i; int i;
if (size <= 0) return 0; if (size <= 0) return 0;
@ -881,7 +881,7 @@ static mio_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, mio_uch_t* buf, mi
cur.base = -1; cur.base = -1;
cur.len = 0; cur.len = 0;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6AD_NWORDS; i++)
{ {
if (words[i] == 0) if (words[i] == 0)
{ {
@ -914,7 +914,7 @@ static mio_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, mio_uch_t* buf, mi
* Format the result. * Format the result.
*/ */
tp = tmp; tp = tmp;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6AD_NWORDS; i++)
{ {
/* Are we inside the best run of 0x00's? */ /* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base && if (best.base != -1 && i >= best.base &&
@ -940,12 +940,12 @@ static mio_oow_t ip6ad_to_ucstr (const struct in6_addr* ipad, mio_uch_t* buf, mi
} }
/* Was it a trailing run of 0x00's? */ /* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == IP6ADDR_NWORDS) *tp++ = ':'; if (best.base != -1 && (best.base + best.len) == IP6AD_NWORDS) *tp++ = ':';
*tp++ = '\0'; *tp++ = '\0';
return mio_copy_ucstr(buf, size, tmp); return mio_copy_ucstr(buf, size, tmp);
#undef IP6ADDR_NWORDS #undef IP6AD_NWORDS
} }
@ -1105,11 +1105,11 @@ static mio_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, mio_bch_t* buf, mi
* to use pointer overlays. All the world's not a VAX. * to use pointer overlays. All the world's not a VAX.
*/ */
#define IP6ADDR_NWORDS (MIO_SIZEOF(ipad->s6_addr) / MIO_SIZEOF(mio_uint16_t)) #define IP6AD_NWORDS (MIO_SIZEOF(ipad->s6_addr) / MIO_SIZEOF(mio_uint16_t))
mio_bch_t tmp[MIO_COUNTOF("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp; mio_bch_t tmp[MIO_COUNTOF("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp;
struct { int base, len; } best, cur; struct { int base, len; } best, cur;
mio_uint16_t words[IP6ADDR_NWORDS]; mio_uint16_t words[IP6AD_NWORDS];
int i; int i;
if (size <= 0) return 0; if (size <= 0) return 0;
@ -1127,7 +1127,7 @@ static mio_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, mio_bch_t* buf, mi
cur.base = -1; cur.base = -1;
cur.len = 0; cur.len = 0;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6AD_NWORDS; i++)
{ {
if (words[i] == 0) if (words[i] == 0)
{ {
@ -1160,7 +1160,7 @@ static mio_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, mio_bch_t* buf, mi
* Format the result. * Format the result.
*/ */
tp = tmp; tp = tmp;
for (i = 0; i < IP6ADDR_NWORDS; i++) for (i = 0; i < IP6AD_NWORDS; i++)
{ {
/* Are we inside the best run of 0x00's? */ /* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base && if (best.base != -1 && i >= best.base &&
@ -1186,12 +1186,12 @@ static mio_oow_t ip6ad_to_bcstr (const struct in6_addr* ipad, mio_bch_t* buf, mi
} }
/* Was it a trailing run of 0x00's? */ /* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == IP6ADDR_NWORDS) *tp++ = ':'; if (best.base != -1 && (best.base + best.len) == IP6AD_NWORDS) *tp++ = ':';
*tp++ = '\0'; *tp++ = '\0';
return mio_copy_bcstr(buf, size, tmp); return mio_copy_bcstr(buf, size, tmp);
#undef IP6ADDR_NWORDS #undef IP6AD_NWORDS
} }
@ -1378,7 +1378,7 @@ void mio_skad_init_for_ip4 (mio_skad_t* skad, mio_uint16_t port, mio_ip4ad_t* ip
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin)); MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
sin->sin_family = AF_INET; sin->sin_family = AF_INET;
sin->sin_port = mio_hton16(port); sin->sin_port = mio_hton16(port);
if (ip4ad) MIO_MEMCPY (&sin->sin_addr, ip4ad->v, MIO_IP4ADDR_LEN); if (ip4ad) MIO_MEMCPY (&sin->sin_addr, ip4ad->v, MIO_IP4AD_LEN);
#endif #endif
} }
@ -1390,7 +1390,7 @@ void mio_skad_init_for_ip6 (mio_skad_t* skad, mio_uint16_t port, mio_ip6ad_t* ip
sin->sin6_family = AF_INET6; sin->sin6_family = AF_INET6;
sin->sin6_port = mio_hton16(port); sin->sin6_port = mio_hton16(port);
sin->sin6_scope_id = scope_id; sin->sin6_scope_id = scope_id;
if (ip6ad) MIO_MEMCPY (&sin->sin6_addr, ip6ad->v, MIO_IP6ADDR_LEN); if (ip6ad) MIO_MEMCPY (&sin->sin6_addr, ip6ad->v, MIO_IP6AD_LEN);
#endif #endif
} }
@ -1399,7 +1399,7 @@ void mio_skad_init_for_ip_with_bytes (mio_skad_t* skad, mio_uint16_t port, const
switch (len) switch (len)
{ {
#if (MIO_SIZEOF_STRUCT_SOCKADDR_IN > 0) #if (MIO_SIZEOF_STRUCT_SOCKADDR_IN > 0)
case MIO_IP4ADDR_LEN: case MIO_IP4AD_LEN:
{ {
struct sockaddr_in* sin = (struct sockaddr_in*)skad; struct sockaddr_in* sin = (struct sockaddr_in*)skad;
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin)); MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
@ -1410,7 +1410,7 @@ void mio_skad_init_for_ip_with_bytes (mio_skad_t* skad, mio_uint16_t port, const
} }
#endif #endif
#if (MIO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) #if (MIO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
case MIO_IP6ADDR_LEN: case MIO_IP6AD_LEN:
{ {
struct sockaddr_in6* sin = (struct sockaddr_in6*)skad; struct sockaddr_in6* sin = (struct sockaddr_in6*)skad;
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin)); MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
@ -1426,17 +1426,17 @@ void mio_skad_init_for_ip_with_bytes (mio_skad_t* skad, mio_uint16_t port, const
} }
void mio_skad_init_for_eth (mio_skad_t* skad, int ifindex, mio_ethaddr_t* ethaddr) void mio_skad_init_for_eth (mio_skad_t* skad, int ifindex, mio_ethad_t* ethad)
{ {
#if defined(AF_PACKET) && (MIO_SIZEOF_STRUCT_SOCKADDR_LL > 0) #if defined(AF_PACKET) && (MIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
struct sockaddr_ll* sll = (struct sockaddr_ll*)skad; struct sockaddr_ll* sll = (struct sockaddr_ll*)skad;
MIO_MEMSET (sll, 0, MIO_SIZEOF(*sll)); MIO_MEMSET (sll, 0, MIO_SIZEOF(*sll));
sll->sll_family = AF_PACKET; sll->sll_family = AF_PACKET;
sll->sll_ifindex = ifindex; sll->sll_ifindex = ifindex;
if (ethaddr) if (ethad)
{ {
sll->sll_halen = MIO_ETHADDR_LEN; sll->sll_halen = MIO_ETHAD_LEN;
MIO_MEMCPY (sll->sll_addr, ethaddr, MIO_ETHADDR_LEN); MIO_MEMCPY (sll->sll_addr, ethad, MIO_ETHAD_LEN);
} }
#elif defined(AF_LINK) && (MIO_SIZEOF_STRUCT_SOCKADDR_DL > 0) #elif defined(AF_LINK) && (MIO_SIZEOF_STRUCT_SOCKADDR_DL > 0)
@ -1444,10 +1444,10 @@ void mio_skad_init_for_eth (mio_skad_t* skad, int ifindex, mio_ethaddr_t* ethadd
MIO_MEMSET (sll, 0, MIO_SIZEOF(*sll)); MIO_MEMSET (sll, 0, MIO_SIZEOF(*sll));
sll->sdl_family = AF_LINK; sll->sdl_family = AF_LINK;
sll->sdl_index = ifindex; sll->sdl_index = ifindex;
if (ethaddr) if (ethad)
{ {
sll->sdl_alen = MIO_ETHADDR_LEN; sll->sdl_alen = MIO_ETHAD_LEN;
MIO_MEMCPY (sll->sdl_data, ethaddr, MIO_ETHADDR_LEN); MIO_MEMCPY (sll->sdl_data, ethad, MIO_ETHAD_LEN);
} }
#else #else
# error UNSUPPORTED DATALINK SOCKET ADDRESS # error UNSUPPORTED DATALINK SOCKET ADDRESS
@ -1505,18 +1505,18 @@ int mio_equal_skads (const mio_skad_t* addr1, const mio_skad_t* addr2, int stric
} }
} }
mio_oow_t mio_ipaddr_bytes_to_ucstr (const mio_uint8_t* iptr, mio_oow_t ilen, mio_uch_t* buf, mio_oow_t blen) mio_oow_t mio_ipad_bytes_to_ucstr (const mio_uint8_t* iptr, mio_oow_t ilen, mio_uch_t* buf, mio_oow_t blen)
{ {
switch (ilen) switch (ilen)
{ {
case MIO_IP4ADDR_LEN: case MIO_IP4AD_LEN:
{ {
struct in_addr ip4ad; struct in_addr ip4ad;
MIO_MEMCPY (&ip4ad.s_addr, iptr, ilen); MIO_MEMCPY (&ip4ad.s_addr, iptr, ilen);
return ip4ad_to_ucstr(&ip4ad, buf, blen); return ip4ad_to_ucstr(&ip4ad, buf, blen);
} }
case MIO_IP6ADDR_LEN: case MIO_IP6AD_LEN:
{ {
struct in6_addr ip6ad; struct in6_addr ip6ad;
MIO_MEMCPY (&ip6ad.s6_addr, iptr, ilen); MIO_MEMCPY (&ip6ad.s6_addr, iptr, ilen);
@ -1529,18 +1529,18 @@ mio_oow_t mio_ipaddr_bytes_to_ucstr (const mio_uint8_t* iptr, mio_oow_t ilen, mi
} }
} }
mio_oow_t mio_ipaddr_bytes_to_bcstr (const mio_uint8_t* iptr, mio_oow_t ilen, mio_bch_t* buf, mio_oow_t blen) mio_oow_t mio_ipad_bytes_to_bcstr (const mio_uint8_t* iptr, mio_oow_t ilen, mio_bch_t* buf, mio_oow_t blen)
{ {
switch (ilen) switch (ilen)
{ {
case MIO_IP4ADDR_LEN: case MIO_IP4AD_LEN:
{ {
struct in_addr ip4ad; struct in_addr ip4ad;
MIO_MEMCPY (&ip4ad.s_addr, iptr, ilen); MIO_MEMCPY (&ip4ad.s_addr, iptr, ilen);
return ip4ad_to_bcstr(&ip4ad, buf, blen); return ip4ad_to_bcstr(&ip4ad, buf, blen);
} }
case MIO_IP6ADDR_LEN: case MIO_IP6AD_LEN:
{ {
struct in6_addr ip6ad; struct in6_addr ip6ad;
MIO_MEMCPY (&ip6ad.s6_addr, iptr, ilen); MIO_MEMCPY (&ip6ad.s6_addr, iptr, ilen);
@ -1553,43 +1553,43 @@ mio_oow_t mio_ipaddr_bytes_to_bcstr (const mio_uint8_t* iptr, mio_oow_t ilen, mi
} }
} }
int mio_uchars_to_ipaddr_bytes (const mio_uch_t* str, mio_oow_t slen, mio_uint8_t* buf, mio_oow_t blen) int mio_uchars_to_ipad_bytes (const mio_uch_t* str, mio_oow_t slen, mio_uint8_t* buf, mio_oow_t blen)
{ {
if (blen >= MIO_IP6ADDR_LEN) if (blen >= MIO_IP6AD_LEN)
{ {
struct in6_addr i6; struct in6_addr i6;
if (uchars_to_ipv6(str, slen, &i6) <= -1) goto ipv4; if (uchars_to_ipv6(str, slen, &i6) <= -1) goto ipv4;
MIO_MEMCPY (buf, i6.s6_addr, 16); MIO_MEMCPY (buf, i6.s6_addr, 16);
return MIO_IP6ADDR_LEN; return MIO_IP6AD_LEN;
} }
else if (blen >= MIO_IP4ADDR_LEN) else if (blen >= MIO_IP4AD_LEN)
{ {
struct in_addr i4; struct in_addr i4;
ipv4: ipv4:
if (uchars_to_ipv4(str, slen, &i4) <= -1) return -1; if (uchars_to_ipv4(str, slen, &i4) <= -1) return -1;
MIO_MEMCPY (buf, &i4.s_addr, 4); MIO_MEMCPY (buf, &i4.s_addr, 4);
return MIO_IP4ADDR_LEN; return MIO_IP4AD_LEN;
} }
return -1; return -1;
} }
int mio_bchars_to_ipaddr_bytes (const mio_bch_t* str, mio_oow_t slen, mio_uint8_t* buf, mio_oow_t blen) int mio_bchars_to_ipad_bytes (const mio_bch_t* str, mio_oow_t slen, mio_uint8_t* buf, mio_oow_t blen)
{ {
if (blen >= MIO_IP6ADDR_LEN) if (blen >= MIO_IP6AD_LEN)
{ {
struct in6_addr i6; struct in6_addr i6;
if (bchars_to_ipv6(str, slen, &i6) <= -1) goto ipv4; if (bchars_to_ipv6(str, slen, &i6) <= -1) goto ipv4;
MIO_MEMCPY (buf, i6.s6_addr, 16); MIO_MEMCPY (buf, i6.s6_addr, 16);
return MIO_IP6ADDR_LEN; return MIO_IP6AD_LEN;
} }
else if (blen >= MIO_IP4ADDR_LEN) else if (blen >= MIO_IP4AD_LEN)
{ {
struct in_addr i4; struct in_addr i4;
ipv4: ipv4:
if (bchars_to_ipv4(str, slen, &i4) <= -1) return -1; if (bchars_to_ipv4(str, slen, &i4) <= -1) return -1;
MIO_MEMCPY (buf, &i4.s_addr, 4); MIO_MEMCPY (buf, &i4.s_addr, 4);
return MIO_IP4ADDR_LEN; return MIO_IP4AD_LEN;
} }
return -1; return -1;