Crate stun_client

Source
Expand description

This is a simple async_std based asynchronous STUN client library. At the moment only some features of RFC8489 are implemented and only simple binding requests are possible.

It also supports the OTHER-ADDRESS and CHANGE-REQUEST attributes for RFC5780 -based NAT Behavior Discovery

§Example

use async_std::task;
use stun_client::*;

task::block_on(async {
    let mut client = Client::new("0.0.0.0:0", None).await.unwrap();
    let res = client
        .binding_request("stun.l.google.com:19302", None)
        .await
        .unwrap();
    let class = res.get_class();
    match class {
        Class::SuccessResponse => {
            let xor_mapped_addr = Attribute::get_xor_mapped_address(&res);
            println!("XOR-MAPPED-ADDRESS: {}", xor_mapped_addr.unwrap());
        },
        _ => panic!("error"),
    }
});

Modules§

nat_behavior_discovery
This module is for NAT Behavior Discovery based on RFC5780. To use this module, the STUN server side must support the OTHER-ADDRESS and CHANGE-REQUEST attributes.

Structs§

Client
STUN client. The transport protocol is UDP only and only supports simple STUN Binding requests.
Header
Struct representing STUN header
Message
Struct representing STUN message
Options
STUN client options.

Enums§

Attribute
Enum representing STUN attribute
Class
Enum representing STUN class
ErrorCode
An enum that defines the type of STUN error code.
Method
Enum representing STUN method
STUNClientError
Defines the error used by the stun_client library.

Constants§

ATTR_CHANGE_REQUEST
CHANGE-REQUEST attribute
ATTR_ERROR_CODE
ERROR-CODE attribute
ATTR_MAPPED_ADDRESS
MAPPED-ADDRESS attribute
ATTR_OTHER_ADDRESS
OTHER-ADDRESS attribute
ATTR_RESPONSE_ORIGIN
RESPONSE-ORIGIN attribute
ATTR_SOFTWARE
SOFTWARE attribute
ATTR_XOR_MAPPED_ADDRESS
XOR-MAPPED-ADDRESS attribute
CHANGE_REQUEST_IP_FLAG
The “change IP” flag for the CHANGE-REQUEST attribute.
CHANGE_REQUEST_PORT_FLAG
The “change port” flag for the CHANGE-REQUEST attribute.
CLASS_ERROR_RESPONSE
A constant that represents a class error response
CLASS_INDICATION
A constant that represents a class indication
CLASS_REQUEST
A constant that represents a class request
CLASS_SUCCESS_RESPONSE
A constant that represents a class success response
FAMILY_IPV4
FAMILY_IPV6
HEADER_BYTE_SIZE
STUN header size
MAGIC_COOKIE
Magic cookie
METHOD_BINDING
Binding method