From 7b11f31ad8c29e227d1c0b5fcd166c5dd1cfd183 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 6 Jan 2018 22:26:13 +0100 Subject: strip pcap --- j1eforth/j1.c | 52 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) (limited to 'j1eforth/j1.c') diff --git a/j1eforth/j1.c b/j1eforth/j1.c index 511d7cf..461e899 100644 --- a/j1eforth/j1.c +++ b/j1eforth/j1.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -28,33 +27,6 @@ int putch(int c) { /* output character to sstdout & flush */ } #endif int len = 0; -static pcap_t* handle = NULL; -static void pcapdev_init(void) { - char errbuf[PCAP_ERRBUF_SIZE]; - pcap_if_t* devices; - if (pcap_findalldevs(&devices, errbuf) == -1) { - fprintf(stderr, "error pcap_findalldevs: %s\n", errbuf); - return; - } - pcap_if_t* device; - for(device = devices; device; device = device->next) { - if (device->description) { - printf(" (%s)\n", device->description); - } - else { - fprintf(stderr, "no device\n"); - return; - } - } - device = devices->next->next; - if (NULL == (handle= pcap_open_live(device->name - , 65536, 1, 10 , errbuf))) { - fprintf(stderr, "\nUnable to open the adapter. %s is not supported by WinPcap\n"); - pcap_freealldevs(devices); - return; - } - pcap_freealldevs(devices); -} static unsigned short t; static unsigned short s; static unsigned short d[0x20]; /* data stack */ @@ -78,31 +50,11 @@ static int pop(void) // pop value from the data stack and return it dsp = 0x1f & (dsp - 1); return v; } -char eth_poll() { - const u_char* packet; - struct pcap_pkthdr* header; - int res = 0; - while (res == 0) - { - res = pcap_next_ex(handle, &header, &packet); - } - len = (int)header->len; - memcpy(&memory[0x2000], packet, len); - return len; -} -void eth_transmit(void) { - if ((pcap_sendpacket(handle, (char *)(&memory[0x2000]), len) == -1)) - { - printf("sorry send error\n"); - exit(1); - } -} static void execute(int entrypoint) { int _pc, _t; int insn = 0x4000 | entrypoint; // first insn: "call entrypoint" - pcapdev_init(); do { _pc = pc + 1; if (insn & 0x8000) { // literal @@ -140,7 +92,7 @@ static void execute(int entrypoint) case 9: _t = s>>t; break; /* rshift */ case 0xa: _t = t-1; break; /* 1- */ case 0xb: _t = r[rsp]; break; /* r@ */ - case 0xc: _t = (t==0xf008)?eth_poll():(t==0xf001)?1:(t==0xf000)?getch():memory[t>>1]; break; /* @ */ + case 0xc: _t = (t==0xf001)?1:(t==0xf000)?getch():memory[t>>1]; break; /* @ */ case 0xd: _t = s<r */ r[rsp] = t; if (insn & 0x20) /* s->[t] */ - (t==0xf008)?eth_transmit(): (t==0xf002)?(rsp=0):(t==0xf000)?putch(s):(memory[t>>1]=s); /* ! */ + (t==0xf002)?(rsp=0):(t==0xf000)?putch(s):(memory[t>>1]=s); /* ! */ t = _t; break; } -- cgit v1.2.3