Kernel: Add support for SIOCGIFNAME ioctl

This commit is contained in:
Bananymous 2024-12-02 01:41:15 +02:00
parent a231f8587e
commit c02de2580d
2 changed files with 13 additions and 0 deletions

View File

@ -95,6 +95,14 @@ namespace Kernel
memcpy(ifreq->ifr_ifru.ifru_hwaddr.sa_data, &mac_address, sizeof(mac_address)); memcpy(ifreq->ifr_ifru.ifru_hwaddr.sa_data, &mac_address, sizeof(mac_address));
return 0; return 0;
} }
case SIOCGIFNAME:
{
auto& ifrn_name = ifreq->ifr_ifrn.ifrn_name;
ASSERT(m_interface->name().size() < sizeof(ifrn_name));
memcpy(ifrn_name, m_interface->name().data(), m_interface->name().size());
ifrn_name[m_interface->name().size()] = '\0';
return 0;
}
default: default:
return BAN::Error::from_errno(EINVAL); return BAN::Error::from_errno(EINVAL);
} }

View File

@ -19,6 +19,10 @@ struct if_nameindex
struct ifreq struct ifreq
{ {
union {
char ifrn_name[IF_NAMESIZE];
} ifr_ifrn;
union { union {
struct sockaddr ifru_addr; struct sockaddr ifru_addr;
struct sockaddr ifru_netmask; struct sockaddr ifru_netmask;
@ -35,6 +39,7 @@ struct ifreq
#define SIOCGIFGWADDR 5 /* Get gateway address */ #define SIOCGIFGWADDR 5 /* Get gateway address */
#define SIOCSIFGWADDR 6 /* Set gateway address */ #define SIOCSIFGWADDR 6 /* Set gateway address */
#define SIOCGIFHWADDR 7 /* Get hardware address */ #define SIOCGIFHWADDR 7 /* Get hardware address */
#define SIOCGIFNAME 8 /* Get interface name */
void if_freenameindex(struct if_nameindex* ptr); void if_freenameindex(struct if_nameindex* ptr);
char* if_indextoname(unsigned ifindex, char* ifname); char* if_indextoname(unsigned ifindex, char* ifname);