Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lldp_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,9 @@ static struct nla_policy ifla_info_policy[IFLA_INFO_MAX + 1] =

int is_macvtap(const char *ifname)
{
int ret, s;
int ret, s, realsize;
struct nlmsghdr *nlh;
void *temp;
struct ifinfomsg *ifinfo;
struct nlattr *tb[IFLA_MAX+1],
*tb2[IFLA_INFO_MAX+1];
Expand All @@ -684,14 +685,12 @@ int is_macvtap(const char *ifname)
return false;
}

nlh = malloc(NLMSG_SIZE);
nlh = calloc(1, NLMSG_SIZE);

if (!nlh) {
goto out;
}

memset(nlh, 0, NLMSG_SIZE);

nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
nlh->nlmsg_type = RTM_GETLINK;
nlh->nlmsg_flags = NLM_F_REQUEST;
Expand All @@ -706,10 +705,23 @@ int is_macvtap(const char *ifname)
goto out_free;
}

memset(nlh, 0, NLMSG_SIZE);
do {
realsize = recv(s, NULL, 0, MSG_DONTWAIT | MSG_PEEK | MSG_TRUNC);
} while ((realsize < 0) && errno == EINTR);

if (realsize < 0) {
goto out_free;
}

temp = realloc(nlh, realsize);
if (!temp) {
goto out_free;
}
memset(temp, 0, realsize);
nlh = temp;

do {
ret = recv(s, (void *) nlh, NLMSG_SIZE, MSG_DONTWAIT);
ret = recv(s, (void *) nlh, realsize, MSG_DONTWAIT);
} while ((ret < 0) && errno == EINTR);

if (nlmsg_parse(nlh, sizeof(struct ifinfomsg),
Expand Down