Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
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
esp
mongoose
Commits
81933021
Commit
81933021
authored
Oct 16, 2017
by
Бобби
Committed by
Cesanta Bot
Oct 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial socks5 client & server implementation
PUBLISHED_FROM=05d3cca6223c963e7ae89dde3628fa8fad46e6bd
parent
6e3e5560
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
512 additions
and
5 deletions
+512
-5
Makefile
examples/socks_server/Makefile
+5
-0
socks_server.c
examples/socks_server/socks_server.c
+32
-0
mongoose.c
mongoose.c
+405
-5
mongoose.h
mongoose.h
+70
-0
No files found.
examples/socks_server/Makefile
0 → 100644
View file @
81933021
PROG
=
socks_server
# NOTE(lsm): -DMG_ENABLE_IPV6 won't work for the mingw build
MODULE_CFLAGS
=
-DMG_ENABLE_SOCKS
=
1
# -DMG_ENABLE_DEBUG=1
#SSL_LIB=openssl
include
../examples.mk
examples/socks_server/socks_server.c
0 → 100644
View file @
81933021
/*
* Copyright (c) 2017 Cesanta Software Limited
* All rights reserved
*
* Use curl to test, e.g.
* curl -i --socks5 127.0.0.1:1080 www.met.ie
*/
#include "mongoose.h"
static
const
char
*
s_listening_addr
=
"1080"
;
int
main
(
void
)
{
struct
mg_mgr
mgr
;
struct
mg_connection
*
c
;
mg_mgr_init
(
&
mgr
,
NULL
);
if
((
c
=
mg_bind
(
&
mgr
,
s_listening_addr
,
NULL
))
==
NULL
)
{
fprintf
(
stderr
,
"mg_bind(%s) failed
\n
"
,
s_listening_addr
);
exit
(
EXIT_FAILURE
);
}
mg_set_protocol_socks
(
c
);
printf
(
"Starting socks5 proxy server on %s
\n
"
,
s_listening_addr
);
for
(;;)
{
mg_mgr_poll
(
&
mgr
,
1000
);
}
mg_mgr_free
(
&
mgr
);
return
0
;
}
mongoose.c
View file @
81933021
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
81933021
...
...
@@ -3029,6 +3029,10 @@ struct { \
#define MG_ENABLE_MQTT 1
#endif
#ifndef MG_ENABLE_SOCKS
#define MG_ENABLE_SOCKS 0
#endif
#ifndef MG_ENABLE_MQTT_BROKER
#define MG_ENABLE_MQTT_BROKER 0
#endif
...
...
@@ -6032,3 +6036,69 @@ struct mg_connection *mg_sntp_get_time(struct mg_mgr *mgr,
#endif
#endif
/* CS_MONGOOSE_SRC_SNTP_H_ */
#ifdef MG_MODULE_LINES
#line 1 "mongoose/src/socks.h"
#endif
/*
* Copyright (c) 2017 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_SRC_SOCKS_H_
#define CS_MONGOOSE_SRC_SOCKS_H_
#if MG_ENABLE_SOCKS
#define MG_SOCKS_VERSION 5
/* SOCKS5 handshake methods */
enum
mg_socks_handshake_method
{
MG_SOCKS_HANDSHAKE_NOAUTH
=
0
,
/* Handshake method - no authentication */
MG_SOCKS_HANDSHAKE_GSSAPI
=
1
,
/* Handshake method - GSSAPI auth */
MG_SOCKS_HANDSHAKE_USERPASS
=
2
,
/* Handshake method - user/password auth */
MG_SOCKS_HANDSHAKE_FAILURE
=
0xff
,
/* Handshake method - failure */
};
/* SOCKS5 commands */
enum
mg_socks_command
{
MG_SOCKS_CMD_CONNECT
=
1
,
/* Command: CONNECT */
MG_SOCKS_CMD_BIND
=
2
,
/* Command: BIND */
MG_SOCKS_CMD_UDP_ASSOCIATE
=
3
,
/* Command: UDP ASSOCIATE */
};
/* SOCKS5 address types */
enum
mg_socks_address_type
{
MG_SOCKS_ADDR_IPV4
=
1
,
/* Address type: IPv4 */
MG_SOCKS_ADDR_DOMAIN
=
3
,
/* Address type: Domain name */
MG_SOCKS_ADDR_IPV6
=
4
,
/* Address type: IPv6 */
};
/* SOCKS5 response codes */
enum
mg_socks_response
{
MG_SOCKS_SUCCESS
=
0
,
/* Response: success */
MG_SOCKS_FAILURE
=
1
,
/* Response: failure */
MG_SOCKS_NOT_ALLOWED
=
2
,
/* Response: connection not allowed */
MG_SOCKS_NET_UNREACHABLE
=
3
,
/* Response: network unreachable */
MG_SOCKS_HOST_UNREACHABLE
=
4
,
/* Response: network unreachable */
MG_SOCKS_CONN_REFUSED
=
5
,
/* Response: network unreachable */
MG_SOCKS_TTL_EXPIRED
=
6
,
/* Response: network unreachable */
MG_SOCKS_CMD_NOT_SUPPORTED
=
7
,
/* Response: network unreachable */
MG_SOCKS_ADDR_NOT_SUPPORTED
=
8
,
/* Response: network unreachable */
};
#ifdef __cplusplus
extern
"C"
{
#endif
/* __cplusplus */
/* Turn the connection into the SOCKS server */
void
mg_set_protocol_socks
(
struct
mg_connection
*
c
);
/* Create socks tunnel for the client connection */
struct
mg_iface
*
mg_socks_mk_iface
(
struct
mg_mgr
*
,
const
char
*
proxy_addr
);
#ifdef __cplusplus
}
#endif
/* __cplusplus */
#endif
#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