-
Notifications
You must be signed in to change notification settings - Fork 1
/
etherif.c
49 lines (41 loc) · 844 Bytes
/
etherif.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include "netsniff.h"
#include "netif.h"
#include "arp.h"
#include "mbuf.h"
static char fmt_buf[1024];
static struct strbuf sb = {
.size = sizeof(fmt_buf),
.buf = fmt_buf,
};
void ip_input(struct netif *ifp, struct mbuf *m);
void
eth_input(struct netif *netif, struct mbuf *m)
{
struct machdr *hdr;
hdr = mb_htrim(m, sizeof(*hdr));
sb_reset(&sb);
eth_print(hdr, &sb);
switch (hdr->type) {
case ntohs(ETH_P_IP):
ip_input(netif, m);
break;
case ntohs(ETH_P_ARP):
arp_recv(netif, m);
break;
default:
mb_chain_free(m);
break;
}
}
void
eth_output(struct netif *ifp, struct mbuf *m,
uint8_t *dst, uint16_t ethproto)
{
struct machdr *eh;
eh = mb_push(m, sizeof(*eh));
memcpy(eh->dst, dst, ETH_ALEN);
memcpy(eh->src, &ifp->hwaddr, ETH_ALEN);
eh->type = htons(ethproto);
netif_xmit(ifp, m);
}