stun client java实现_stun 协议客户端实现

/*

* 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值