[netfilter-cvslog] r4233 - in trunk/libnfnetlink: include/libnfnetlink src

laforge at netfilter.org laforge at netfilter.org
Mon Aug 8 19:05:57 CEST 2005


Author: laforge at netfilter.org
Date: 2005-08-08 19:05:57 +0200 (Mon, 08 Aug 2005)
New Revision: 4233

Modified:
   trunk/libnfnetlink/include/libnfnetlink/libnfnetlink.h
   trunk/libnfnetlink/src/libnfnetlink.c
Log:
- more verbose dump_packet
- add new nfnl_recv() function


Modified: trunk/libnfnetlink/include/libnfnetlink/libnfnetlink.h
===================================================================
--- trunk/libnfnetlink/include/libnfnetlink/libnfnetlink.h	2005-08-08 11:46:12 UTC (rev 4232)
+++ trunk/libnfnetlink/include/libnfnetlink/libnfnetlink.h	2005-08-08 17:05:57 UTC (rev 4233)
@@ -65,6 +65,7 @@
                       void *);
 
 /* receiving */
+extern ssize_t nfnl_recv(const struct nfnl_handle *h, unsigned char *buf, size_t len);
 extern int nfnl_callback_register(struct nfnl_handle *,
 				  u_int8_t type, struct nfnl_callback *cb);
 extern int nfnl_callback_unregister(struct nfnl_handle *, u_int8_t type);

Modified: trunk/libnfnetlink/src/libnfnetlink.c
===================================================================
--- trunk/libnfnetlink/src/libnfnetlink.c	2005-08-08 11:46:12 UTC (rev 4232)
+++ trunk/libnfnetlink/src/libnfnetlink.c	2005-08-08 17:05:57 UTC (rev 4233)
@@ -43,6 +43,7 @@
 	       (nlmsg_data - (void *)nlh));
 	printf("  NFM_NFA(NLMSG_DATA(nlh)) = %p (+%td bytes)\n",
 		nfa, ((void *)nfa - (void *)nlh));
+	printf("  NFM_PAYLOAD(nlh) = %u\n", len);
 	printf("  nlmsg_type = %u, nlmsg_len = %u, nlmsg_seq = %u "
 		"nlmsg_flags = 0x%x\n", nlh->nlmsg_type, nlh->nlmsg_len,
 		nlh->nlmsg_seq, nlh->nlmsg_flags);
@@ -221,6 +222,36 @@
 	return ((void *)nlh + NLMSG_LENGTH(sizeof(struct nfgenmsg)));
 }
 
+ssize_t 
+nfnl_recv(const struct nfnl_handle *h, unsigned char *buf, size_t len)
+{
+	socklen_t addrlen;
+	int status;
+	struct nlmsghdr *nlh;
+	struct sockaddr_nl peer;
+	
+	if (len < sizeof(struct nlmsgerr)
+	    || len < sizeof(struct nlmsghdr))
+		return -1; 
+
+	addrlen = sizeof(h->peer);
+	status = recvfrom(h->fd, buf, len, 0, (struct sockaddr *)&peer,	
+			&addrlen);
+	if (status <= 0)
+		return status;
+
+	if (addrlen != sizeof(peer))
+		return -1;
+
+	if (peer.nl_pid != 0)
+		return -1;
+
+	nlh = (struct nlmsghdr *)buf;
+	if (nlh->nlmsg_flags & MSG_TRUNC || status > len)
+		return -1;
+
+	return status;
+}
 /**
  * nfnl_listen: listen for one or more netlink messages
  *




More information about the netfilter-cvslog mailing list