Shrink stack use of nl_getifdata().
This commit is contained in:
parent
93b44ed48d
commit
a8a761da14
@ -353,7 +353,7 @@ int main(int argc, char **argv)
|
|||||||
log_line("FATAL - failed to open netlink socket");
|
log_line("FATAL - failed to open netlink socket");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (nl_getifdata(client_config.interface, &cs) < 0) {
|
if (nl_getifdata(&cs) < 0) {
|
||||||
log_line("FATAL - failed to get interface MAC and index");
|
log_line("FATAL - failed to get interface MAC and index");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ static int nl_process_msgs(const struct nlmsghdr *nlh, void *data)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Destroys contents of nlbuf */
|
||||||
void handle_nl_message(struct client_state_t *cs)
|
void handle_nl_message(struct client_state_t *cs)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
@ -137,12 +138,11 @@ void handle_nl_message(struct client_state_t *cs)
|
|||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nl_getifdata(const char *ifname, struct client_state_t *cs)
|
static int nl_sendgetlink(struct client_state_t *cs)
|
||||||
{
|
{
|
||||||
char buf[8192];
|
struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf;
|
||||||
struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof buf);
|
memset(nlbuf, 0, sizeof nlbuf);
|
||||||
nlh->nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg));
|
nlh->nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg));
|
||||||
nlh->nlmsg_type = RTM_GETLINK;
|
nlh->nlmsg_type = RTM_GETLINK;
|
||||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
|
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
|
||||||
@ -151,9 +151,16 @@ int nl_getifdata(const char *ifname, struct client_state_t *cs)
|
|||||||
struct sockaddr_nl addr = {
|
struct sockaddr_nl addr = {
|
||||||
.nl_family = AF_NETLINK,
|
.nl_family = AF_NETLINK,
|
||||||
};
|
};
|
||||||
if (sendto(cs->nlFd, buf, nlh->nlmsg_len, 0, (struct sockaddr *)&addr,
|
if (sendto(cs->nlFd, nlbuf, nlh->nlmsg_len, 0, (struct sockaddr *)&addr,
|
||||||
sizeof addr) == -1)
|
sizeof addr) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nl_getifdata(struct client_state_t *cs)
|
||||||
|
{
|
||||||
|
if (nl_sendgetlink(cs))
|
||||||
|
return -1;
|
||||||
|
|
||||||
for (int pr = 0; !pr;) {
|
for (int pr = 0; !pr;) {
|
||||||
pr = poll(&((struct pollfd){.fd=cs->nlFd,.events=POLLIN}), 1, -1);
|
pr = poll(&((struct pollfd){.fd=cs->nlFd,.events=POLLIN}), 1, -1);
|
||||||
|
@ -43,6 +43,6 @@ enum {
|
|||||||
extern int nlportid;
|
extern int nlportid;
|
||||||
|
|
||||||
void handle_nl_message(struct client_state_t *cs);
|
void handle_nl_message(struct client_state_t *cs);
|
||||||
int nl_getifdata(const char *ifname, struct client_state_t *cs);
|
int nl_getifdata(struct client_state_t *cs);
|
||||||
|
|
||||||
#endif /* NK_NETLINK_H_ */
|
#endif /* NK_NETLINK_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user