Commit 9b32eee4 authored by John Selbie's avatar John Selbie

resource compile changes

parent 16dd4b2a
......@@ -3,7 +3,6 @@ nbproject/
*.o
*.gch
*.a
*.txtcode
callgrind.out.*
stunclient
......
......@@ -3,9 +3,8 @@ include ../common.inc
PROJECT_TARGET := stunclient
PROJECT_OBJS := clientmain.o
PROJECT_INTERMEDIATES := usage.txtcode usagelite.txtcode
INCLUDES := $(BOOST_INCLUDE) -I../common -I../stuncore -I../networkutils
INCLUDES := $(BOOST_INCLUDE) -I../common -I../stuncore -I../networkutils -I../resources
LIB_PATH := -L../common -L../stuncore -L../networkutils
LIBS := -lnetworkutils -lstuncore -lcommon -lcrypto
......@@ -13,14 +12,9 @@ LIBS := -lnetworkutils -lstuncore -lcommon -lcrypto
all: $(PROJECT_TARGET)
clean:
rm -f $(PROJECT_OBJS) $(PROJECT_TARGET) $(PROJECT_INTERMEDIATES)
rm -f $(PROJECT_OBJS) $(PROJECT_TARGET)
$(PROJECT_TARGET): $(PROJECT_OBJS)
$(LINK.cpp) -o $@ $^ $(LIB_PATH) $(LIBS)
clientmain.cpp: usage.txtcode usagelite.txtcode
%.txtcode: %.txt
sh ../server/makecodefile.sh $< $@ $(*)_text
......@@ -28,9 +28,9 @@
#include "oshelper.h"
#include "prettyprint.h"
// unusual to include usage.cpp and usagelite.cpp here, but these are auto-generated resource file
#include "usage.txtcode"
#include "usagelite.txtcode"
// These files are in ../resources
#include "stunclient.txtcode"
#include "stunclient_lite.txtcode"
struct ClientCmdLineArgs
......@@ -74,7 +74,7 @@ void DumpConfig(StunClientLogicConfig& config, ClientSocketConfig& socketConfig)
void PrintUsage(bool fSummaryUsage)
{
size_t width = GetConsoleWidth();
const char* psz = fSummaryUsage ? usagelite_text : usage_text;
const char* psz = fSummaryUsage ? stunclient_lite_text : stunclient_text;
// save some margin space
if (width > 2)
......
Usage: stunclient [OPTIONS] server [port]
Perform a binding test with a remote STUN server and optionally perform a full behavior test
Parameters:
"server" is the IP address or FQDN of the remote server to befrom the binding tests with. It is the only required paramter
"port" is an optional paramter that can follow the server paramter. The default is 3478 for UDP and TCP.
Available options:
--localaddr = INTERFACE OR IPADDRESS
The value for this option may the name of an interface (such as "eth0" or "lo"). Or it may be one of the available IP addresses assigned to a network interface present on the host (such as "128.23.45.67"). The interface chosen will be the preferred address for sending and receiving responses with the remote server. The default is to let the system decide which address to send on and to listen on all addresses (INADDR_ANY).
--localport=PORTNUM
PORTNUM is a value between 1 to 65535. This is the UDP or TCP port that the primary and alternate interfaces listen on as the primary port for binding requests. If not specified, a randomly avaialbe port chosed by the system is used.
--mode=MODE
Where MODE is either "basic" or "full". "basic" mode is the default and indicates that the client should perform a STUN binding test only. "full" mode indicates that the client should attempt to diagnose NAT behavior and filtering methodologies if the server supports this mode. The NAT filtering test is only supported for UDP.
--family=IPVERSION
IPVERSION is either "4" or "6" to specify the usage of IPV4 or IPV6. If not specified, the default value is "4".
--protocol=PROTO
PROTO is either "udp" or "tcp". "udp" is the default if this parameter is not specified
--verbosity=LOGLEVEL
Sets the verbosity of the logging level. 0 is the default (minimal output and logging). 1 shows slightly more. 2 and higher shows even more.
--help
Prints this help page
Examples:
stunclient stunserver.org 3478
Performs a simple binding test request with the server listening at "stunserver.org"
stunclient --mode full --localport 9999 12.34.56.78
Performs a full set of UDP NAT behavior tests from local port 9999 to the server listening at IP Address 12.34.56.78 (port 3478)
stunclient --protocol tcp stun.selbie.com
Performs a simple binding test using TCP to server listening on the default port of 3478 at stun.selbie.com
......@@ -12,12 +12,17 @@ include ../common.inc
pandoc -s -w man -o $@ $^
all: stunserver.txtcode README stunclient.txtcode stunserver.1 stunclient.1
all:
@echo "specify one of the following make options: textres manpages README or clean"
README: readme.src
textres: stunserver.txtcode stunserver_lite.txtcode stunclient.txtcode stunclient_lite.txtcode
manpages: stunserver.1 stunclient.1
README:
../stuntestcode --pp < readme.src > README
clean:
rm -f *.txtcode *.txt README *.1
rm -f *.txtcode README *.1
StunServer version 1.1.0
January 22, 2012
---------------------------------------------------------
Features:
Compliant with the latest RFCs including 5389, 5769, and 5780. Also includes
backwards compatibility for RFC 3489.
Supports both UDP and TCP on both IPv4 and IPv6.
Client test app provided.
Stun server can operate in "full" mode as well as "basic" mode. Basic mode
configures the server to listen on one port and respond to STUN binding
requests. Full mode configures the service to listen on two different IP
address interfaces (if available) and provide NAT behavior and filtering
detection support for clients.
Open source Apache license. See LICENSE file fore more details.
---------------------------------------------------------
Known issues:
TLS mode has yet to be implemented.
Server does not honor the stun padding attribute. If someone really wants
this support, let me know and I will consider adding it.
By default, the stun server operates in an open mode without performing
authentication. All the code for authentication, challenge-response, message
hashing, and message integrity attributes are fully coded. HMAC/SHA1/MD5
hashing code for generating and validating the message integrity attribute
has been implemented and tested. However, the code for validating a username
or looking up a password is outside the scope of this release. Instead,
hooks are provided for implementors to write their own code to validate a
username, fetch a password, and allow/deny a request. Details of writing
your own authentication provider code are described in the file
"server/sampleauthprovider.h".
Dependency checking is not implemented in the Makefile. So if you need to
recompile, I recommend "make clean" from the root to preceed any subsequent
"make" call.
If you run an instance of stunserver locally, you may observe that
"stunclient localhost" may not successfully work. This is because the server
is not listening on the loopback adapter when running in full mode. The
workaround is to specify the actual IP address that the server is listening
on. Type "ifconfig" to discover your IP address (e.g. 10.11.12.13) followed
by "stunclient 10.11.12.13"
---------------------------------------------------------
Testing:
Fedora 15 with gcc/g++ 4.6.0
Ubuntu 11 with gcc/g++ 4.5.2
Amazon AWS with gcc/g++ 4.4
MacOS Snow Leopard (will not compile on earlier versions without updating to
a newer version of gcc/g++)
Parsing code has been fuzz tested with zzuf. http://caca.zoy.org/wiki/zzuf
---------------------------------------------------------
Prerequisites before compiling and running.
perl. Just have any old version installed. It is needed for one particular
build script.
Boost header files. (Actual boost runtime not required) www.boost.org (sudo
yum install boost-devel)
OpenSSL development files and runtime. www.boost.org (sudo yum install
openssl-devel)
pthreads header and libs (I haven't seen a distribution where this wasn't
already installed)
---------------------------------------------------------
Compiling and running
Got Boost and OpenSSL taken care of as described above? Good. Just type
"make". There will be three resulting binaries in the root of the source
code package produced.
stuntestcode - This is the unit test code. I highly recommend you run this
program first. When run, you'll see a series of lines being printed in
regards to different code paths being tested. If you see any line that ends
in "FAIL", we likely have a bug. Please contact me immediately if you see
this.
stunserver - this is the server binary. Run "./stunserver --help" for
details on running this program. Running this program without any command
line arguments defaults to listening on port 3478 on all adapters.
stunclient - this is the client test binary. Run "./stunclient --help" for
details on running this program. Example: "./stunclient stun.selbie.com"
---------------------------------------------------------
Firewall
Don't forget to configure your firewall to allow traffic for the local ports
the stunserver will be listening on!
---------------------------------------------------------
Feature roadmap (the features I want to implement in a subsequent release)
Host a full server across two separate machines (such that two ip addresses
on a single machine will not be required for full mode).
Cleanup Makefile and add "configure" and autotools support
Finish Windows port and able to run as a Windows service
Scale across more than one CPU (for multi-core and multi-proc machines). The
threading code has already been written, just needs some finish work.
TLS support
---------------------------------------------------------
Contact the author
John Selbie
john@selbie.com
.TH STUNCLIENT 1 "" "January 22, 2012" "User Manual"
.SH NAME
.PP
stunclient - command line app for the STUN protocol
.SH SYNOPSIS
.PP
\f[B]stunclient\f[] [OPTIONS] server [port]
.SH DESCRIPTION
.PP
stunclient attempts to discover the local host's own external IP
address, obtain a port mapping, and optionally discover properties
of the Network Address Translator (NAT) between the host and the
the server.
.SH OPTIONS
.PP
The following options are supported.
.PP
\f[CR]
--mode\ MODE
--localaddr\ INTERFACE
--localport\ PORTNUMBER
--family\ IPVERSION
--protocol\ PROTO
--verbosity\ LOGLEVEL
--help
\f[]
.PP
Details of each option and paramters are as follows.
.PP
\f[B]server\f[]
.PP
The \f[B]server\f[] parameter is the IP address or FQDN of the
remote server to befrom the binding tests with.
It is the only required parameter.
.PP
* * * * *
.PP
\f[B]port\f[]
.PP
The \f[B]port\f[] parameter is an optional parameter that can
follow the server parameter.
The default is 3478 for UDP and TCP.
.PP
* * * * *
.PP
\f[B]\[em]mode\f[] MODE
.PP
Where MODE is either \[lq]basic\[rq] or \[lq]full\[rq].
\[lq]basic\[rq] mode is the default and indicates that the client
should perform a STUN binding test only.
\[lq]full\[rq] mode indicates that the client should attempt to
diagnose NAT behavior and filtering methodologies if the server
supports this mode.
The NAT filtering test is only supported for UDP.
.PP
* * * * *
.PP
\f[B]\[em]localaddr\f[] INTERFACE or IPADDRESS
.PP
The value for this option may the name of an interface (such as
\[lq]eth0\[rq] or \[lq]lo\[rq]).
Or it may be one of the available IP addresses assigned to a
network interface present on the host (such as
\[lq]128.23.45.67\[rq]).
The interface chosen will be the preferred address for sending and
receiving responses with the remote server.
The default is to let the system decide which address to send on
and to listen for responses on all addresses (INADDR_ANY).
.PP
* * * * *
.PP
\f[B]\[em]localport\f[] PORTNUM
.PP
PORTNUM is a value between 1 to 65535.
This is the UDP or TCP port that the primary and alternate
interfaces listen on as the primary port for binding requests.
If not specified, a randomly available port chosen by the system is
used.
.PP
* * * * *
.PP
\f[B]\[em]family\f[] IPVERSION
.PP
IPVERSION is either \[lq]4\[rq] or \[lq]6\[rq] to specify the usage
of IPV4 or IPV6.
If not specified, the default value is \[lq]4\[rq].
.PP
* * * * *
.PP
\f[B]\[em]protocol\f[] PROTO
.PP
PROTO is either \[lq]udp\[rq] or \[lq]tcp\[rq].
\[lq]udp\[rq] is the default if this parameter is not specified
.PP
* * * * *
.PP
\f[B]\[em]verbosity\f[] LOGLEVEL
.PP
Sets the verbosity of the logging level.
0 is the default (minimal output and logging).
1 shows slightly more.
2 and higher shows even more.
.PP
* * * * *
.PP
\f[B]\[em]help\f[] Prints this help page
.SH EXAMPLES
.TP
.B stunclient stunserver.org 3478
Performs a simple binding test request with the server listening at
\[lq]stunserver.org\[rq]
.RS
.RE
.TP
.B stunclient \[em]mode full \[em]localport 9999 12.34.56.78
Performs a full set of UDP NAT behavior tests from local port 9999
to the server listening at IP Address 12.34.56.78 (port 3478)
.RS
.RE
.TP
.B stunclient \[em]protocol tcp stun.selbie.com
Performs a simple binding test using TCP to server listening on the
default port of 3478 at stun.selbie.com
.RS
.RE
.SH AUTHOR
.PP
john selbie (jselbie\@gmail.com)
......@@ -79,6 +79,7 @@ ____
**--protocol** PROTO
PROTO is either "udp" or "tcp". "udp" is the default if this parameter is not specified
____
**--verbosity** LOGLEVEL
......
This diff is collapsed.
const char stunclient_lite_text[] = {
0x55, 0x73, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x73, 0x74, 0x75, 0x6e, 0x63,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x5b, 0x4f, 0x50, 0x54, 0x49, 0x4f,
0x4e, 0x53, 0x5d, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x5b,
0x70, 0x6f, 0x72, 0x74, 0x5d, 0x0a, 0x54, 0x72, 0x79, 0x20, 0x27, 0x73,
0x74, 0x75, 0x6e, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x2d, 0x2d,
0x68, 0x65, 0x6c, 0x70, 0x27, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x73, 0x65, 0x74,
0x20, 0x6f, 0x66, 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20,
0x61, 0x6e, 0x64, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x70, 0x61, 0x72, 0x61, 0x6d,
0x74, 0x65, 0x72, 0x73, 0x0a, 0x0a,0x00};
.TH STUNSERVER 1 "" "January 22, 2012" "User Manual"
.SH NAME
.PP
stunserver - STUN protocol service (RFCs: 3489, 5389, 5789, 5780)
.SH SYNOPSIS
.PP
\f[B]stunserver\f[] [OPTIONS]
.SH DESCRIPTION
.PP
stunserver starts a STUN listening service that responds to STUN
binding requests from remote clients.
Options are described below.
.SH OPTIONS
.PP
The following options are supported.
.PP
\f[CR]
--mode\ MODE
--primaryinterface\ INTERFACE
--altinterface\ INTERFACE
--primaryport\ PORTNUMBER
--altport\ PORTNUMBER
--family\ IPVERSION
--protocol\ PROTO
--maxconn\ MAXCONN
--verbosity\ LOGLEVEL
--help
\f[]
.PP
Details of each option are as follows.
.PP
\f[B]\[em]mode\f[] MODE
.PP
Where the MODE parameter specified is either \[lq]basic\[rq] or
\[lq]full\[rq].
In basic mode, the server listens on a single port.
Basic mode is sufficient for basic NAT traversal scenarios in which
a client needs to discover its external IP address and obtain a
port mapping for a local port it is listening on.
The STUN CHANGE-REQUEST attribute is not supported in basic mode.
.PP
In full mode, the STUN service listens on two different interfaces
and two different ports on each.
A client binding request may specify an option for the server to
send the response back from one of the alternate interfaces and/or
ports.
Full mode facilitates clients attempting to discover NAT behavior
and NAT filtering behavior of the network they are on.
Full mode requires two unique IP addresses on the host.
When run over TCP, the service is not able to support a
CHANGE-REQUEST attribute from the client.
.PP
If this parameter is not specified, basic mode is the default.
.PP
* * * * *
.PP
\f[B]\[em]primaryinterface\f[] INTERFACE
.PP
Where INTERFACE specified is either a local IP address (e.g.
\[lq]192.168.1.2\[rq]) of the host or the name of a network
interface (e.g.
\[lq]eth0\[rq]).
.PP
The interface or address specified will be used by the service as
the primary listening address.
.PP
In basic mode, the default is to bind to all available adapters
(INADDR_ANY).
In full mode, the default is to bing to the first non-localhost
adapter with a configured IP address.
.PP
* * * * *
.PP
\f[B]\[em]altinterface\f[] INTERFACE OR IPADDRESS
.PP
Where INTERFACE specified is either a local IP address (e.g.
\[lq]192.168.1.3\[rq]) of the host or the name of a network
interface (e.g.
\[lq]eth1\[rq]).
.PP
This parameter is nearly identical as the \[em]primaryinterface
option except that it specifies the alternate listening address for
full mode.
.PP
This option is ignored in basic mode.
In full mode, the default is to bind to the second non-localhost
adapter with a configured IP address.
.PP
* * * * *
.PP
\f[B]\[em]primaryport\f[] PORTNUM
.PP
Where PORTNUM is a value between 1 to 65535.
.PP
This is the primary port the server will bind to for listening for
incoming binding requests.
The service will bind both the primary address and the alternate
address to this port.
.PP
The default is 3478.
.PP
* * * * *
.PP
\f[B]\[em]altport\f[] PORTNUM
.PP
Where PORTNUM is a value between 1 to 65535.
.PP
This is the alternate port the server will bind to for listening
for incoming binding requests.
The service will bind both the primary address and the alternate
address to this port.
.PP
This option is ignored in basic mode.
The default is 3479.
.PP
* * * * *
.PP
\f[B]\[em]family\f[] IPVERSION
.PP
Where IPVERSION is either \[lq]4\[rq] or \[lq]6\[rq] to specify the
usage of IPV4 or IPV6.
.PP
The default family is 4 for IPv4 usage.
.PP
* * * * *
.PP
\f[B]\[em]protocol\f[] PROTO
.PP
Where PROTO is either IP protocol, \[lq]udp\[rq] or \[lq]tcp\[rq].
.PP
udp is the default.
.PP
* * * * *
.PP
\f[B]\[em]maxconn\f[] MAXCONN
.PP
Where MAXCONN is a value between 1 and 100000.
.PP
For TCP mode, this parameter specifies the maximum number of
simultaneous connections that can exist at any given time.
.PP
This parameter is ignored when the protocol is UDP.
The default value is 1000
.PP
* * * * *
.PP
\f[B]\[em]verbosity\f[] LOGLEVEL
.PP
Where LOGLEVEL is a value greater than or equal to 0.
.PP
This parameter specifies how much is printed to the console with
regards to initialization, errors, and network activity.
A value of 0 specifies a very minimal amount of output.
A value of 1 shows slightly more.
A value of 2 shows even more.
Specifying 3 will show a lot more.
.PP
The default is 0.
.PP
* * * * *
.PP
\f[B]\[em]help\f[]
.PP
Prints this help page
.SH EXAMPLES
.TP
.B stunserver
With no options, starts a basic STUN binding service on UDP port
3478.
.RS
.RE
.TP
.B stunserver \[em]mode full \[em]primaryinterface 128.34.56.78 \[em]altinterface 128.34.56.79
Above example starts a dual-host STUN service on the the interfaces
identified by the IP address \[lq]128.34.56.78\[rq] and
\[lq]128.34.56.79\[rq].
There are four UDP socket listeners
.RS
.PP
128.34.56.78:3478 (Primary IP, Primary Port) 128.34.56.78:3479
(Primary IP, Alternate Port) 128.34.56.79:3478 (Primary IP, Primary
Port) 128.34.56.79:3479 (Alternate IP, Alternate Port)
.RE
.PP
An error occurs if the addresses specified do not exist on the
local host running the service.
.TP
.B stunserver \[em]mode full \[em]primaryinterface eth0 \[em]altinterface eth1
Same as above, except the interfaces are specified by their names
as enumerated by the system.
(The \[lq]ifconfig\[rq] or \[lq]ipconfig\[rq] command will
enumerate available interface names.
.RS
.RE
.SH AUTHOR
.PP
john selbie (john\@selbie.com)
......@@ -178,5 +178,6 @@ stunserver --mode full --primaryinterface eth0 --altinterface eth1
enumerate available interface names.
# AUTHOR
john selbie (jselbie@gmail.com)
john selbie (john@selbie.com)
This diff is collapsed.
Usage: stunserver [OPTION]...
Try 'stunserver --help' for a complete set of options
const char stunserver_lite_text[] = {
0x55, 0x73, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x73, 0x74, 0x75, 0x6e, 0x73,
0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x5b, 0x4f, 0x50, 0x54, 0x49, 0x4f,
0x4e, 0x5d, 0x2e, 0x2e, 0x2e, 0x0a, 0x54, 0x72, 0x79, 0x20, 0x27, 0x73,
0x74, 0x75, 0x6e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x2d, 0x2d,
0x68, 0x65, 0x6c, 0x70, 0x27, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x73, 0x65, 0x74,
0x20, 0x6f, 0x66, 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a,0x00};
......@@ -3,10 +3,7 @@ include ../common.inc
PROJECT_TARGET := stunserver
PROJECT_OBJS := main.o server.o stunconnection.o stunsocketthread.o tcpserver.o
PROJECT_INTERMEDIATES := usage.txtcode usagelite.txtcode
INCLUDES := $(BOOST_INCLUDE) -I../common -I../stuncore -I../networkutils
INCLUDES := $(BOOST_INCLUDE) -I../common -I../stuncore -I../networkutils -I../resources
LIB_PATH := -L../common -L../stuncore -L../networkutils
LIBS := -lnetworkutils -lstuncore -lcommon -pthread -lcrypto
......@@ -14,16 +11,9 @@ LIBS := -lnetworkutils -lstuncore -lcommon -pthread -lcrypto
all: $(PROJECT_TARGET)
clean:
rm -f $(PROJECT_OBJS) $(PROJECT_TARGET) $(PROJECT_INTERMEDIATES)
rm -f $(PROJECT_OBJS) $(PROJECT_TARGET)
$(PROJECT_TARGET): $(PROJECT_OBJS)
$(LINK.cpp) -o $@ $^ $(LIB_PATH) $(LIBS)
main.cpp: usage.txtcode usagelite.txtcode
%.txtcode: %.txt
sh makecodefile.sh $< $@ $(*)_text
......@@ -28,15 +28,15 @@
#include "stringhelper.h"
// unusual to include usage.cpp and usagelite.cpp here, but these are auto-generated resource file
#include "usage.txtcode"
#include "usagelite.txtcode"
// these are auto-generated files made from markdown sources. See ../resources
#include "stunserver.txtcode"
#include "stunserver_lite.txtcode"
void PrintUsage(bool fSummaryUsage)
{
size_t width = GetConsoleWidth();
const char* psz = fSummaryUsage ? usagelite_text : usage_text;
const char* psz = fSummaryUsage ? stunserver_lite_text : stunserver_text;
// save some margin space
if (width > 2)
......
#
# Copyright 2011 John Selbie
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
plfile=`dirname $0`/xxdperl.pl
echo BUILDING $1 INTO $2
echo const char $3[] = { > $2
#xxd -i < $1 >> $2
echo "perl $plfile <" $1 ">>" $2
perl $plfile < $1 >> $2
echo ",0x00};" >> $2
echo "" >> $2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment