File: main.go

package info (click to toggle)
golang-github-pion-stun 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 868 kB
  • sloc: sh: 50; makefile: 40
file content (35 lines) | stat: -rw-r--r-- 872 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 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"
)

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)
}