12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package stun
- import (
- "net"
- "strconv"
- )
- type Host struct {
- family uint16
- ip string
- port uint16
- }
- func newHostFromStr(s string) *Host {
- udpAddr, err := net.ResolveUDPAddr("udp", s)
- if err != nil {
- return nil
- }
- host := new(Host)
- if udpAddr.IP.To4() != nil {
- host.family = attributeFamilyIPv4
- } else {
- host.family = attributeFamilyIPV6
- }
- host.ip = udpAddr.IP.String()
- host.port = uint16(udpAddr.Port)
- return host
- }
- func (h *Host) Family() uint16 {
- return h.family
- }
- func (h *Host) IP() string {
- return h.ip
- }
- func (h *Host) Port() uint16 {
- return h.port
- }
- func (h *Host) TransportAddr() string {
- return net.JoinHostPort(h.ip, strconv.Itoa(int(h.port)))
- }
- func (h *Host) String() string {
- return h.TransportAddr()
- }
|