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

  • 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

  • STUN client. The transport protocol is UDP only and only supports simple STUN Binding requests.
  • Struct representing STUN header
  • Struct representing STUN message
  • STUN client options.

Enums

  • Enum representing STUN attribute
  • Enum representing STUN class
  • An enum that defines the type of STUN error code.
  • Enum representing STUN method
  • Defines the error used by the stun_client library.

Constants