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
1d5d6d55
Commit
1d5d6d55
authored
Sep 18, 2024
by
Michael Pastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
5a381fad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
49 deletions
+9
-49
src/bytevia.c
+9
-49
No files found.
src/bytevia.c
View file @
1d5d6d55
...
...
@@ -304,31 +304,6 @@ int build() {
return
0
;
}
int
add_udp_client
(
struct
sockaddr_in
client_addr
,
pid_t
pid
)
{
int
i
;
for
(
i
=
0
;
i
<
MAX_UDP_CLIENTS
;
i
++
)
{
if
(
clients
[
i
].
pid
==
0
)
{
clients
[
i
].
addr
=
client_addr
;
clients
[
i
].
pid
=
pid
;
return
0
;
}
}
return
-
1
;
/* No space for new clients */
}
void
remove_udp_client
(
pid_t
pid
)
{
int
i
;
for
(
i
=
0
;
i
<
MAX_UDP_CLIENTS
;
i
++
)
{
if
(
clients
[
i
].
pid
==
pid
)
{
if
(
options
.
log
)
printf
(
"removing client %s, pid: %d
\n
"
,
inet_ntoa
(
clients
[
i
].
addr
.
sin_addr
),
pid
);
clients
[
i
].
pid
=
0
;
memset
(
&
clients
[
i
].
addr
,
0
,
sizeof
(
clients
[
i
].
addr
));
break
;
}
}
}
int
compare_clients
(
struct
sockaddr_in
client1
,
struct
sockaddr_in
client2
)
{
return
(
client1
.
sin_addr
.
s_addr
==
client2
.
sin_addr
.
s_addr
&&
client1
.
sin_port
==
client2
.
sin_port
);
...
...
@@ -343,13 +318,13 @@ int find_udp_client(struct sockaddr_in client_addr) {
return
-
1
;
}
int
use
(
void
)
int
use
()
{
fd_set
io
;
unsigned
char
buffer
[
options
.
buffer_size
];
struct
sockaddr_in
client_addr
;
socklen_t
addr_len
=
sizeof
(
client_addr
);
int
count_recv
;
//, count_sent;
int
count_recv
;
for
(;;)
{
...
...
@@ -374,7 +349,7 @@ int use(void)
if
(
rc
.
my_addr
.
sin_port
==
0
)
{
rc
.
my_addr
.
sin_addr
.
s_addr
=
client_addr
.
sin_addr
.
s_addr
;
rc
.
my_addr
.
sin_port
=
client_addr
.
sin_port
;
if
(
options
.
log
)
if
(
options
.
log
>
2
)
printf
(
"my address %s:%d
\t
pid: %d
\n
"
,
inet_ntoa
(
client_addr
.
sin_addr
),
ntohs
(
client_addr
.
sin_port
),
getpid
());
}
else
{
if
(
!
compare_clients
(
rc
.
my_addr
,
client_addr
))
{
...
...
@@ -406,7 +381,7 @@ int use(void)
decode
(
buffer
,
count_recv
)
:
encode
(
buffer
,
count_recv
);
/* count_sent = */
(
options
.
proto
==
SOCK_DGRAM
)
?
(
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
);
...
...
@@ -456,26 +431,11 @@ void run() {
void
fork_udp
()
{
#ifndef __MINGW32__
pid_t
child_pid
;
int
client_index
=
find_udp_client
(
rc
.
client_addr
);
if
(
client_index
==
-
1
)
{
if
((
child_pid
=
fork
())
==
0
)
{
if
(
options
.
log
)
printf
(
"request from %s, forking %d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
getpid
());
run
();
exit
(
0
);
}
if
(
add_udp_client
(
rc
.
client_addr
,
child_pid
)
<
0
)
{
printf
(
"maximum clients %d reached:
\n
"
,
MAX_UDP_CLIENTS
);
}
/* Reap any zombie processes (clients that exited) */
while
((
child_pid
=
waitpid
(
-
1
,
NULL
,
WNOHANG
))
>
0
)
{
remove_udp_client
(
child_pid
);
}
}
else
{
if
(
options
.
log
>
2
)
printf
(
"existing udp client %s, handled by %d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
clients
[
client_index
].
pid
);
if
((
child_pid
=
fork
())
==
0
)
{
if
(
options
.
log
)
printf
(
"request from %s, forking %d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
getpid
());
run
();
exit
(
0
);
}
#endif
}
...
...
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