summaryrefslogtreecommitdiff
path: root/net/netdev.c
blob: 863661ddf289bf4b08b9ed5a6015b869416d1802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "netdev.h"
#include "net_sys.h"

#include <stdint.h>

#include "eth.h"
#include "inet.h"
#include "arp.h"
#include "ipv4.h"

void net_incoming(struct netdev *netdev, struct eth_hdr *hdr)
{
    if(hdr->ethertype==htons(ETH_P_ARP))arp_incoming(netdev,hdr);
    if(hdr->ethertype==htons(ETH_P_IPV4))ipv4_incoming(netdev,hdr);
}

void netdev_transmit(struct netdev *dev, struct eth_hdr *hdr, uint16_t ethertype, int len, unsigned char *dst)
{
    hdr->ethertype = htons(ethertype);
    memcpy(hdr->smac, dev->hwaddr, 6);
    memcpy(hdr->dmac, dst, 6);

    len += sizeof(struct eth_hdr);

    dev->transmit(hdr,len);
}