Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bytevia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Pastushkov
bytevia
Commits
7d496dba
Commit
7d496dba
authored
Sep 18, 2024
by
Michael Pastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
another try
parent
c30dcd97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
62 deletions
+14
-62
src/bytevia.c
+14
-62
No files found.
src/bytevia.c
View file @
7d496dba
...
@@ -353,15 +353,9 @@ int use(void)
...
@@ -353,15 +353,9 @@ int use(void)
for
(;;)
for
(;;)
{
{
int
proxy_sock
;
struct
sockaddr_in
proxy_addr
;
struct
sockaddr_in
proxy_addr2
;
int
proxy_port
=
12340
;
FD_ZERO
(
&
io
);
FD_ZERO
(
&
io
);
FD_SET
(
rc
.
client_socket
,
&
io
);
FD_SET
(
rc
.
client_socket
,
&
io
);
FD_SET
(
rc
.
remote_socket
,
&
io
);
FD_SET
(
rc
.
remote_socket
,
&
io
);
int
max_fd
=
(
rc
.
client_socket
>
rc
.
remote_socket
)
?
rc
.
client_socket
:
rc
.
remote_socket
;
int
max_fd
=
(
rc
.
client_socket
>
rc
.
remote_socket
)
?
rc
.
client_socket
:
rc
.
remote_socket
;
/* Waiting for data */
/* Waiting for data */
...
@@ -370,27 +364,8 @@ int use(void)
...
@@ -370,27 +364,8 @@ int use(void)
break
;
break
;
}
}
if
(
options
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
FD_ZERO
(
&
io
);
if
((
proxy_sock
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
FD_SET
(
rc
.
client_socket
,
&
io
);
perror
(
"proxy socket creation failed"
);
return
1
;
}
memset
(
&
proxy_addr
,
0
,
sizeof
(
proxy_addr
));
proxy_addr
.
sin_family
=
AF_INET
;
proxy_addr
.
sin_addr
.
s_addr
=
inet_addr
(
"127.0.0.1"
);
proxy_addr
.
sin_port
=
htons
(
proxy_port
);
// Bind the socket to the specific IP and port
if
(
bind
(
proxy_sock
,
(
struct
sockaddr
*
)
&
proxy_addr
,
sizeof
(
proxy_addr
))
<
0
)
{
perror
(
"bind failed"
);
close
(
proxy_sock
);
return
1
;
}
printf
(
"** proxy sock created and mound to %d"
,
proxy_port
);
}
if
(
FD_ISSET
(
rc
.
client_socket
,
&
io
))
if
(
FD_ISSET
(
rc
.
client_socket
,
&
io
))
{
{
/* Processing request from local, sending it to remote*/
/* Processing request from local, sending it to remote*/
...
@@ -414,45 +389,22 @@ int use(void)
...
@@ -414,45 +389,22 @@ int use(void)
decode
(
buffer
,
count_recv
)
:
decode
(
buffer
,
count_recv
)
:
encode
(
buffer
,
count_recv
);
encode
(
buffer
,
count_recv
);
if
(
options
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
count_sent
=
(
options
.
proto
==
SOCK_DGRAM
)
?
sendto
(
rc
.
remote_socket
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
rc
.
remote_addr
,
sizeof
(
rc
.
remote_addr
))
:
count_sent
=
sendto
(
proxy_sock
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
rc
.
remote_addr
,
sizeof
(
rc
.
remote_addr
));
send
(
rc
.
remote_socket
,
buffer
,
count_recv
,
0
);
if
(
count_sent
<
0
)
{
perror
(
"sendto proxy_sockfailed"
);
close
(
proxy_sock
);
return
1
;
}
printf
(
"** bytes sent to remote: %d
\n
"
,
count_recv
);
}
else
{
count_sent
=
(
options
.
proto
==
SOCK_DGRAM
)
?
sendto
(
rc
.
remote_socket
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
rc
.
remote_addr
,
sizeof
(
rc
.
remote_addr
))
:
send
(
rc
.
remote_socket
,
buffer
,
count_recv
,
0
);
}
if
(
options
.
log
>
2
)
if
(
options
.
log
>
1
)
printf
(
"
forwarded %d / %d bytes from local to remote
\n
"
,
count_recv
,
count_sent
);
printf
(
"
recv %d
\t
%s:%d
\t
pid:
\n
"
,
ntohs
(
client_addr
.
sin_port
),
inet_ntoa
(
client_addr
.
sin_addr
),
getpid
()
);
}
}
FD_ZERO
(
&
io
);
FD_SET
(
rc
.
remote_socket
,
&
io
);
if
(
FD_ISSET
(
rc
.
remote_socket
,
&
io
))
if
(
FD_ISSET
(
rc
.
remote_socket
,
&
io
))
{
{
/* Processing response from remote, sending it back to local */
/* Processing response from remote, sending it back to local */
count_recv
=
(
options
.
proto
==
SOCK_DGRAM
)
?
if
(
options
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
recvfrom
(
rc
.
remote_socket
,
buffer
,
sizeof
(
buffer
),
0
,
NULL
,
NULL
)
:
recv
(
rc
.
remote_socket
,
buffer
,
sizeof
(
buffer
),
0
);
count_recv
=
recvfrom
(
proxy_sock
,
buffer
,
sizeof
(
buffer
),
0
,
(
struct
sockaddr
*
)
&
proxy_addr2
,
&
addr_len
);
if
(
count_sent
<
0
)
{
perror
(
"recvfrom proxy_sock failed"
);
close
(
proxy_sock
);
return
1
;
}
printf
(
"** bytes received from remote: %d, port: %d, address: %s
\n
"
,
count_recv
,
proxy_addr2
.
sin_port
,
inet_ntoa
(
proxy_addr2
.
sin_addr
));
}
else
{
count_recv
=
(
options
.
proto
==
SOCK_DGRAM
)
?
recvfrom
(
rc
.
remote_socket
,
buffer
,
sizeof
(
buffer
),
0
,
NULL
,
NULL
)
:
recv
(
rc
.
remote_socket
,
buffer
,
sizeof
(
buffer
),
0
);
}
if
(
count_recv
<
0
)
{
if
(
count_recv
<
0
)
{
perror
(
"use: recv(rc.remote_socket)"
);
perror
(
"use: recv(rc.remote_socket)"
);
...
@@ -473,8 +425,8 @@ int use(void)
...
@@ -473,8 +425,8 @@ int use(void)
sendto
(
rc
.
client_socket
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
client_addr
,
addr_len
)
:
sendto
(
rc
.
client_socket
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
client_addr
,
addr_len
)
:
send
(
rc
.
client_socket
,
buffer
,
count_recv
,
0
);
send
(
rc
.
client_socket
,
buffer
,
count_recv
,
0
);
if
(
options
.
log
>
2
)
if
(
options
.
log
>
1
)
printf
(
"
forwarded %d / %d bytes from remote to local
\n
"
,
count_recv
,
count_sent
);
printf
(
"
sent %d
\t
%s:%d
\t
pid:
\n
"
,
ntohs
(
client_addr
.
sin_port
),
inet_ntoa
(
client_addr
.
sin_addr
),
getpid
()
);
}
}
}
}
...
...
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