mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-06 12:45:13 +02:00
pknlusr: use NLMSG macros and proper types, rather than arithmetic on char pointers
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
This commit is contained in:

committed by
Jan Engelhardt

parent
9cd0b44c81
commit
c3bd1c61d1
@@ -17,8 +17,11 @@ int main(void)
|
|||||||
int status;
|
int status;
|
||||||
int group = GROUP;
|
int group = GROUP;
|
||||||
struct sockaddr_nl local_addr = {.nl_family = AF_NETLINK};
|
struct sockaddr_nl local_addr = {.nl_family = AF_NETLINK};
|
||||||
int sock_fd, buf_size;
|
int sock_fd;
|
||||||
unsigned char *buf;
|
size_t nlmsg_size;
|
||||||
|
struct nlmgrhdr *nlmsg;
|
||||||
|
struct cn_msg *cn_msg;
|
||||||
|
struct xt_pknock_nl_msg *pknock_msg;
|
||||||
|
|
||||||
sock_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
|
sock_fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
|
||||||
|
|
||||||
@@ -35,34 +38,30 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_size = sizeof(struct xt_pknock_nl_msg) + sizeof(struct cn_msg) + sizeof(struct nlmsghdr);
|
nlmsg_size = NLMSG_SPACE(sizeof(*cn_msg) + sizeof(*pknock_msg));
|
||||||
buf = malloc(buf_size);
|
nlmsg = malloc(nlmsg_size);
|
||||||
|
if (!nlmsg) {
|
||||||
if (!buf) {
|
|
||||||
perror("malloc()");
|
perror("malloc()");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
struct xt_pknock_nl_msg *nlmsg;
|
|
||||||
const char *ip;
|
const char *ip;
|
||||||
char ipbuf[48];
|
char ipbuf[48];
|
||||||
|
|
||||||
memset(buf, 0, buf_size);
|
memset(nlmsg, 0, nlmsg_size);
|
||||||
status = recv(sock_fd, buf, buf_size, 0);
|
status = recv(sock_fd, nlmsg, nlmsg_size, 0);
|
||||||
if (status <= 0) {
|
if (status <= 0) {
|
||||||
perror("recv()");
|
perror("recv()");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
nlmsg = (struct xt_pknock_nl_msg *)(buf + sizeof(struct cn_msg) + sizeof(struct nlmsghdr));
|
cn_msg = NLMSG_DATA(nlmsg);
|
||||||
ip = inet_ntop(AF_INET, &nlmsg->peer_ip, ipbuf, sizeof(ipbuf));
|
pknock_msg = (struct xt_pknock_nl_msg *)(cn_msg->data);
|
||||||
printf("rule_name: %s - ip %s\n", nlmsg->rule_name, ip);
|
ip = inet_ntop(AF_INET, &pknock_msg->peer_ip, ipbuf, sizeof(ipbuf));
|
||||||
|
printf("rule_name: %s - ip %s\n", pknock_msg->rule_name, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
|
free(nlmsg);
|
||||||
free(buf);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user