-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathether.c
More file actions
23 lines (17 loc) · 815 Bytes
/
ether.c
File metadata and controls
23 lines (17 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "ether.h"
void send_eth(struct skb_buff* socket_buffer) {
printf("Sending Ethernet Packet...\n");
int buf_size = sizeof(struct eth_header) + socket_buffer->ip->length;
// int buf_size = sizeof(struct eth_header) + sizeof(struct ip_hdr);
// copy on this format [Ethernet]-[IP]-[Mimir]-[Payload]
uint8_t* buffer = (uint8_t*)malloc(buf_size);
memset(buffer, 0, buf_size);
memcpy(buffer, socket_buffer->eth, sizeof(struct eth_header));
memcpy(buffer + sizeof(struct eth_header), socket_buffer->ip, sizeof(struct ip_hdr));
int rc = sendto(socket_buffer->sock, buffer, buf_size, 0, (const struct sockaddr *)&(socket_buffer->iface->iface_addr), sizeof(struct sockaddr_ll));
if (rc < 0) {
perror("sendto");
exit(EXIT_FAILURE);
}
free(buffer);
}