mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-09 06:04:56 +02:00
pknock: pknlusr: remove dest_addr and rename src_addr
We only need to specify the address at our end, and given that we are receiving messages, not sending them, calling it `src_addr` is misleading. Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
This commit is contained in:

committed by
Jan Engelhardt

parent
b052ec0f7d
commit
b05ea5644c
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define GROUP 1
|
#define GROUP 1
|
||||||
|
|
||||||
static struct sockaddr_nl src_addr, dest_addr;
|
static struct sockaddr_nl local_addr;
|
||||||
static int sock_fd;
|
static int sock_fd;
|
||||||
|
|
||||||
static unsigned char *buf;
|
static unsigned char *buf;
|
||||||
@@ -21,7 +21,6 @@ static struct xt_pknock_nl_msg *nlmsg;
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
socklen_t addrlen;
|
|
||||||
int status;
|
int status;
|
||||||
int group = GROUP;
|
int group = GROUP;
|
||||||
|
|
||||||
@@ -37,24 +36,17 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&src_addr, 0, sizeof(src_addr));
|
memset(&local_addr, 0, sizeof(local_addr));
|
||||||
src_addr.nl_family = AF_NETLINK;
|
local_addr.nl_family = AF_NETLINK;
|
||||||
src_addr.nl_pid = getpid();
|
local_addr.nl_pid = getpid();
|
||||||
src_addr.nl_groups = group;
|
local_addr.nl_groups = group;
|
||||||
|
status = bind(sock_fd, (struct sockaddr *)&local_addr, sizeof(local_addr));
|
||||||
status = bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr));
|
|
||||||
|
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
perror("bind()");
|
perror("bind()");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&dest_addr, 0, sizeof(dest_addr));
|
|
||||||
dest_addr.nl_family = AF_NETLINK;
|
|
||||||
dest_addr.nl_pid = 0;
|
|
||||||
dest_addr.nl_groups = group;
|
|
||||||
|
|
||||||
buf_size = sizeof(struct xt_pknock_nl_msg) + sizeof(struct cn_msg) + sizeof(struct nlmsghdr);
|
buf_size = sizeof(struct xt_pknock_nl_msg) + sizeof(struct cn_msg) + sizeof(struct nlmsghdr);
|
||||||
buf = malloc(buf_size);
|
buf = malloc(buf_size);
|
||||||
|
|
||||||
@@ -63,16 +55,12 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addrlen = sizeof(dest_addr);
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
memset(buf, 0, buf_size);
|
memset(buf, 0, buf_size);
|
||||||
|
status = recv(sock_fd, buf, buf_size, 0);
|
||||||
status = recvfrom(sock_fd, buf, buf_size, 0, (struct sockaddr *)&dest_addr, &addrlen);
|
|
||||||
|
|
||||||
if (status <= 0) {
|
if (status <= 0) {
|
||||||
perror("recvfrom()");
|
perror("recv()");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
nlmsg = (struct xt_pknock_nl_msg *)(buf + sizeof(struct cn_msg) + sizeof(struct nlmsghdr));
|
nlmsg = (struct xt_pknock_nl_msg *)(buf + sizeof(struct cn_msg) + sizeof(struct nlmsghdr));
|
||||||
|
Reference in New Issue
Block a user