remove dependency on libnfnetlink
fixes #110 still allow to use libnfnetlink by defining USE_LIBNFNETLINK if you really want/need to
This commit is contained in:
parent
e501f5625d
commit
940909890e
|
@ -1,6 +1,6 @@
|
|||
# $Id: Makefile.linux,v 1.86 2014/04/09 07:22:28 nanard Exp $
|
||||
# MiniUPnP project
|
||||
# (c) 2006-2014 Thomas Bernard
|
||||
# (c) 2006-2015 Thomas Bernard
|
||||
# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
# Author : Thomas Bernard
|
||||
# for use with GNU Make
|
||||
|
@ -138,7 +138,7 @@ endif # ($(TEST), 1)
|
|||
endif # ifdef IPTABLESPATH
|
||||
endif # ifdef PCFILE_FOUND
|
||||
|
||||
LDLIBS += -lnfnetlink
|
||||
#LDLIBS += -lnfnetlink
|
||||
|
||||
TEST := $(shell $(PKG_CONFIG) --atleast-version=1.0.2 libnetfilter_conntrack && $(PKG_CONFIG) --atleast-version=1.0.3 libmnl && echo 1)
|
||||
ifeq ($(TEST),1)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: getroute.c,v 1.4 2013/02/06 10:50:04 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2013 Thomas Bernard
|
||||
* (c) 2006-2015 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
|
@ -16,7 +16,12 @@
|
|||
/*#include <linux/in_route.h>*/
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#ifdef USE_LIBNFNETLINK
|
||||
/* define USE_LIBNFNETLINK in order to use libnfnetlink
|
||||
* instead of custom code
|
||||
* see https://github.com/miniupnp/miniupnp/issues/110 */
|
||||
#include <libnfnetlink/libnfnetlink.h>
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
|
||||
#include "../getroute.h"
|
||||
#include "../upnputils.h"
|
||||
|
@ -46,6 +51,9 @@ get_src_for_route_to(const struct sockaddr * dst,
|
|||
};
|
||||
const struct sockaddr_in * dst4;
|
||||
const struct sockaddr_in6 * dst6;
|
||||
#ifndef USE_LIBNFNETLINK
|
||||
struct rtattr * rta;
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
||||
|
@ -66,15 +74,32 @@ get_src_for_route_to(const struct sockaddr * dst,
|
|||
syslog(LOG_DEBUG, "get_src_for_route_to (%s)", dst_str);
|
||||
}
|
||||
/* add address */
|
||||
#ifndef USE_LIBNFNETLINK
|
||||
rta = (struct rtattr *)(((char*)&req) + NLMSG_ALIGN(req.n.nlmsg_len));
|
||||
rta->rta_type = RTA_DST;
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
if(dst->sa_family == AF_INET) {
|
||||
dst4 = (const struct sockaddr_in *)dst;
|
||||
#ifdef USE_LIBNFNETLINK
|
||||
nfnl_addattr_l(&req.n, sizeof(req), RTA_DST, &dst4->sin_addr, 4);
|
||||
#else
|
||||
rta->rta_len = RTA_SPACE(sizeof(dst4->sin_addr));
|
||||
memcpy(RTA_DATA(rta), &dst4->sin_addr, sizeof(dst4->sin_addr));
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
req.r.rtm_dst_len = 32;
|
||||
} else {
|
||||
dst6 = (const struct sockaddr_in6 *)dst;
|
||||
#ifdef USE_LIBNFNETLINK
|
||||
nfnl_addattr_l(&req.n, sizeof(req), RTA_DST, &dst6->sin6_addr, 16);
|
||||
#else
|
||||
rta->rta_len = RTA_SPACE(sizeof(dst6->sin6_addr));
|
||||
memcpy(RTA_DATA(rta), &dst6->sin6_addr, sizeof(dst6->sin6_addr));
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
req.r.rtm_dst_len = 128;
|
||||
}
|
||||
#ifndef USE_LIBNFNETLINK
|
||||
req.n.nlmsg_len += rta->rta_len;
|
||||
#endif /* USE_LIBNFNETLINK */
|
||||
|
||||
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (fd < 0) {
|
||||
|
|
Loading…
Reference in New Issue