#include #include #include #include #include char *host; char *net; Biobuf bio; int secs; char* getport(int i) { static char port[10], *p; sprint(port, "%d", i); if((p=csgetvalue("/net", "port", port, net, nil)) == nil) return port; strncpy(port, p, sizeof(port)-1); port[sizeof(port)-1] = 0; free(p); return port; } void ci5(char *port) { int fd; alarm(1000*secs); if((fd=dial(netmkaddr(host, net, port), 0, 0, 0)) > 0){ Bprint(&bio, "%s!%s!%s\n", net, host, port); Bflush(&bio); close(fd); } alarm(0); } void main(int argc, char *argv[]) { Waitmsg *w; int port[2], i; char *p; port[0] = 1; port[1] = 512; secs = 10; ARGBEGIN{ case 'r': for(i=0; i<2; i++){ p = ARGF(); if(p == nil) goto Usage; port[i] = atoi(p); if(port[i] <= 0) goto Usage; } if(port[0] >= port[1]){ fprint(2, "ci5: invalid range: %d-%d\n", port[0], port[1]); exits("range"); } break; case 's': p = ARGF(); if(p == nil) goto Usage; secs = atoi(p); if(secs <= 0) goto Usage; break; default: goto Usage; }ARGEND if(argc != 1){ Usage: fprint(2, "Usage: ci5 [-r start end] [-s secs] net!host\n"); exits("usage"); } Binit(&bio, 1, OWRITE); net = "tcp"; host = argv[0]; if((p = strchr(host, '!'))){ *p++ = '\0'; net = host; host = p; } for(i=port[0]; i