/* mkpass.c Steve Simon Apr 2005 */ #include #include #include #include static void ding(void *u, char *msg) { USED(u); if(strstr(msg, "alarm")) noted(NCONT); noted(NDFLT); } void main() { int fd, cfd, num, n; char buf[1024]; DigestState *s; uchar digest[SHA1dlen]; notify(ding); fmtinstall('[', encodefmt); if((fd = dial("/net/ether0!-1", 0, 0, &cfd)) == -1) sysfatal("cannot open ether device - %r\n"); if (fprint(cfd, "promiscuous") < 0) sysfatal("cannot set ether to promiscuous mode\n"); alarm(1000*10); s = sha1(nil, 0, nil, nil); for(n = num = 0; num < 4096 && n >= 0; num += n){ n = read(fd, buf, sizeof(buf)); s = sha1((uchar *)buf, n, nil, s); num += n; } sha1(nil, 0, digest, s); if (num < 4096) sysfatal("%d bytes, not enough ethernet traffic\n", num); /* * -2 below as otherwise base64 gives * a fixed pattern at the end of each password. */ print("%.*[\n", SHA1dlen-2, digest); exits(0); }