Files
stun/cmd/stun-decode/main.go
Sean DuBois 4ff55da887 Start pion/stun@v2
This is required to update pion/transport/v2 to v3

The public API of transport changed, and we expose transport as part of
our public API.
2023-09-05 11:17:47 -04:00

36 lines
875 B
Go

// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
// Package main implements a simple CLI tool to decode STUN messages
package main
import (
"encoding/base64"
"flag"
"fmt"
"log"
"os"
"github.com/pion/stun/v2"
)
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", "stun-decode")
fmt.Fprintln(os.Stderr, "stun-decode AAEAHCESpEJML0JTQWsyVXkwcmGALwAWaHR0cDovL2xvY2FsaG9zdDozMDAwLwAA")
fmt.Fprintln(os.Stderr, "First argument must be a base64.StdEncoding-encoded message")
flag.PrintDefaults()
}
flag.Parse()
data, err := base64.StdEncoding.DecodeString(flag.Arg(0))
if err != nil {
log.Fatalln("Unable to decode bas64 value:", err)
}
m := new(stun.Message)
m.Raw = data
if err = m.Decode(); err != nil {
log.Fatalln("Unable to decode message:", err)
}
fmt.Println(m)
}