summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-25 12:47:06 -0400
committerIan Moffett <ian@osmora.org>2025-09-25 12:47:06 -0400
commit25872d593fc4f9d2845ef6f676ce4ec3d55e9aac (patch)
treedb3324f184063ed958cf0f8654539e60fff1231d /src
parent9e9ca9c770a7677936d2b4ea0a6313543e4ee8ee (diff)
dgram: Allow specification of dest hwaddr
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r--src/dgram/dgram_link.c7
-rw-r--r--src/include/dgram.h7
-rw-r--r--src/main.c7
3 files changed, 17 insertions, 4 deletions
diff --git a/src/dgram/dgram_link.c b/src/dgram/dgram_link.c
index 718201b..eec8697 100644
--- a/src/dgram/dgram_link.c
+++ b/src/dgram/dgram_link.c
@@ -38,7 +38,7 @@
#include "dgram.h"
tx_len_t
-dgram_send(struct onet_link *link, void *buf, uint16_t len)
+dgram_send(struct onet_link *link, mac_addr_t dst, void *buf, uint16_t len)
{
struct sockaddr_ll saddr;
struct ether_hdr *eth;
@@ -60,13 +60,16 @@ dgram_send(struct onet_link *link, void *buf, uint16_t len)
memset(data, 0, len);
memcpy(data, buf, len);
+ /* Hardware address needs to be big endian */
+ dst = mac_swap((void *)&dst);
+
/*
* Set up link layer sockaddr, load up the frame, datagram
* and send it off.
*/
saddr.sll_ifindex = link->iface_idx;
saddr.sll_halen = HW_ADDR_LEN;
- ether_load_route(link->hwaddr, 0xFFFFFFFFFFFF, eth);
+ ether_load_route(link->hwaddr, dst, eth);
dgram_load(len, 50, dgram);
sendto(
link->sockfd, p, dgram_len, 0,
diff --git a/src/include/dgram.h b/src/include/dgram.h
index e67eee6..9c87b81 100644
--- a/src/include/dgram.h
+++ b/src/include/dgram.h
@@ -91,12 +91,17 @@ int dgram_load(uint16_t length, uint8_t port, struct onet_dgram *res);
* Send a datagram through ONET
*
* @link: The ONET link to send data over
+ * @dst: Destination address to send to
* @buf: The buffer containing data to send
* @len: Length of buffer to send
*
* Returns the number of bytes transmitted on success, otherwise
* a less than zero value on failure.
*/
-tx_len_t dgram_send(struct onet_link *link, void *buf, uint16_t len);
+tx_len_t dgram_send(
+ struct onet_link *link, mac_addr_t dst,
+ void *buf, uint16_t len
+);
+
#endif /* DGRAM_H */
diff --git a/src/main.c b/src/main.c
index 77a6c5a..5cdcc63 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,7 +68,12 @@ data_send(void)
return error;
}
- dgram_send(&link, TEST_STR, sizeof(TEST_STR));
+ /* Send test packet to FF:FF:FF:FF:FF:FF */
+ dgram_send(
+ &link, 0xFFFFFFFFFFFF,
+ TEST_STR, sizeof(TEST_STR)
+ );
+
onet_close(&link);
return 0;
}