summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-24 23:32:49 -0400
committerIan Moffett <ian@osmora.org>2025-09-24 23:32:49 -0400
commit912fe9fd05732d4e7da17f7110fe5e895ac88672 (patch)
tree905cbb758e99941c621e4e0738cd288b1ed99fe3 /src/main.c
parent570dc38023cac588a66118e8beb8dba66a3ec459 (diff)
link: Get MAC address from specified interface
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 62bf519..7372d2f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -63,6 +63,8 @@ data_send(void)
struct ether_hdr *eth;
struct onet_dgram *dgram;
struct ifreq ifr;
+ uint32_t ifidx;
+ mac_addr_t mac;
int error, sockfd;
eth = (struct ether_hdr *)data;
@@ -86,13 +88,24 @@ data_send(void)
return error;
}
+ ifidx = ifr.ifr_ifindex;
+
+ /* Grab the hardware address */
+ error = ioctl(sockfd, SIOCGIFHWADDR, &ifr);
+ if (error < 0) {
+ printf("ioctl[SIOGIFHWADDR]: could not read hwaddr \"%s\"\n", iface);
+ return error;
+ }
+
+ mac = mac_swap((void *)ifr.ifr_hwaddr.sa_data);
+
/*
* Set up link layer sockaddr, load up the frame, datagram
* and send it off.
*/
- saddr.sll_ifindex = ifr.ifr_ifindex;
+ saddr.sll_ifindex = ifidx;
saddr.sll_halen = ETH_ALEN;
- ether_load_route(0x54E1AD2CAE48, 0xFFFFFFFFFFFF, eth);
+ ether_load_route(mac, 0xFFFFFFFFFFFF, eth);
dgram_load(sizeof(TEST_STR), 50, dgram);
sendto(
sockfd, &data, sizeof(data), 0,