10 char errbuf[PCAP_ERRBUF_SIZE];
14 typedef struct netwatch_frame {
17 unsigned short whatthefuck;
18 unsigned short ethertype;
19 unsigned short buf_offset;
20 unsigned short buf_window;
26 void out(char *buf, unsigned short start)
31 for (y = 0; y < 25; y++)
33 printf("\x1B[%d;%df",y+1,1);
34 for (x = 0; x < 80; x++)
37 static unsigned char last = 0xFF;
44 printf("\x1B[0m\x1B[");
47 case 0: printf("30;"); break;
48 case 1: printf("34;"); break;
49 case 2: printf("32;"); break;
50 case 3: printf("36;"); break;
51 case 4: printf("31;"); break;
52 case 5: printf("35;"); break;
53 case 6: printf("33;"); break;
54 case 7: printf("37;"); break;
60 switch ((col >> 4) & 0x7)
62 case 0: printf("40"); break;
63 case 1: printf("44"); break;
64 case 2: printf("42"); break;
65 case 3: printf("46"); break;
66 case 4: printf("41"); break;
67 case 5: printf("45"); break;
68 case 6: printf("43"); break;
69 case 7: printf("47"); break;
88 #include <sys/types.h>
89 #include <sys/socket.h>
90 #include <netpacket/packet.h>
91 #include <net/ethernet.h>
93 typedef struct frame {
95 unsigned short datalen;
102 void send_text(char *d, int len)
104 int datalen = sizeof(frame) + len;
105 frame * f = alloca(datalen + 1);
106 struct sockaddr_ll addr;
108 memcpy(f->header, "\x00\xb0\xd0\x97\xbc\xac\x00\x03\x93\x87\x84\x8C\x13\x38", 14);
111 memcpy(f->data, d, len);
113 addr.sll_family = AF_PACKET;
114 addr.sll_ifindex = 2;
117 if (sendto(sendsock, f, datalen, 0, (struct sockaddr *)&addr, sizeof(addr)) < datalen)
123 struct sockaddr_ll addr;
125 memcpy(f.header, "\x00\xb0\xd0\x97\xbc\xac\x00\x03\x93\x87\x84\x8C\x13\x38", 14);
128 addr.sll_family = AF_PACKET;
129 addr.sll_ifindex = 2;
132 if (sendto(sendsock, &f, sizeof(frame), 0, (struct sockaddr *)&addr, sizeof(addr)) < sizeof(frame))
136 void handler (u_char * user, const struct pcap_pkthdr *h, const u_char *bytes)
138 netwatch_frame * f = (netwatch_frame *) bytes;
141 int data_len = h->caplen - sizeof(netwatch_frame) - 4;
143 if (data_len < 0) return;
145 if (ntohs(f->ethertype) != 0x1337) return;
147 if (data_len > sizeof(buf)) return;
149 if (f->buf_offset + data_len > sizeof(buf))
151 int wrap_pos = sizeof(buf) - f->buf_offset;
152 memcpy(buf + f->buf_offset, f->data, wrap_pos);
153 memcpy(buf, f->data + wrap_pos, data_len - wrap_pos);
155 memcpy(buf + f->buf_offset, f->data, data_len);
161 pcap_breakloop(pcap);
162 if (c == '\r') c = '\n';
163 if (c == 127) c = '\b';
189 out(buf, f->buf_window);
193 pcap = pcap_open_live(NULL, 65535, 1, 0, errbuf);
197 printf("pcap_open_live: %s\n", errbuf);
200 sendsock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
206 fcntl(0, F_SETFL, O_NONBLOCK);
207 printf("\x1b[H\x1b[J\x1b[5C");
209 struct termios t, t_orig;
211 tcgetattr(0, &t_orig);
215 pcap_loop(pcap, -1, handler, NULL);
217 tcsetattr(0, 0, &t_orig);