Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
P
proxy-in-proxychains
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
proxy-in-proxychains
Commits
f4f0fd76
Commit
f4f0fd76
authored
Aug 20, 2012
by
Krzysztof Klis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pipes error handling
parent
b76e6066
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
proxy.c
proxy.c
+11
-5
No files found.
proxy.c
View file @
f4f0fd76
...
@@ -260,8 +260,10 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd[]) {
...
@@ -260,8 +260,10 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd[]) {
char
buffer
[
BUF_SIZE
];
char
buffer
[
BUF_SIZE
];
int
n
,
i
,
pipe_in
[
2
],
pipe_out
[
2
];
int
n
,
i
,
pipe_in
[
2
],
pipe_out
[
2
];
pipe
(
pipe_in
);
// command input pipe
if
(
pipe
(
pipe_in
)
<
0
||
pipe
(
pipe_out
)
<
0
)
{
// create command input and output pipes
pipe
(
pipe_out
);
// command output pipe
perror
(
"Cannot create pipe"
);
exit
(
EXIT_FAILURE
);
}
if
(
fork
()
==
0
)
{
if
(
fork
()
==
0
)
{
dup2
(
pipe_in
[
READ
],
STDIN_FILENO
);
// redirect stdin to input pipe
dup2
(
pipe_in
[
READ
],
STDIN_FILENO
);
// redirect stdin to input pipe
...
@@ -275,10 +277,14 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd[]) {
...
@@ -275,10 +277,14 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd[]) {
close
(
pipe_out
[
WRITE
]);
// no need to write to output 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
while
((
n
=
recv
(
source_sock
,
buffer
,
BUF_SIZE
,
0
))
>
0
)
{
// read data from input socket
write
(
pipe_in
[
WRITE
],
buffer
,
n
);
// write data to input pipe of external command
if
(
write
(
pipe_in
[
WRITE
],
buffer
,
n
)
<
0
)
{
// write data to input pipe of external command
i
=
read
(
pipe_out
[
READ
],
buffer
,
BUF_SIZE
);
// read command output
perror
(
"Cannot write to pipe"
);
exit
(
EXIT_FAILURE
);
}
if
((
i
=
read
(
pipe_out
[
READ
],
buffer
,
BUF_SIZE
))
>
0
)
{
// read command output
send
(
destination_sock
,
buffer
,
i
,
0
);
// send data to output socket
send
(
destination_sock
,
buffer
,
i
,
0
);
// send data to output socket
}
}
}
shutdown
(
destination_sock
,
SHUT_RDWR
);
// stop other processes from using socket
shutdown
(
destination_sock
,
SHUT_RDWR
);
// stop other processes from using socket
close
(
destination_sock
);
close
(
destination_sock
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment