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;
90 #include <sys/types.h>
91 #include <sys/socket.h>
92 #include <netpacket/packet.h>
93 #include <net/ethernet.h>
95 typedef struct frame {
97 unsigned short datalen;
104 void send_text(char *d, int len)
106 int datalen = sizeof(frame) + len;
107 frame * f = alloca(datalen + 1);
108 struct sockaddr_ll addr;
110 memcpy(f->header, "\x00\xb0\xd0\x97\xbc\xac\x00\x03\x93\x87\x84\x8C\x13\x38", 14);
113 memcpy(f->data, d, len);
115 addr.sll_family = AF_PACKET;
116 addr.sll_ifindex = 2;
119 if (sendto(sendsock, f, datalen, 0, (struct sockaddr *)&addr, sizeof(addr)) < datalen)
123 void handler (u_char * user, const struct pcap_pkthdr *h, const u_char *bytes)
125 netwatch_frame * f = (netwatch_frame *) bytes;
128 int data_len = h->caplen - sizeof(netwatch_frame) - 4;
130 if (data_len < 0) return;
132 if (ntohs(f->ethertype) != 0x1337) return;
134 if (data_len > sizeof(buf)) return;
136 if (f->buf_offset + data_len > sizeof(buf))
138 int wrap_pos = sizeof(buf) - f->buf_offset;
139 memcpy(buf + f->buf_offset, f->data, wrap_pos);
140 memcpy(buf, f->data + wrap_pos, data_len - wrap_pos);
142 memcpy(buf + f->buf_offset, f->data, data_len);
148 pcap_breakloop(pcap);
149 if (c == '\r') c = '\n';
150 if (c == 127) c = '\b';
157 out(buf, f->buf_window);
161 pcap = pcap_open_live(NULL, 65535, 1, 0, errbuf);
165 printf("pcap_open_live: %s\n", errbuf);
168 sendsock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
174 fcntl(0, F_SETFL, O_NONBLOCK);
175 printf("\x1b[H\x1b[J\x1b[5C");
177 struct termios t, t_orig;
179 tcgetattr(0, &t_orig);
183 pcap_loop(pcap, -1, handler, NULL);
185 tcsetattr(0, 0, &t_orig);