summaryrefslogtreecommitdiff
path: root/src/user/app/ethdump/ethdump.c
blob: 40479626951e454960f146ce92279ee642eb96a9 (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
27
28
29
30
31
32
33
34
#include "proto.h"
#include "util.h"
#include <camellia/syscalls.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

struct net_state state = {
	// TODO dynamically get mac
	.mac = {0x52, 0x54, 0x00, 0xCA, 0x77, 0x1A},
	.ip = (192 << 24) + (168 << 16) + 11,
};

int main(void) {
	const char *path = "/kdev/eth";
	state.raw_h = _syscall_open(path, strlen(path), 0);
	if (state.raw_h < 0) {
		eprintf("couldn't open %s", path);
		return 1;
	}

	const size_t buflen = 4096;
	char *buf = malloc(buflen);
	for (;;) {
		long ret = _syscall_read(state.raw_h, buf, buflen, -1);
		if (ret < 0) break;
		printf("\npacket of length %u\n", ret);
		hexdump(buf, ret);
		ether_parse((void*)buf, ret);
	}
	free(buf);
	return 0;
}