Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
Project
Project
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
b0696c44
Commit
b0696c44
authored
Jun 16, 2010
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better C proxy host resolution.
Use getaddrinfo instead of gethostbyname.
parent
f2898eab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
websocket.c
utils/websocket.c
+27
-11
wsproxy.c
utils/wsproxy.c
+5
-10
No files found.
utils/websocket.c
View file @
b0696c44
...
@@ -12,8 +12,8 @@
...
@@ -12,8 +12,8 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <openssl/err.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <openssl/ssl.h>
#include <resolv.h>
/* base64 encode/decode */
#include <resolv.h>
/* base64 encode/decode */
...
@@ -55,6 +55,30 @@ void fatal(char *msg)
...
@@ -55,6 +55,30 @@ void fatal(char *msg)
exit
(
1
);
exit
(
1
);
}
}
/* resolve host with also IP address parsing */
int
resolve_host
(
struct
in_addr
*
sin_addr
,
const
char
*
hostname
)
{
if
(
!
inet_aton
(
hostname
,
sin_addr
))
{
struct
addrinfo
*
ai
,
*
cur
;
struct
addrinfo
hints
;
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_family
=
AF_INET
;
if
(
getaddrinfo
(
hostname
,
NULL
,
&
hints
,
&
ai
))
return
-
1
;
for
(
cur
=
ai
;
cur
;
cur
=
cur
->
ai_next
)
{
if
(
cur
->
ai_family
==
AF_INET
)
{
*
sin_addr
=
((
struct
sockaddr_in
*
)
cur
->
ai_addr
)
->
sin_addr
;
freeaddrinfo
(
ai
);
return
0
;
}
}
freeaddrinfo
(
ai
);
return
-
1
;
}
return
0
;
}
/*
/*
* SSL Wrapper Code
* SSL Wrapper Code
*/
*/
...
@@ -331,7 +355,6 @@ void start_server(int listen_port,
...
@@ -331,7 +355,6 @@ void start_server(int listen_port,
char
*
listen_host
)
{
char
*
listen_host
)
{
int
lsock
,
csock
,
clilen
,
sopt
=
1
,
i
;
int
lsock
,
csock
,
clilen
,
sopt
=
1
,
i
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
struct
sockaddr_in
serv_addr
,
cli_addr
;
struct
hostent
*
lhost
;
ws_ctx_t
*
ws_ctx
;
ws_ctx_t
*
ws_ctx
;
/* Initialize buffers */
/* Initialize buffers */
...
@@ -355,15 +378,8 @@ void start_server(int listen_port,
...
@@ -355,15 +378,8 @@ void start_server(int listen_port,
if
((
listen_host
==
NULL
)
||
(
listen_host
[
0
]
==
'\0'
))
{
if
((
listen_host
==
NULL
)
||
(
listen_host
[
0
]
==
'\0'
))
{
serv_addr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
serv_addr
.
sin_addr
.
s_addr
=
INADDR_ANY
;
}
else
{
}
else
{
lhost
=
gethostbyname
(
listen_host
);
if
(
resolve_host
(
&
serv_addr
.
sin_addr
,
listen_host
)
<
-
1
)
{
if
(
lhost
==
NULL
)
{
fatal
(
"Could not resolve listen address"
);
fatal
(
"Could not resolve self address"
);
}
bcopy
((
char
*
)
lhost
->
h_addr
,
(
char
*
)
&
serv_addr
.
sin_addr
.
s_addr
,
lhost
->
h_length
);
for
(
i
=
0
;
i
<
strlen
(
lhost
->
h_addr
);
i
++
)
{
printf
(
"%d: %d
\n
"
,
i
,
lhost
->
h_addr
[
i
]);
}
}
}
}
...
...
utils/wsproxy.c
View file @
b0696c44
...
@@ -193,7 +193,6 @@ void do_proxy(ws_ctx_t *ws_ctx, int target) {
...
@@ -193,7 +193,6 @@ void do_proxy(ws_ctx_t *ws_ctx, int target) {
void
proxy_handler
(
ws_ctx_t
*
ws_ctx
)
{
void
proxy_handler
(
ws_ctx_t
*
ws_ctx
)
{
int
tsock
=
0
;
int
tsock
=
0
;
struct
sockaddr_in
taddr
;
struct
sockaddr_in
taddr
;
struct
hostent
*
thost
;
printf
(
"Connecting to: %s:%d
\n
"
,
target_host
,
target_port
);
printf
(
"Connecting to: %s:%d
\n
"
,
target_host
,
target_port
);
...
@@ -202,19 +201,15 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
...
@@ -202,19 +201,15 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
error
(
"Could not create target socket"
);
error
(
"Could not create target socket"
);
return
;
return
;
}
}
thost
=
gethostbyname
(
target_host
);
if
(
thost
==
NULL
)
{
error
(
"Could not resolve server"
);
close
(
tsock
);
return
;
}
bzero
((
char
*
)
&
taddr
,
sizeof
(
taddr
));
bzero
((
char
*
)
&
taddr
,
sizeof
(
taddr
));
taddr
.
sin_family
=
AF_INET
;
taddr
.
sin_family
=
AF_INET
;
bcopy
((
char
*
)
thost
->
h_addr
,
(
char
*
)
&
taddr
.
sin_addr
.
s_addr
,
thost
->
h_length
);
taddr
.
sin_port
=
htons
(
target_port
);
taddr
.
sin_port
=
htons
(
target_port
);
/* Resolve target address */
if
(
resolve_host
(
&
taddr
.
sin_addr
,
target_host
)
<
-
1
)
{
fatal
(
"Could not resolve target address"
);
}
if
(
connect
(
tsock
,
(
struct
sockaddr
*
)
&
taddr
,
sizeof
(
taddr
))
<
0
)
{
if
(
connect
(
tsock
,
(
struct
sockaddr
*
)
&
taddr
,
sizeof
(
taddr
))
<
0
)
{
error
(
"Could not connect to target"
);
error
(
"Could not connect to target"
);
close
(
tsock
);
close
(
tsock
);
...
...
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