Add SRV lookup for xmpps DNS records.

raw
Martin Dosch 4 years ago
parent c4f813d056
commit 9c7dc43658

@ -8,8 +8,10 @@ import (
"bufio"
"crypto/tls"
"errors"
"fmt"
"io"
"log"
"net"
"os"
"os/exec"
"os/user"
@ -286,6 +288,25 @@ func main() {
server = *flagServer
}
// Lookup SRV record for xmpps-client if direct TLS is requested and the server is not
// specified.
if *flagTLS {
if _, addrs, err := net.LookupSRV("xmpps-client", "tcp", server); err == nil {
if len(addrs) > 0 {
// Default to first record
server = fmt.Sprintf("%s:%d", addrs[0].Target, addrs[0].Port)
defP := addrs[0].Priority
for _, adr := range addrs {
if adr.Priority < defP {
server = fmt.Sprintf("%s:%d", adr.Target, adr.Port)
defP = adr.Priority
}
}
}
}
}
// Use the JIDs server part if no server is specified.
if server == "" {
server = strings.Split(user, "@")[1]

Loading…
Cancel
Save