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
ecd4b1a4
Commit
ecd4b1a4
authored
Nov 17, 2016
by
Krzysztof Kliś
Committed by
GitHub
Nov 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5 from ticpu/syslog
Add syslog support.
parents
84a36ddd
81286f92
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
18 deletions
+55
-18
Makefile
Makefile
+8
-5
proxy.c
proxy.c
+47
-13
No files found.
Makefile
View file @
ecd4b1a4
CFLAGS
=
-O2
-std
=
c99
-s
-Wall
-DUSE_SPLICE
LDFLAGS
=
all
:
gcc
-O2
-s
-o
proxy proxy.c
gcc
$(CFLAGS)
-o
proxy proxy.c
$(LDFLAGS)
tomato
:
mipsel-uclibc-gcc
-O2
-s
-o
proxy proxy.c
mipsel-uclibc-gcc
$(CFLAGS)
-o
proxy proxy.c
$(LDFLAGS)
openwrt
:
mipsel-linux-uclibc-gcc
-O2
-s
-o
proxy proxy.c
mipsel-linux-uclibc-gcc
$(CFLAGS)
-o
proxy proxy.c
$(LDFLAGS)
backfire
:
mipsel-openwrt-linux-uclibc-gcc
-O2
-s
-o
proxy proxy.c
mipsel-openwrt-linux-uclibc-gcc
$(CFLAGS)
-o
proxy proxy.c
$(LDFLAGS)
clean
:
rm
-
r
f
proxy proxy.exe
rm
-f
proxy proxy.exe
proxy.c
View file @
ecd4b1a4
...
...
@@ -37,10 +37,12 @@
#include <netdb.h>
#include <resolv.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <syslog.h>
#include <unistd.h>
#include <wait.h>
#ifdef USE_SYSTEMD
...
...
@@ -74,11 +76,13 @@ void forward_data(int source_sock, int destination_sock);
void
forward_data_ext
(
int
source_sock
,
int
destination_sock
,
char
*
cmd
);
int
create_connection
();
int
parse_options
(
int
argc
,
char
*
argv
[]);
void
plog
(
int
priority
,
const
char
*
format
,
...);
int
server_sock
,
client_sock
,
remote_sock
,
remote_port
=
0
;
int
connections_processed
=
0
;
char
*
remote_host
,
*
cmd_in
,
*
cmd_out
;
bool
foreground
=
FALSE
;
bool
use_syslog
=
FALSE
;
/* Program start */
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -88,12 +92,15 @@ int main(int argc, char *argv[]) {
local_port
=
parse_options
(
argc
,
argv
);
if
(
local_port
<
0
)
{
printf
(
"Syntax: %s -l local_port -h remote_host -p remote_port [-i
\"
input parser
\"
] [-o
\"
output parser
\"
] [-f (stay in foreground)]
\n
"
,
argv
[
0
]);
printf
(
"Syntax: %s -l local_port -h remote_host -p remote_port [-i
\"
input parser
\"
] [-o
\"
output parser
\"
] [-f (stay in foreground)]
[-s (use syslog)]
\n
"
,
argv
[
0
]);
return
local_port
;
}
if
(
use_syslog
)
openlog
(
"proxy"
,
LOG_PID
,
LOG_DAEMON
);
if
((
server_sock
=
create_socket
(
local_port
))
<
0
)
{
// start server
p
error
(
"Cannot run server
"
);
p
log
(
LOG_CRIT
,
"Cannot run server: %m
"
);
return
server_sock
;
}
...
...
@@ -108,13 +115,16 @@ int main(int argc, char *argv[]) {
server_loop
();
break
;
case
-
1
:
// error
p
error
(
"Cannot daemonize
"
);
p
log
(
LOG_CRIT
,
"Cannot daemonize: %m
"
);
return
pid
;
default:
// parent
close
(
server_sock
);
}
}
if
(
use_syslog
)
closelog
();
return
EXIT_SUCCESS
;
}
...
...
@@ -122,7 +132,7 @@ int main(int argc, char *argv[]) {
int
parse_options
(
int
argc
,
char
*
argv
[])
{
int
c
,
local_port
=
0
;
while
((
c
=
getopt
(
argc
,
argv
,
"l:h:p:i:o:f"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"l:h:p:i:o:f
s
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'l'
:
local_port
=
atoi
(
optarg
);
...
...
@@ -141,6 +151,10 @@ int parse_options(int argc, char *argv[]) {
break
;
case
'f'
:
foreground
=
TRUE
;
break
;
case
's'
:
use_syslog
=
TRUE
;
break
;
}
}
...
...
@@ -180,6 +194,24 @@ int create_socket(int port) {
return
server_sock
;
}
/* Send log message to stderr or syslog */
void
plog
(
int
priority
,
const
char
*
format
,
...)
{
va_list
ap
;
va_start
(
ap
,
format
);
if
(
use_syslog
)
vsyslog
(
priority
,
format
,
ap
);
else
{
vfprintf
(
stderr
,
format
,
ap
);
fprintf
(
stderr
,
"
\n
"
);
}
va_end
(
ap
);
}
/* Update systemd status with connection count */
void
update_connection_count
()
{
#ifdef USE_SYSTEMD
...
...
@@ -226,7 +258,7 @@ void server_loop() {
void
handle_client
(
int
client_sock
,
struct
sockaddr_in
client_addr
)
{
if
((
remote_sock
=
create_connection
())
<
0
)
{
p
error
(
"Cannot connect to host
"
);
p
log
(
LOG_ERR
,
"Cannot connect to host: %m
"
);
goto
cleanup
;
}
...
...
@@ -261,14 +293,14 @@ void forward_data(int source_sock, int destination_sock) {
int
buf_pipe
[
2
];
if
(
pipe
(
buf_pipe
)
==
-
1
)
{
p
error
(
"pipe
"
);
exit
(
EXIT_FAILURE
);
p
log
(
LOG_ERR
,
"pipe: %m
"
);
exit
(
CREATE_PIPE_ERROR
);
}
while
((
n
=
splice
(
source_sock
,
NULL
,
buf_pipe
[
WRITE
],
NULL
,
SSIZE_MAX
,
SPLICE_F_NONBLOCK
|
SPLICE_F_MOVE
))
>
0
)
{
if
(
splice
(
buf_pipe
[
READ
],
NULL
,
destination_sock
,
NULL
,
SSIZE_MAX
,
SPLICE_F_MOVE
)
<
0
)
{
p
error
(
"write
"
);
exit
(
EXIT_FAILURE
);
p
log
(
LOG_ERR
,
"write: %m
"
);
exit
(
BROKEN_PIPE_ERROR
);
}
}
#else
...
...
@@ -279,8 +311,10 @@ void forward_data(int source_sock, int destination_sock) {
}
#endif
if
(
n
<
0
)
perror
(
"read"
);
if
(
n
<
0
)
{
plog
(
LOG_ERR
,
"read: %m"
);
exit
(
BROKEN_PIPE_ERROR
);
}
#ifdef USE_SPLICE
close
(
buf_pipe
[
0
]);
...
...
@@ -300,7 +334,7 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd) {
int
n
,
i
,
pipe_in
[
2
],
pipe_out
[
2
];
if
(
pipe
(
pipe_in
)
<
0
||
pipe
(
pipe_out
)
<
0
)
{
// create command input and output pipes
p
error
(
"Cannot create pipe
"
);
p
log
(
LOG_CRIT
,
"Cannot create pipe: %m
"
);
exit
(
CREATE_PIPE_ERROR
);
}
...
...
@@ -317,7 +351,7 @@ void forward_data_ext(int source_sock, int destination_sock, char *cmd) {
while
((
n
=
recv
(
source_sock
,
buffer
,
BUF_SIZE
,
0
))
>
0
)
{
// read data from input socket
if
(
write
(
pipe_in
[
WRITE
],
buffer
,
n
)
<
0
)
{
// write data to input pipe of external command
p
error
(
"Cannot write to pipe
"
);
p
log
(
LOG_ERR
,
"Cannot write to pipe: %m
"
);
exit
(
BROKEN_PIPE_ERROR
);
}
if
((
i
=
read
(
pipe_out
[
READ
],
buffer
,
BUF_SIZE
))
>
0
)
{
// read command output
...
...
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