Skip to content

Commit d59d394

Browse files
committed
remove residual mentions of mtu for interfaces
1 parent 66734e2 commit d59d394

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

src/enum_net.cpp

+3-29
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ namespace {
284284
#pragma clang diagnostic pop
285285
#endif
286286

287-
if_indextoname(std::uint32_t(if_index), rt_info->name);
288287
ifreq req = {};
289288
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));
290291
ioctl(s, siocgifmtu, &req);
291292
rt_info->mtu = req.ifr_mtu;
292293
// obviously this doesn't work correctly. How do you get the netmask for a route?
@@ -381,7 +382,7 @@ namespace {
381382
int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
382383
#endif
383384

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)
385386
{
386387
sockaddr* rti_info[RTAX_MAX];
387388
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
414415
rt_info->netmask = sockaddr_to_address(rti_info[RTAX_NETMASK]
415416
, rt_info->destination.is_v4() ? AF_INET : AF_INET6);
416417
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-
426418
return true;
427419
}
428420
#endif
@@ -615,15 +607,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
615607
{
616608
ip_interface iface;
617609
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);
625610
ret.push_back(iface);
626-
}
627611
}
628612
}
629613
close(s);
@@ -672,16 +656,6 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
672656
std::strcpy(iface.name, item.ifr_name);
673657

674658
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));
685659
std::strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1);
686660
if (ioctl(s, SIOCGIFNETMASK, &req) < 0)
687661
{

test/enum_if.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ int main()
8181
return 1;
8282
}
8383

84-
std::printf("%-30s%-45s%-20s%-8sflags\n", "address", "netmask", "name", "mtu");
84+
std::printf("%-34s%-45s%-20sflags\n", "address", "netmask", "name");
8585

8686
for (std::vector<ip_interface>::const_iterator i = net.begin()
8787
, end(net.end()); i != end; ++i)
8888
{
89-
std::printf("%-30s%-45s%-20s%s%s%s\n"
89+
std::printf("%-34s%-45s%-20s%s%s%s\n"
9090
, i->interface_address.to_string(ec).c_str()
9191
, i->netmask.to_string(ec).c_str()
9292
, i->name

0 commit comments

Comments
 (0)