Commit d56b391d authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Updated ipq interface

parent a1ecc09c
......@@ -48,7 +48,7 @@ static struct ipq_handle *getIPQHandle()
int result;
// Create our ipq socket
h = ipq_create_handle(0, PF_INET, 1048576);
h = ipq_create_handle(0, PF_INET);
if (!h)
{
fprintf(stderr,"Failed to create IPQ handle\n");
......
......@@ -57,8 +57,7 @@ enum {
IPQ_ERR_SUPP,
IPQ_ERR_RECVBUF,
IPQ_ERR_TIMEOUT,
IPQ_ERR_PROTOCOL,
IPQ_ERR_SETSOCKET
IPQ_ERR_PROTOCOL
};
#define IPQ_MAXERR IPQ_ERR_PROTOCOL
......@@ -82,8 +81,7 @@ struct ipq_errmap_t {
{ IPQ_ERR_SUPP, "Operation not supported" },
{ IPQ_ERR_RECVBUF, "Receive buffer size invalid" },
{ IPQ_ERR_TIMEOUT, "Timeout"},
{ IPQ_ERR_PROTOCOL, "Invalid protocol specified" },
{ IPQ_ERR_SETSOCKET, "Failed to set socket options" }
{ IPQ_ERR_PROTOCOL, "Invalid protocol specified" }
};
static int ipq_errno = IPQ_ERR_NONE;
......@@ -125,7 +123,8 @@ static ssize_t ipq_netlink_recvfrom(const struct ipq_handle *h,
unsigned char *buf, size_t len,
int timeout)
{
int addrlen, status;
unsigned int addrlen;
int status;
struct nlmsghdr *nlh;
if (len < sizeof(struct nlmsgerr)) {
......@@ -174,6 +173,10 @@ static ssize_t ipq_netlink_recvfrom(const struct ipq_handle *h,
ipq_errno = IPQ_ERR_RECV;
return -1;
}
if (h->peer.nl_pid != 0) {
ipq_errno = IPQ_ERR_RECV;
return -1;
}
if (status == 0) {
ipq_errno = IPQ_ERR_NLEOF;
return -1;
......@@ -202,7 +205,7 @@ static char *ipq_strerror(int errcode)
/*
* Create and initialise an ipq handle.
*/
struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol, int recv_buf_size)
struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol)
{
int status;
struct ipq_handle *h;
......@@ -224,22 +227,13 @@ struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol, int re
free(h);
return NULL;
}
if (h->fd == -1) {
ipq_errno = IPQ_ERR_SOCKET;
close(h->fd);
free(h);
return NULL;
}
status = setsockopt(h->fd,SOL_SOCKET,SO_RCVBUF,&recv_buf_size,sizeof(int));
if (status == -1) {
ipq_errno = IPQ_ERR_SETSOCKET;
close(h->fd);
free(h);
return NULL;
}
memset(&h->local, 0, sizeof(struct sockaddr_nl));
h->local.nl_family = AF_NETLINK;
h->local.nl_pid = getpid();
......
......@@ -35,7 +35,7 @@
typedef u_int64_t ipq_id_t;
#else
#include <linux/netfilter_ipv4/ip_queue.h>
typedef u_int32_t ipq_id_t;
typedef unsigned long ipq_id_t;
#endif
#ifdef DEBUG_LIBIPQ
......@@ -58,7 +58,7 @@ struct ipq_handle
struct sockaddr_nl peer;
};
struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol, int recv_buf_size);
struct ipq_handle *ipq_create_handle(u_int32_t flags, u_int32_t protocol);
int ipq_destroy_handle(struct ipq_handle *h);
......
Supports Markdown
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