/*
* Spider -- An open source C language toolkit.
*
* Copyright (C) 2011 , Inc.
*
* lidp
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*
* \brief stun client implimentation
*/
#include "stun.h"
#include "logger.h"
/*!
* \brief STUN support code
*
* http://www.ietf.org/rfc/rfc3489.txt
*
* This code provides some support for doing STUN transactions.
* STUN is described in RFC3489 and it is based on the exchange
* of UDP packets between a client and one or more servers to
* determine the externally visible address (and port) of the client
* once it has gone through the NAT boxes that connect it to the
* outside.
* The simplest request packet is just the header defined in
* struct stun_header, and from the response we may just look at
* one attribute, STUN_MAPPED_ADDRESS, that we find in the response.
* By doing more transactions with different server addresses we
* may determine more about the behaviour of the NAT boxes, of
* course - the details are in the RFC.
*
* All STUN packets start with a simple header made of a type,
* length (excluding the header) and a 16-byte random transaction id.
* Following the header we may have zero or more attributes, each
* structured as a type, length and a value (whose format depends
* on the type, but often contains addresses).
* Of course all fields are in network format.
*/
/*! \brief STUN message types
* 'BIND' refers to transactions used to determine the externally
* visible addresses. 'SEC' refers to transactions used to establish
* a session key for subsequent requests.
* 'SEC' functionality is not supported here.
*/
#define STUN_BINDREQ 0x0001
#define STUN_BINDRESP 0x0101
#define STUN_BINDERROR 0x0111
#define STUN_SECREQ 0x0002
#define STUN_SECRESP 0x0102
#define STUN_SECERROR 0x0112
/*! \brief Basic attribute types in stun messages.
* Messages can also contain custom attributes (codes above 0x7fff)
*/
#define STUN_MSG_MAPPED_ADDR 0x0001
#define STUN_MSG_RESPONCE_ADDR 0x0002
#define STUN_MSG_RESPONSE_ADDRESS0x0002
#define STUN_MSG_CHANGE_REQUEST0x0003
#define STUN_MSG_SOURCE_ADDRESS0x0004
#define STUN_MSG_CHANGED_ADDRESS0x0005
#define STUN_MSG_USERNAME0x0006
#define STUN_MSG_PASSWORD0x0007
#define STUN_MSG_INTEGRITY0x0008
#define STUN_MSG_ERROR_CODE0x0009
#define STUN_MSG_UNKNOWN_ATTRIBUTES0x000a
#define STUN_MSG_REFLECTED_FROM0x000b
#define stun_debug 0;
typedef struct { unsigned int id[4]; } __a