Skip to content

Commit 6f80039

Browse files
committed
LocalIP: address Copilot suggestions
1 parent c57e903 commit 6f80039

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/common/netif/netif_bsd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ get_rt_address(struct rt_msghdr *rtm, int desired)
5252

5353
bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
5454
{
55+
if (preferredSourceAddr)
56+
*preferredSourceAddr = 0;
57+
5558
#if defined(__OpenBSD__) || defined(__DragonFly__)
5659
int mib[6] = {CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_FLAGS, RTF_GATEWAY};
5760
size_t needed;

src/common/netif/netif_haiku.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
1515
{
16+
if (preferredSourceAddr)
17+
*preferredSourceAddr = 0;
18+
1619
// TODO: AF_INET6
1720
FF_AUTO_CLOSE_FD int pfRoute = socket(AF_INET, SOCK_RAW, AF_INET);
1821
if (pfRoute < 0)

src/common/netif/netif_linux.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ static bool getDefaultRouteIPv4(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex,
101101

102102
ssize_t received = recvfrom(sock_fd, buffer, (size_t)peek_size, 0,
103103
(struct sockaddr*)&src_addr, &src_addr_len);
104+
if (received != peek_size) {
105+
return false;
106+
}
104107

105108
struct Route4Entry best_gw;
106109
memset(&best_gw, 0, sizeof(best_gw));
@@ -124,7 +127,7 @@ static bool getDefaultRouteIPv4(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex,
124127
entry.prefix_length = rtm->rtm_dst_len;
125128

126129
// Parse route attributes
127-
uint64_t rtm_len = RTM_PAYLOAD(nlh);
130+
size_t rtm_len = RTM_PAYLOAD(nlh);
128131
for (struct rtattr* rta = RTM_RTA(rtm);
129132
RTA_OK(rta, rtm_len);
130133
rta = RTA_NEXT(rta, rtm_len)) {

0 commit comments

Comments
 (0)