Commit 2629d35f authored by Marek Vavrusa's avatar Marek Vavrusa

lib/utils: added function for addr family

the field length is platform-dependent
parent eb15446c
......@@ -254,6 +254,7 @@ int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen);
int kr_pkt_recycle(knot_pkt_t *pkt);
const char *kr_inaddr(const struct sockaddr *addr);
int kr_inaddr_family(const struct sockaddr *addr);
int kr_inaddr_len(const struct sockaddr *addr);
int kr_straddr_family(const char *addr);
int kr_straddr_subnet(void *dst, const char *addr);
......@@ -281,6 +282,7 @@ ffi.metatype( sockaddr_t, {
__index = {
len = function(sa) return C.kr_inaddr_len(sa) end,
ip = function (sa) return C.kr_inaddr(sa) end,
family = function (sa) return C.kr_inaddr_family(sa) end,
}
})
......@@ -435,4 +437,4 @@ local kres = {
context = function () return ffi.cast('struct kr_context *', __engine) end,
}
return kres
\ No newline at end of file
return kres
......@@ -239,6 +239,13 @@ const char *kr_inaddr(const struct sockaddr *addr)
}
}
int kr_inaddr_family(const struct sockaddr *addr)
{
if (!addr)
return AF_UNSPEC;
return addr->sa_family;
}
int kr_inaddr_len(const struct sockaddr *addr)
{
if (!addr) {
......
......@@ -111,6 +111,9 @@ int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
/** Address bytes for given family. */
KR_EXPORT KR_PURE
const char *kr_inaddr(const struct sockaddr *addr);
/** Address family. */
KR_EXPORT KR_PURE
int kr_inaddr_family(const struct sockaddr *addr);
/** Address length for given family. */
KR_EXPORT KR_PURE
int kr_inaddr_len(const struct sockaddr *addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment