netlink: make netlink_snl(3) c++ friendly.
This commit is contained in:
parent
4d68605f31
commit
629d9219d9
@ -44,6 +44,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netlink/netlink.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define _roundup2(x, y) (((x)+((y)-1))&(~((y)-1)))
|
||||
|
||||
@ -83,7 +84,7 @@ lb_allocz(struct linear_buffer *lb, int len)
|
||||
return (NULL);
|
||||
void *data = (void *)(lb->base + lb->offset);
|
||||
lb->offset += len;
|
||||
return (data);
|
||||
return ((char *)data);
|
||||
}
|
||||
|
||||
static inline void
|
||||
@ -132,10 +133,10 @@ struct snl_hdr_parser {
|
||||
#define SNL_DECLARE_PARSER(_name, _t, _fp, _np) \
|
||||
static const struct snl_hdr_parser _name = { \
|
||||
.hdr_off = sizeof(_t), \
|
||||
.fp = &((_fp)[0]), \
|
||||
.np = &((_np)[0]), \
|
||||
.fp_size = NL_ARRAY_LEN(_fp), \
|
||||
.np_size = NL_ARRAY_LEN(_np), \
|
||||
.fp = &((_fp)[0]), \
|
||||
.np = &((_np)[0]), \
|
||||
}
|
||||
|
||||
#define SNL_DECLARE_ATTR_PARSER(_name, _np) \
|
||||
@ -175,14 +176,14 @@ snl_init(struct snl_state *ss, int netlink_family)
|
||||
}
|
||||
|
||||
ss->bufsize = rcvbuf;
|
||||
ss->buf = malloc(ss->bufsize);
|
||||
ss->buf = (char *)malloc(ss->bufsize);
|
||||
if (ss->buf == NULL) {
|
||||
snl_free(ss);
|
||||
return (false);
|
||||
}
|
||||
|
||||
ss->lb.size = SCRATCH_BUFFER_SIZE;
|
||||
ss->lb.base = calloc(1, ss->lb.size);
|
||||
ss->lb.base = (char *)calloc(1, ss->lb.size);
|
||||
if (ss->lb.base == NULL) {
|
||||
snl_free(ss);
|
||||
return (false);
|
||||
@ -360,7 +361,7 @@ snl_attr_get_uint16(struct snl_state *ss __unused, struct nlattr *nla,
|
||||
const void *arg __unused, void *target)
|
||||
{
|
||||
if (NLA_DATA_LEN(nla) == sizeof(uint16_t)) {
|
||||
*((uint16_t *)target) = *((const uint16_t *)NLA_DATA_CONST(nla));
|
||||
*((uint16_t *)target) = *((const uint16_t *)NL_RTA_DATA_CONST(nla));
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
@ -371,7 +372,7 @@ snl_attr_get_uint32(struct snl_state *ss __unused, struct nlattr *nla,
|
||||
const void *arg __unused, void *target)
|
||||
{
|
||||
if (NLA_DATA_LEN(nla) == sizeof(uint32_t)) {
|
||||
*((uint32_t *)target) = *((const uint32_t *)NLA_DATA_CONST(nla));
|
||||
*((uint32_t *)target) = *((const uint32_t *)NL_RTA_DATA_CONST(nla));
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
@ -396,7 +397,7 @@ snl_attr_get_stringn(struct snl_state *ss, struct nlattr *nla,
|
||||
{
|
||||
int maxlen = NLA_DATA_LEN(nla);
|
||||
|
||||
char *buf = snl_allocz(ss, maxlen + 1);
|
||||
char *buf = (char *)snl_allocz(ss, maxlen + 1);
|
||||
if (buf == NULL)
|
||||
return (false);
|
||||
buf[maxlen] = '\0';
|
||||
@ -416,7 +417,8 @@ snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, v
|
||||
}
|
||||
|
||||
static inline bool
|
||||
snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla, void *target)
|
||||
snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla,
|
||||
const void *arg __unused, void *target)
|
||||
{
|
||||
*((struct nlattr **)target) = nla;
|
||||
return (true);
|
||||
@ -440,4 +442,6 @@ snl_field_get_uint32(struct snl_state *ss __unused, void *src, void *target)
|
||||
*((uint32_t *)target) = *((uint32_t *)src);
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include <netlink/netlink_route.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Simple Netlink Library - NETLINK_ROUTE helpers
|
||||
*/
|
||||
@ -100,7 +102,7 @@ snl_attr_get_ip(struct snl_state *ss, struct nlattr *nla,
|
||||
static inline struct sockaddr *
|
||||
parse_rta_via(struct snl_state *ss, struct rtattr *rta, int *perror)
|
||||
{
|
||||
struct rtvia *via = NL_RTA_DATA(rta);
|
||||
struct rtvia *via = (struct rtvia *)NL_RTA_DATA(rta);
|
||||
|
||||
switch (via->rtvia_family) {
|
||||
case AF_INET:
|
||||
@ -127,4 +129,6 @@ snl_attr_get_ipvia(struct snl_state *ss, struct nlattr *nla,
|
||||
return (false);
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user