convert to ListenTCP
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
f437bfec59
commit
17e5b73aa4
|
@ -5,23 +5,24 @@
|
||||||
|
|
||||||
package dnssecsocket
|
package dnssecsocket
|
||||||
|
|
||||||
// import "fmt"
|
import "os"
|
||||||
// import "os"
|
|
||||||
|
|
||||||
import "bufio"
|
import "bufio"
|
||||||
import "math/rand"
|
import "math/rand"
|
||||||
import "net"
|
import "net"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
import "strings"
|
import "strings"
|
||||||
// import "time"
|
|
||||||
import "log"
|
import "log"
|
||||||
|
// import "fmt"
|
||||||
|
// import "time"
|
||||||
|
|
||||||
|
import "git.wit.com/jcarr/shell"
|
||||||
|
|
||||||
// will try to get this hosts FQDN
|
// will try to get this hosts FQDN
|
||||||
// import "github.com/Showmax/go-fqdn"
|
// import "github.com/Showmax/go-fqdn"
|
||||||
|
|
||||||
import "github.com/miekg/dns"
|
import "github.com/miekg/dns"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
const MIN = 1
|
const MIN = 1
|
||||||
const MAX = 100
|
const MAX = 100
|
||||||
|
@ -30,8 +31,8 @@ func random() int {
|
||||||
return rand.Intn(MAX-MIN) + MIN
|
return rand.Intn(MAX-MIN) + MIN
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRemoteAddr(c net.Conn) string {
|
func GetRemoteAddr(conn net.TCPConn) string {
|
||||||
clientAddr := c.RemoteAddr().String()
|
clientAddr := conn.RemoteAddr().String()
|
||||||
parts := strings.Split(clientAddr, "]")
|
parts := strings.Split(clientAddr, "]")
|
||||||
ipv6 := parts[0]
|
ipv6 := parts[0]
|
||||||
return ipv6[1:]
|
return ipv6[1:]
|
||||||
|
@ -42,12 +43,19 @@ func GetRemoteAddr(c net.Conn) string {
|
||||||
// Each client must send it's hostname as the first line
|
// Each client must send it's hostname as the first line
|
||||||
// Then each hostname is verified with DNSSEC
|
// Then each hostname is verified with DNSSEC
|
||||||
//
|
//
|
||||||
func HandleConnection(c net.Conn) {
|
func HandleConnection(conn *net.TCPConn) {
|
||||||
ipv6client := GetRemoteAddr(c)
|
spew.Dump(conn)
|
||||||
|
// ipv6client := GetRemoteAddr(c)
|
||||||
|
ipv6client := conn.RemoteAddr()
|
||||||
log.Println("Serving to %s as the IPv6 client", ipv6client)
|
log.Println("Serving to %s as the IPv6 client", ipv6client)
|
||||||
|
|
||||||
|
// setup this TCP socket as the "standard input"
|
||||||
|
// newStdin, _ := bufio.NewReader(conn.File())
|
||||||
|
newStdin, _ := conn.File()
|
||||||
|
newreader := bufio.NewReader(newStdin)
|
||||||
|
|
||||||
log.Println("Waiting for the client to tell me its name")
|
log.Println("Waiting for the client to tell me its name")
|
||||||
netData, err := bufio.NewReader(c).ReadString('\n')
|
netData, err := newreader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -59,18 +67,21 @@ func HandleConnection(c net.Conn) {
|
||||||
ipaddr := dns.Field(dnsRR, 1)
|
ipaddr := dns.Field(dnsRR, 1)
|
||||||
log.Println("Client claims to be: ", ipaddr)
|
log.Println("Client claims to be: ", ipaddr)
|
||||||
log.Println("Serving to IPv6 client:", ipv6client)
|
log.Println("Serving to IPv6 client:", ipv6client)
|
||||||
|
|
||||||
|
/* TODO: figure out how to fix this check
|
||||||
if (ipaddr != ipv6client) {
|
if (ipaddr != ipv6client) {
|
||||||
log.Println()
|
log.Println()
|
||||||
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
||||||
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
||||||
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
log.Println("DNSSEC ERROR: client IPv6 does not work")
|
||||||
log.Println()
|
log.Println()
|
||||||
c.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for {
|
for {
|
||||||
netData, err := bufio.NewReader(c).ReadString('\n')
|
netData, err := newreader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -82,8 +93,26 @@ func HandleConnection(c net.Conn) {
|
||||||
}
|
}
|
||||||
log.Println("Recieved: ", temp)
|
log.Println("Recieved: ", temp)
|
||||||
|
|
||||||
result := strconv.Itoa(random()) + "\n"
|
if (temp == "list") {
|
||||||
c.Write([]byte(string(result)))
|
log.Println("Should run list here")
|
||||||
|
f, _ := conn.File()
|
||||||
|
shell.SetStdout(f)
|
||||||
|
shell.Run("ls /tmp/")
|
||||||
|
// close(f)
|
||||||
|
shell.SetStdout(os.Stdout)
|
||||||
}
|
}
|
||||||
c.Close()
|
|
||||||
|
if (temp == "cpuinfo") {
|
||||||
|
log.Println("Should cat /proc/cpuinfo")
|
||||||
|
// f, _ := conn.File()
|
||||||
|
// shell.SetStdout(f)
|
||||||
|
shell.Run("cat /proc/cpuinfo")
|
||||||
|
// close(f)
|
||||||
|
shell.SetStdout(os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strconv.Itoa(random()) + "\n"
|
||||||
|
conn.Write([]byte(string(result)))
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,13 @@ const (
|
||||||
CONN_TYPE = "tcp"
|
CONN_TYPE = "tcp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
go func(c net.Conn) {
|
||||||
|
defer c.Close()
|
||||||
|
io.Copy(os.Stdout, c)
|
||||||
|
}(conn)
|
||||||
|
*/
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
hostname := fqdn.Get()
|
hostname := fqdn.Get()
|
||||||
log.Println("FQDN hostname is", hostname)
|
log.Println("FQDN hostname is", hostname)
|
||||||
|
@ -44,8 +51,10 @@ func main() {
|
||||||
listenstr := "[" + ipaddr + "]:" + CONN_PORT
|
listenstr := "[" + ipaddr + "]:" + CONN_PORT
|
||||||
log.Println("listenstr", listenstr)
|
log.Println("listenstr", listenstr)
|
||||||
|
|
||||||
|
myTCPAddr, err := net.ResolveTCPAddr("tcp", listenstr)
|
||||||
|
|
||||||
// // Listen for incoming connections on the IPv6 address only
|
// // Listen for incoming connections on the IPv6 address only
|
||||||
l, err := net.Listen(CONN_TYPE, listenstr)
|
l, err := net.ListenTCP("tcp", myTCPAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error listening:", err.Error())
|
log.Println("Error listening:", err.Error())
|
||||||
return
|
return
|
||||||
|
@ -60,7 +69,7 @@ func main() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Listen for an incoming connection.
|
// Listen for an incoming connection.
|
||||||
conn, err := l.Accept()
|
conn, err := l.AcceptTCP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error accepting: ", err.Error())
|
log.Println("Error accepting: ", err.Error())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue