Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
1779fee2
Commit
1779fee2
authored
14 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Turn select() usage in tor-fw-helper into a function.
parent
a6dc00fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tools/tor-fw-helper/tor-fw-helper-natpmp.c
+28
-25
28 additions, 25 deletions
src/tools/tor-fw-helper/tor-fw-helper-natpmp.c
with
28 additions
and
25 deletions
src/tools/tor-fw-helper/tor-fw-helper-natpmp.c
+
28
−
25
View file @
1779fee2
...
...
@@ -80,6 +80,29 @@ tor_natpmp_cleanup(tor_fw_options_t *tor_fw_options, void *backend_state)
return
r
;
}
/** Use select() to wait until we can read on fd. */
static
int
wait_until_fd_readable
(
int
fd
,
struct
timeval
*
timeout
)
{
int
r
;
fd_set
fds
;
if
(
fd
>=
FD_SETSIZE
)
{
fprintf
(
stderr
,
"E: NAT-PMP FD_SETSIZE error %d
\n
"
,
fd
);
return
-
1
;
}
FD_ZERO
(
&
fds
);
FD_SET
(
fd
,
&
fds
);
r
=
select
(
fd
+
1
,
&
fds
,
NULL
,
NULL
,
timeout
);
if
(
r
==
-
1
)
{
fprintf
(
stdout
,
"V: select failed in wait_until_fd_readable: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
/* XXXX we should really check to see whether fd was readable, or we timed
out. */
return
0
;
}
/** Add a TCP port mapping for a single port stored in <b>tor_fw_options</b>
* using the <b>natpmp_t</b> stored in <b>backend_state</b>. */
int
...
...
@@ -91,7 +114,6 @@ tor_natpmp_add_tcp_mapping(tor_fw_options_t *tor_fw_options,
int
x
=
0
;
int
sav_errno
;
fd_set
fds
;
struct
timeval
timeout
;
if
(
tor_fw_options
->
verbose
)
...
...
@@ -105,16 +127,10 @@ tor_natpmp_add_tcp_mapping(tor_fw_options_t *tor_fw_options,
"returned %d (%s)
\n
"
,
r
,
r
==
12
?
"SUCCESS"
:
"FAILED"
);
do
{
FD_ZERO
(
&
fds
);
FD_SET
(
state
->
natpmp
.
s
,
&
fds
);
getnatpmprequesttimeout
(
&
(
state
->
natpmp
),
&
timeout
);
x
=
select
(
FD_SETSIZE
,
&
fds
,
NULL
,
NULL
,
&
timeout
);
x
=
wait_until_fd_readable
(
state
->
natpmp
.
s
,
&
timeout
);
if
(
x
==
-
1
)
{
fprintf
(
stdout
,
"V: select failed in "
"tor_natpmp_fetch_public_ip.
\n
"
);
return
-
1
;
}
return
-
1
;
if
(
tor_fw_options
->
verbose
)
fprintf
(
stdout
,
"V: attempting to readnatpmpreponseorretry...
\n
"
);
...
...
@@ -166,30 +182,17 @@ tor_natpmp_fetch_public_ip(tor_fw_options_t *tor_fw_options,
natpmp_state_t
*
state
=
(
natpmp_state_t
*
)
backend_state
;
struct
timeval
timeout
;
fd_set
fds
;
r
=
sendpublicaddressrequest
(
&
(
state
->
natpmp
));
fprintf
(
stdout
,
"tor-fw-helper: NAT-PMP sendpublicaddressrequest returned"
" %d (%s)
\n
"
,
r
,
r
==
2
?
"SUCCESS"
:
"FAILED"
);
do
{
if
(
state
->
natpmp
.
s
>=
FD_SETSIZE
)
{
fprintf
(
stderr
,
"E: NAT-PMP FD_SETSIZE error %d
\n
"
,
state
->
natpmp
.
s
);
return
-
1
;
}
FD_ZERO
(
&
fds
);
FD_SET
(
state
->
natpmp
.
s
,
&
fds
);
getnatpmprequesttimeout
(
&
(
state
->
natpmp
),
&
timeout
);
x
=
select
(
FD_SETSIZE
,
&
fds
,
NULL
,
NULL
,
&
timeout
);
x
=
wait_until_fd_readable
(
state
->
natpmp
.
s
,
&
timeout
);
if
(
x
==
-
1
)
{
fprintf
(
stdout
,
"V: select failed in "
"tor_natpmp_fetch_public_ip.
\n
"
);
return
-
1
;
}
return
-
1
;
if
(
tor_fw_options
->
verbose
)
fprintf
(
stdout
,
"V: NAT-PMP attempting to read reponse...
\n
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment