Commit 16dd4b2a authored by John Selbie's avatar John Selbie

latest stuff

parent 905f2f46
include ../common.inc
%.txtcode: %.txt
sh makecodefile.sh $^ $@ $(*)_text
%.txt: %.md
pandoc --no-wrap -s -w plain -o $@ $^
%.1: %.md
pandoc -s -w man -o $@ $^
all: stunserver.txtcode README stunclient.txtcode stunserver.1 stunclient.1
README: readme.src
../stuntestcode --pp < readme.src > README
clean:
rm -f *.txtcode *.txt README *.1
#
# 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
% STUNCLIENT(1) January 22, 2012 | User Manual
# NAME
stunclient \- command line app for the STUN protocol
# SYNOPSIS
**stunclient** [OPTIONS] server [port]
#DESCRIPTION
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.
# OPTIONS
The following options are supported.
--mode MODE
--localaddr INTERFACE
--localport PORTNUMBER
--family IPVERSION
--protocol PROTO
--verbosity LOGLEVEL
--help
Details of each option and paramters are as follows.
**server**
The **server** parameter is the IP address or FQDN of the remote server to befrom the binding tests with. It is the only required parameter.
_____
**port**
The **port** parameter is an optional parameter that can follow the server parameter. The default is 3478 for UDP and TCP.
_____
**--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.
____
**--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 for responses 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 available port chosen by the system is used.
____
**--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
# AUTHOR
john selbie (jselbie@gmail.com)
.TH STUNSERVER 1 "Version 1.1" STUNSERVER "User Manuals"
.SH NAME
stunserver \- STUN protocol service (RFC 5389 and RFC 3489)
.SH SYNOPSIS
stunserver [OPTIONS]
.SH DESCRIPTION
stunserver starts a STUN listening service that responds to STUN binding
requests from remote clients. Options are described below.
.SH OPTIONS
% STUNSERVER(1) January 22, 2012 | User Manual
# NAME
stunserver \- STUN protocol service (RFCs: 3489, 5389, 5789, 5780)
# SYNOPSIS
**stunserver** [OPTIONS]
#DESCRIPTION
stunserver starts a STUN listening service that responds to STUN binding requests from remote
clients. Options are described below.
# OPTIONS
The following options are supported.
.\" indent by 4
.in +4
--mode MODE
.br
--primaryinterface INTERFACE
.br
--altinterface INTERFACE
.br
--primaryport PORTNUMBER
.br
--altport PORTNUMBER
.br
--family IPVERSION
.br
--protocol PROTO
.br
--maxconn MAXCONN
.br
--help
.\" restore indentation
.in
--mode MODE
--primaryinterface INTERFACE
--altinterface INTERFACE
--primaryport PORTNUMBER
--altport PORTNUMBER
--family IPVERSION
--protocol PROTO
--maxconn MAXCONN
--verbosity LOGLEVEL
--help
Details of each option are as follows.
--mode MODE
.br
Where the MODE parameter specified is either "basic" or "full".
**--mode** MODE
Where the MODE parameter specified is either "basic" or "full".
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
......@@ -49,11 +46,14 @@ 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.
If this parameter is not specified, basic mode is the default.
--primaryinterface INTERFACE
.br
____
**--primaryinterface** INTERFACE
Where INTERFACE specified is either a local IP address (e.g. "192.168.1.2")
of the host or the name of a network interface (e.g. "eth0").
......@@ -64,8 +64,11 @@ 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.
--altinterface INTERFACE OR IPADDRESS
.br
____
**--altinterface** INTERFACE OR IPADDRESS
Where INTERFACE specified is either a local IP address (e.g. "192.168.1.3")
of the host or the name of a network interface (e.g. "eth1").
......@@ -75,8 +78,11 @@ that it specifies the alternate listening address for full mode.
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.
--primaryport PORTNUM
.br
____
**--primaryport** PORTNUM
Where PORTNUM is a value between 1 to 65535.
This is the primary port the server will bind to for listening for incoming
......@@ -85,8 +91,11 @@ alternate address to this port.
The default is 3478.
--altport PORTNUM
.br
____
**--altport** PORTNUM
Where PORTNUM is a value between 1 to 65535.
This is the alternate port the server will bind to for listening for incoming
......@@ -95,29 +104,39 @@ alternate address to this port.
This option is ignored in basic mode. The default is 3479.
--family IPVERSION
.br
____
**--family** IPVERSION
Where IPVERSION is either "4" or "6" to specify the usage of IPV4 or IPV6.
The default family is 4 for IPv4 usage.
--protocol PROTO
.br
____
**--protocol** PROTO
Where PROTO is either IP protocol, "udp" or "tcp".
udp is the default.
--maxconn MAXCONN
.br
____
**--maxconn** MAXCONN
Where MAXCONN is a value between 1 and 100000.
For TCP mode, this parameter specifies the maximum number of simultaneous
connections that can exist at any given time.
This parameter is ignored when the protocol is UDP.
This parameter is ignored when the protocol is UDP. The default value is 1000
____
**--verbosity** LOGLEVEL
--verbosity LOGLEVEL
.br
Where LOGLEVEL is a value greater than or equal to 0.
This parameter specifies how much is printed to the console with regards to
......@@ -127,40 +146,37 @@ very minimal amount of output. A value of 1 shows slightly more. A value of
The default is 0.
--help
.br
____
**--help**
Prints this help page
.SH EXAMPLES
stunserver
With no options, starts a basic STUN binding service on UDP port 3478.
# EXAMPLES
stunserver
: With no options, starts a basic STUN binding service on UDP port 3478.
stunserver --mode full --primaryinterface 128.34.56.78 --altinterface 128.34.56.79
: Above example starts a dual-host STUN service on the the interfaces
identified by the IP address "128.34.56.78" and "128.34.56.79". There are
four UDP socket listeners
Above example starts a dual-host STUN service on the the interfaces
identified by the IP address "128.34.56.78" and "128.34.56.79". There are
four UDP socket listeners:
.in +4
128.34.56.78:3478 (Primary IP, Primary Port)
.br
128.34.56.78:3479 (Primary IP, Alternate Port)
.br
128.34.56.79:3478 (Primary IP, Primary Port)
.br
128.34.56.79:3479 (Alternate IP, Alternate Port)
.in
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)
An error occurs if the addresses specified do not exist on the local host
running the service.
.br
stunserver --mode full --primaryinterface eth0 --altinterface eth1
Same as above, except the interfaces are specified by their names as
enumerated by the system. (The "ifconfig" or "ipconfig" command will
enumerate available interface names.
stunserver --mode full --primaryinterface eth0 --altinterface eth1
: Same as above, except the interfaces are specified by their names as
enumerated by the system. (The "ifconfig" or "ipconfig" command will
enumerate available interface names.
.SH AUTHOR
# AUTHOR
john selbie (jselbie@gmail.com)
#!/usr/bin/perl
# xxdperl.pl
# emulates "xxd -i" in perl (stdin and stdout only)
$count = 0;
while ($input = <STDIN>) {
@characters = split(//, $input);
foreach (@characters) {
if ($count != 0) {
print ',';
if (($count % 12)==0) {
print "\n ";
}
}
else {
print ' ';
}
print sprintf(" 0x%.2x", ord($_));
$count++;
}
}
......@@ -213,6 +213,7 @@ HRESULT CStunRequestHandler::ProcessBindingRequest()
CSocketAddress addrOther;
CStunMessageBuilder builder;
uint16_t paddingSize = 0;
HRESULT hrResult;
_pMsgOut->spBufferOut->SetSize(0);
......@@ -243,7 +244,10 @@ HRESULT CStunRequestHandler::ProcessBindingRequest()
}
// handle change request logic and figure out what "other-address" attribute is going to be
if (SUCCEEDED(reader.GetChangeRequest(&changerequest)))
// Some clients (like jstun) will send a change-request attribute with neither the IP or PORT flag set
// So ignore this block of code in that case (because the fConnectionOriented check below could fail)
hrResult = reader.GetChangeRequest(&changerequest);
if (SUCCEEDED(hrResult) && (changerequest.fChangeIP || changerequest.fChangePort))
{
if (changerequest.fChangeIP)
{
......
......@@ -113,6 +113,8 @@ bool CBasicBindingTest::IsReadyToRun()
HRESULT CBasicBindingTest::GetMessage(CRefCountedBuffer& spMsg, CSocketAddress* pAddrDest)
{
StunChangeRequestAttribute attribChangeRequest = {};
HRESULT hr = S_OK;
ASSERT(spMsg->GetAllocatedSize() > 0);
ASSERT(pAddrDest);
......@@ -122,6 +124,9 @@ HRESULT CBasicBindingTest::GetMessage(CRefCountedBuffer& spMsg, CSocketAddress*
builder.GetStream().Attach(spMsg, true);
Chk(StartBindingRequest(builder));
builder.AddChangeRequest(attribChangeRequest); // adding a blank CHANGE-REQUEST, because a JSTUN server will not respond if the request doesn't have one
builder.FixLengthField();
*pAddrDest = _pConfig->addrServer;
......@@ -234,10 +239,15 @@ HRESULT CBehaviorTest::GetMessage(CRefCountedBuffer& spMsg, CSocketAddress* pAdd
HRESULT hr = S_OK;
ASSERT(spMsg->GetAllocatedSize() > 0);
ASSERT(pAddrDest);
StunChangeRequestAttribute attribChangeRequest = {};
CStunMessageBuilder builder;
builder.GetStream().Attach(spMsg, true);
StartBindingRequest(builder);
builder.AddChangeRequest(attribChangeRequest); // adding a blank CHANGE-REQUEST, because a JSTUN server will not respond if the request doesn't have one
builder.FixLengthField();
if (_fIsTest3 == false)
......
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