@@ -284,9 +284,10 @@ namespace {
284
284
#pragma clang diagnostic pop
285
285
#endif
286
286
287
- if_indextoname (std::uint32_t (if_index), rt_info->name );
288
287
ifreq req = {};
289
288
if_indextoname (std::uint32_t (if_index), req.ifr_name );
289
+ static_assert (sizeof (rt_info->name ) >= sizeof (req.ifr_name ), " ip_route::name is too small" );
290
+ std::memcpy (rt_info->name , req.ifr_name , sizeof (req.ifr_name ));
290
291
ioctl (s, siocgifmtu, &req);
291
292
rt_info->mtu = req.ifr_mtu ;
292
293
// obviously this doesn't work correctly. How do you get the netmask for a route?
@@ -381,7 +382,7 @@ namespace {
381
382
int _System __libsocket_sysctl (int * mib, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
382
383
#endif
383
384
384
- bool parse_route (int s , rt_msghdr* rtm, ip_route* rt_info)
385
+ bool parse_route (int , rt_msghdr* rtm, ip_route* rt_info)
385
386
{
386
387
sockaddr* rti_info[RTAX_MAX];
387
388
sockaddr* sa = reinterpret_cast <sockaddr*>(rtm + 1 );
@@ -414,15 +415,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
414
415
rt_info->netmask = sockaddr_to_address (rti_info[RTAX_NETMASK]
415
416
, rt_info->destination .is_v4 () ? AF_INET : AF_INET6);
416
417
if_indextoname (rtm->rtm_index , rt_info->name );
417
-
418
- // TODO: get the MTU (and other interesting metrics) from the rt_msghdr instead
419
- ifreq req = {};
420
- if_indextoname (rtm->rtm_index , req.ifr_name );
421
-
422
- // ignore errors here. This is best-effort
423
- ioctl (s, siocgifmtu, &req);
424
- rt_info->mtu = req.ifr_mtu ;
425
-
426
418
return true ;
427
419
}
428
420
#endif
@@ -615,15 +607,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
615
607
{
616
608
ip_interface iface;
617
609
if (iface_from_ifaddrs (ifa, iface))
618
- {
619
- ifreq req = {};
620
- // -1 to leave a 0-terminator
621
- std::strncpy (req.ifr_name , iface.name , IF_NAMESIZE - 1 );
622
-
623
- // ignore errors here. This is best-effort
624
- ioctl (s, siocgifmtu, &req);
625
610
ret.push_back (iface);
626
- }
627
611
}
628
612
}
629
613
close (s);
@@ -672,16 +656,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
672
656
std::strcpy (iface.name , item.ifr_name );
673
657
674
658
ifreq req = {};
675
- // -1 to leave a 0-terminator
676
- strncpy (req.ifr_name , item.ifr_name , IF_NAMESIZE - 1 );
677
- if (ioctl (s, siocgifmtu, &req) < 0 )
678
- {
679
- ec = error_code (errno, system_category ());
680
- close (s);
681
- return ret;
682
- }
683
-
684
- std::memset (&req, 0 , sizeof (req));
685
659
std::strncpy (req.ifr_name , item.ifr_name , IF_NAMESIZE - 1 );
686
660
if (ioctl (s, SIOCGIFNETMASK, &req) < 0 )
687
661
{
0 commit comments