mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-18 21:53:56 +00:00
espat: add ResolveUDPAddr and ResolveTCPAddr implementations using AT command for DNS lookup
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package espat
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -156,6 +157,51 @@ func (c *SerialConn) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolveTCPAddr returns an address of TCP end point.
|
||||
//
|
||||
// The network must be a TCP network name.
|
||||
//
|
||||
func (d *Device) ResolveTCPAddr(network, address string) (*TCPAddr, error) {
|
||||
// TODO: make sure network is 'tcp'
|
||||
// separate domain from port, if any
|
||||
r := strings.Split(address, ":")
|
||||
ip, err := d.GetDNS(r[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(r) > 1 {
|
||||
port, e := strconv.Atoi(r[1])
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return &TCPAddr{IP: ip, Port: port}, nil
|
||||
}
|
||||
return &TCPAddr{IP: ip}, nil
|
||||
}
|
||||
|
||||
// ResolveUDPAddr returns an address of UDP end point.
|
||||
//
|
||||
// The network must be a UDP network name.
|
||||
//
|
||||
func (d *Device) ResolveUDPAddr(network, address string) (*UDPAddr, error) {
|
||||
// TODO: make sure network is 'udp'
|
||||
// separate domain from port, if any
|
||||
r := strings.Split(address, ":")
|
||||
ip, err := d.GetDNS(r[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(r) > 1 {
|
||||
port, e := strconv.Atoi(r[1])
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return &UDPAddr{IP: ip, Port: port}, nil
|
||||
}
|
||||
|
||||
return &UDPAddr{IP: ip}, nil
|
||||
}
|
||||
|
||||
// The following definitions are here to support a Golang standard package
|
||||
// net-compatible interface for IP until TinyGo can compile the net package.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user