quinn-os/ether.h
2022-07-21 14:52:54 +10:00

40 lines
1.2 KiB
C

#ifndef __ETHER_H
#define __ETHER_H
#include "pvec.h"
#define htons(A) ((((uint16_t)(A)&0xff00) >> 8) | (((uint16_t)(A)&0x00ff) << 8))
#define htonl(A) \
((((uint32_t)(A)&0xff000000) >> 24) | (((uint32_t)(A)&0x00ff0000) >> 8) | (((uint32_t)(A)&0x0000ff00) << 8) | (((uint32_t)(A)&0x000000ff) << 24))
#define ETH_MIN_PACKET_SIZE 60
struct ether_t {
int type;
int state;
uint8_t mac[6];
uint32_t ipv4;
uint32_t mask;
uint32_t default_gw;
void *data;
uint8_t arp_initialized;
struct ptr_vector arp_table;
struct ptr_vector arp_wait;
};
struct ether_packet_t {
uint8_t destmac[6];
uint8_t sourcemac[6];
uint16_t ethertype;
uint8_t payload[];
} __attribute__((packed));
extern void init_ether();
extern int ether_send(struct ether_t *card, char *packet, int len);
extern int ether_receive(struct ether_t *ether, uint8_t *packet, int len);
extern int ether_enable(int ether, uint32_t ipv4, uint32_t mask);
extern struct ether_t *ether_find_from_ipv4(uint32_t ipv4);
extern int ether_add_default_gw(int ether, uint32_t ipv4);
extern int ether_get_mac(int ether, uint8_t *dest);
#endif