8000 minix/minix/commands/rget/rget.c at master · openube/minix · GitHub
[go: up one dir, main page]

Skip to content
< 8000 link rel="preload" as="image" href="https://github.githubassets.com/assets/changelog-dark-b1c25ae971bd641b.png"/>

Latest commit

 

History

History
290 lines (251 loc) · 6.81 KB

rget.c

File metadata and controls

290 lines (251 loc) · 6.81 KB
memset(&channel, 0, sizeof(channel));
channel.sin_family= AF_INET;
memcpy(&channel.sin_addr.s_addr, hent->h_addr,
sizeof(channel.sin_addr.s_addr));
channel.sin_port= name2port(key);
if (connect(s, (struct sockaddr *) &channel,
sizeof(channel)) >= 0) break;
if (--n > 0) sleep(2); else fatal("connect()");
close(s);
}
#endif
}
if (cmdv[0] != nil) {
/* A command is given, so execute it with standard input (rget),
* standard output (rput) or both (-io) tied to the TCP stream.
*/
if (iflag) dup2(s, 0);
if (oflag) dup2(s, 1);
close(s);
execvp(cmdv[0], cmdv);
fatal(cmdv[0]);
} else {
/* Without a command we have to copy bytes ourselves, probably to or
* from a command that is connected to us with a pipe. (The original
* function of rput/rget, a remote pipe.)
*/
int fi, fo;
int n;
char buf[8192];
if (iflag) {
fi= s;
fo= 1;
} else {
fi= 0;
fo= s;
}
while ((n= read(fi, buf, sizeof(buf))) > 0) {
char *bp= buf;
while (n > 0) {
int r;
if ((r= write(fo, bp, n)) <= 0) {
if (r == 0) {
fprintf(stderr, "%s: write(): Unexpected EOF\n", name);
exit(1);
}
fatal("write()");
}
bp+= r;
n-= r;
}
}
if (n < 0) fatal("read()");
}
return 0;
}
0