summaryrefslogtreecommitdiff
path: root/kernel/network/ethernet.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/network/ethernet.c')
-rw-r--r--kernel/network/ethernet.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/kernel/network/ethernet.c b/kernel/network/ethernet.c
index e97ccbd..5cf1a54 100644
--- a/kernel/network/ethernet.c
+++ b/kernel/network/ethernet.c
@@ -8,16 +8,16 @@
#include <stdio.h>
struct ETHERNET_HEADER {
- uint8_t mac_dst[6];
- uint8_t mac_src[6];
- uint16_t type;
+ u8 mac_dst[6];
+ u8 mac_src[6];
+ u16 type;
};
-uint32_t crc32(const char *buf, size_t len) {
- static uint32_t table[256];
+u32 crc32(const char *buf, size_t len) {
+ static u32 table[256];
static int have_table = 0;
- uint32_t rem;
- uint8_t octet;
+ u32 rem;
+ u8 octet;
int i, j;
const char *p, *q;
@@ -36,7 +36,7 @@ uint32_t crc32(const char *buf, size_t len) {
have_table = 1;
}
- uint32_t crc = 0xFFFFFFFF;
+ u32 crc = 0xFFFFFFFF;
q = buf + len;
for (p = buf; p < q; p++) {
octet = *p;
@@ -45,17 +45,17 @@ uint32_t crc32(const char *buf, size_t len) {
return ~crc;
}
-void handle_ethernet(const uint8_t *packet, uint64_t packet_length) {
+void handle_ethernet(const u8 *packet, u64 packet_length) {
struct ETHERNET_HEADER *eth_header = (struct ETHERNET_HEADER *)packet;
packet += sizeof(struct ETHERNET_HEADER);
- const uint8_t *payload = packet;
+ const u8 *payload = packet;
packet += packet_length - sizeof(struct ETHERNET_HEADER);
- uint32_t crc = *((uint32_t *)packet - 1);
+ u32 crc = *((u32 *)packet - 1);
kprintf("PACKET crc: %x\n", crc);
kprintf("OUR OWN CALCULATED crc: %x\n",
crc32((const char *)eth_header, (packet_length - 4)));
- uint16_t type = ntohs(eth_header->type);
+ u16 type = ntohs(eth_header->type);
switch (type) {
case 0x0806:
handle_arp(payload);
@@ -69,22 +69,22 @@ void handle_ethernet(const uint8_t *packet, uint64_t packet_length) {
}
}
-void send_ethernet_packet(uint8_t mac_dst[6], uint16_t type, uint8_t *payload,
- uint64_t payload_length) {
+void send_ethernet_packet(u8 mac_dst[6], u16 type, u8 *payload,
+ u64 payload_length) {
// FIXME: Janky allocation, do this better
- uint64_t buffer_size =
- sizeof(struct ETHERNET_HEADER) + payload_length + sizeof(uint32_t);
- uint8_t *buffer = kmalloc(buffer_size);
- uint8_t *buffer_start = buffer;
+ u64 buffer_size =
+ sizeof(struct ETHERNET_HEADER) + payload_length + sizeof(u32);
+ u8 *buffer = kmalloc(buffer_size);
+ u8 *buffer_start = buffer;
struct ETHERNET_HEADER *eth_header = (struct ETHERNET_HEADER *)buffer;
buffer += sizeof(struct ETHERNET_HEADER);
memcpy(buffer, payload, payload_length);
buffer += payload_length;
- memcpy(eth_header->mac_dst, mac_dst, sizeof(uint8_t[6]));
+ memcpy(eth_header->mac_dst, mac_dst, sizeof(u8[6]));
get_mac_address(eth_header->mac_src);
eth_header->type = htons(type);
- *(uint32_t *)(buffer) =
+ *(u32 *)(buffer) =
htonl(crc32((const char *)buffer_start, buffer_size - 4));
assert(rtl8139_send_data(buffer_start, buffer_size));