43 lines
1.2 KiB
C
43 lines
1.2 KiB
C
#ifndef __ETHER_H
|
|
#define __ETHER_H
|
|
|
|
#define htons(A) ((((unsigned short)(A) & 0xff00) >> 8) | \
|
|
(((unsigned short)(A) & 0x00ff) << 8))
|
|
#define htonl(A) ((((unsigned int)(A) & 0xff000000) >> 24) | \
|
|
(((unsigned int)(A) & 0x00ff0000) >> 8) | \
|
|
(((unsigned int)(A) & 0x0000ff00) << 8) | \
|
|
(((unsigned int)(A) & 0x000000ff) << 24))
|
|
|
|
#define ETH_MIN_PACKET_SIZE 60
|
|
|
|
struct ether_t {
|
|
int type;
|
|
int state;
|
|
unsigned char mac[6];
|
|
unsigned int ipv4;
|
|
unsigned int mask;
|
|
unsigned int default_gw;
|
|
void *data;
|
|
unsigned char arp_initialized;
|
|
struct arp_table_t **arp_table;
|
|
unsigned int arp_table_count;
|
|
struct arp_wait_t **arp_wait;
|
|
unsigned int arp_wait_count;
|
|
};
|
|
|
|
struct ether_packet_t {
|
|
unsigned char destmac[6];
|
|
unsigned char sourcemac[6];
|
|
unsigned short ethertype;
|
|
unsigned char 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, unsigned char *packet, int len);
|
|
extern int ether_enable(int ether, unsigned int ipv4, unsigned int mask);
|
|
extern struct ether_t *ether_find_from_ipv4(unsigned int ipv4);
|
|
extern int ether_add_default_gw(int ether, unsigned int ipv4);
|
|
extern int ether_get_mac(int ether, unsigned char *dest);
|
|
#endif
|