mmaraya / port-mirroring

OpenWrt package for copying network packets without iptables
BSD 2-Clause "Simplified" License
102 stars 32 forks source link

src/port-mirroring.c:514: warning: comparison between signed and unsigned integer expressions #43

Closed mmaraya closed 8 years ago

mmaraya commented 8 years ago

https://github.com/mmaraya/port-mirroring/blob/8ac5075e976e73dbb88c9a98d6c0d43958864ec2/src/port-mirroring.c#L514

src/port-mirroring.c: In function 'getSenderInterface':
src/port-mirroring.c:514:122: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (; NLMSG_OK(nlMsg, len); nlMsg = NLMSG_NEXT(nlMsg, len)) {
                                                                                                                          ^

NLMSG_OK from netlink expands to:

 87 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
 88                            (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
 89                            (nlh)->nlmsg_len <= (len))
mmaraya commented 8 years ago

The netlink macro NLMSG_OK produces the error by comparing an unsigned uint32_t with a signed ssize_t. Rewrote the NLMSG_OK macro into a function in 70bd14901267f7c2dc3af2ce73d3fcd053d6fb50 and type casted one of the operands.