dial.c has been attached.
2014-05-26 20:06 GMT-04:00 yan cui <ccuiy...@gmail.com>: > Hi all, > > I used a program to dial from one system to another system, but > it gives a connection time out error. I have searched on Internet for a > long time and cannot get a solution. Could you please provide some > suggestions or hints? Basically, one system is Linux based system with rc > shell installed (we call it A). The other one is a auth+cpu+file server > (we call it B). On B, I have used fossil/conf command to listen tcp!*!564. > On A, I executed dial tcp!<B's ip address>!564, but it reports a time out > error after waiting some time. Results are the same when A is a plan9 > terminal. By the way, I can ping A to B successfully. What could be the > possible problems? > > > Thanks, Yan > > -- > Think big; Dream impossible; Make it happen. > -- Think big; Dream impossible; Make it happen.
#include <u.h> #include <libc.h> void usage(void) { fprint(2, "usage: dial [-e] addr\n"); exits("usage"); } void killer(void *x, char *msg) { USED(x); if(strcmp(msg, "kill") == 0) exits(0); noted(NDFLT); } void main(int argc, char **argv) { int fd, pid; char buf[8192]; int n, waitforeof; notify(killer); waitforeof = 0; ARGBEGIN{ case 'e': waitforeof = 1; break; default: usage(); }ARGEND if(argc != 1) usage(); if((fd = dial(argv[0], nil, nil, nil)) < 0) sysfatal("dial: %r"); switch(pid = fork()){ case -1: sysfatal("fork: %r"); case 0: while((n = read(0, buf, sizeof buf)) > 0) if(write(fd, buf, n) < 0) break; if(!waitforeof) postnote(PNPROC, getppid(), "kill"); exits(nil); } while((n = read(fd, buf, sizeof buf)) > 0) if(write(1, buf, n) < 0) break; postnote(PNPROC, pid, "kill"); waitpid(); exits(0); }