Commit 50a72acd authored by Krzysztof Klis's avatar Krzysztof Klis

code cleanup

parent f4f0fd76
......@@ -99,10 +99,10 @@ int main(int argc, char *argv[]) {
/* Parse command line options */
int parse_options(int argc, char *argv[]) {
bool l,h,p,i,o;
bool l,h,p;
int c, local_port;
l = h = p = i = o = FALSE;
l = h = p = FALSE;
while ((c = getopt(argc, argv, "l:h:p:i:o:")) != -1) {
switch(c) {
......@@ -266,14 +266,14 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd[]) {
}
if (fork() == 0) {
dup2(pipe_in[READ], STDIN_FILENO); // redirect stdin to input pipe
close(pipe_in[WRITE]); // no need to write to input pipe here
dup2(pipe_out[WRITE], STDOUT_FILENO); // redirect stdout to output pipe
close(pipe_out[READ]); // no need to read output pipe here
dup2(pipe_in[READ], STDIN_FILENO); // replace standard input with input part of pipe_in
dup2(pipe_out[WRITE], STDOUT_FILENO); // replace standard output with output part of pipe_out
close(pipe_in[WRITE]); // close unused end of pipe_in
close(pipe_out[READ]); // close unused end of pipe_out
n = execvp(cmd[0], cmd); // execute command
exit(n);
} else {
close(pipe_in[READ]); // no need to read input pipe here
close(pipe_in[READ]); // no need to read from input pipe here
close(pipe_out[WRITE]); // no need to write to output pipe here
while ((n = recv(source_sock, buffer, BUF_SIZE, 0)) > 0) { // read data from input socket
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment