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
34a6ce1d
Commit
34a6ce1d
authored
Oct 28, 2016
by
Krzysztof Kliś
Committed by
GitHub
Oct 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from ticpu/splice
Use splice instead of copy.
parents
e0ee747c
0f5e7804
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
proxy.c
proxy.c
+25
-1
No files found.
proxy.c
View file @
34a6ce1d
...
...
@@ -28,8 +28,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <netdb.h>
#include <resolv.h>
...
...
@@ -233,12 +235,34 @@ void handle_client(int client_sock, struct sockaddr_in client_addr)
/* Forward data between sockets */
void
forward_data
(
int
source_sock
,
int
destination_sock
)
{
ssize_t
n
;
#ifdef USE_SPLICE
int
buf_pipe
[
2
];
if
(
pipe
(
buf_pipe
)
==
-
1
)
{
perror
(
"pipe"
);
exit
(
EXIT_FAILURE
);
}
while
((
n
=
splice
(
source_sock
,
NULL
,
buf_pipe
[
WRITE
],
NULL
,
BUF_SIZE
,
SPLICE_F_MOVE
))
>
0
)
{
if
(
splice
(
buf_pipe
[
READ
],
NULL
,
destination_sock
,
NULL
,
n
,
SPLICE_F_MOVE
)
<
0
)
{
perror
(
"splice"
);
exit
(
EXIT_FAILURE
);
}
}
#else
char
buffer
[
BUF_SIZE
];
int
n
;
while
((
n
=
recv
(
source_sock
,
buffer
,
BUF_SIZE
,
0
))
>
0
)
{
// read data from input socket
send
(
destination_sock
,
buffer
,
n
,
0
);
// send data to output socket
}
#endif
#ifdef USE_SPLICE
close
(
buf_pipe
[
0
]);
close
(
buf_pipe
[
1
]);
#endif
shutdown
(
destination_sock
,
SHUT_RDWR
);
// stop other processes from using socket
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