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
1458192b
Commit
1458192b
authored
Sep 18, 2024
by
Michael Pastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy sock exp
parent
d020106a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
6 deletions
+57
-6
src/bytevia.c
+57
-6
No files found.
src/bytevia.c
View file @
1458192b
...
...
@@ -353,6 +353,11 @@ int use(void)
for
(;;)
{
int
proxy_sock
;
struct
sockaddr_in
proxy_addr
;
struct
sockaddr_in
proxy_addr2
;
int
proxy_port
=
1234
;
FD_ZERO
(
&
io
);
FD_SET
(
rc
.
client_socket
,
&
io
);
FD_SET
(
rc
.
remote_socket
,
&
io
);
...
...
@@ -365,6 +370,27 @@ int use(void)
break
;
}
if
(
options
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
if
((
proxy_sock
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
))
<
0
)
{
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
))
{
/* Processing request from local, sending it to remote*/
...
...
@@ -388,9 +414,21 @@ int use(void)
decode
(
buffer
,
count_recv
)
:
encode
(
buffer
,
count_recv
);
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
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
count_sent
=
sendto
(
proxy_sock
,
buffer
,
count_recv
,
0
,
(
struct
sockaddr
*
)
&
rc
.
remote_addr
,
sizeof
(
rc
.
remote_addr
));
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
)
printf
(
"forwarded %d / %d bytes from local to remote
\n
"
,
count_recv
,
count_sent
);
...
...
@@ -399,9 +437,22 @@ int use(void)
if
(
FD_ISSET
(
rc
.
remote_socket
,
&
io
))
{
/* Processing response from remote, sending it back to local */
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
(
options
.
mode
==
MODE_SERVER
&&
options
.
proto
==
SOCK_DGRAM
)
{
/* EXPERIMENTAL */
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
)
{
perror
(
"use: recv(rc.remote_socket)"
);
...
...
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