Skip to content

Commit

Permalink
sysdeps/managarm: Implement SIOCGIFBRDADDR/SIOCGIFHWADDR
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed May 27, 2024
1 parent b5b0f3c commit 20a83e7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sysdeps/managarm/generic/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/vt.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>

#include <bits/ensure.h>
Expand Down Expand Up @@ -873,6 +874,34 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {

ifr->ifr_mtu = resp.mtu();

return 0;
});
}else if(request == SIOCGIFBRDADDR) {
return handle_siocgif([](auto req, auto ifr) {
req.set_name(frg::string<MemoryAllocator>{ifr->ifr_name, getSysdepsAllocator()});
}, [](auto resp, auto ifr) {
if(resp.error() != managarm::fs::Errors::SUCCESS)
return EINVAL;

sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr = { htonl(resp.ip4_broadcast_addr()) };
memcpy(&ifr->ifr_broadaddr, &addr, sizeof(addr));

return 0;
});
} else if(request == SIOCGIFHWADDR) {
return handle_siocgif([](auto req, auto ifr) {
req.set_name(frg::string<MemoryAllocator>{ifr->ifr_name, getSysdepsAllocator()});
}, [](auto resp, auto ifr) {
if(resp.error() != managarm::fs::Errors::SUCCESS)
return EINVAL;

sockaddr addr{};
addr.sa_family = ARPHRD_ETHER;
memcpy(addr.sa_data, resp.mac().data(), 6);
memcpy(&ifr->ifr_hwaddr, &addr, sizeof(addr));

return 0;
});
}
Expand Down

0 comments on commit 20a83e7

Please sign in to comment.