GetHost() API

This commit is contained in:
Russ Magee 2018-06-27 19:08:56 -07:00
parent 7ad2b5b340
commit 9047cf4dd3
1 changed files with 18 additions and 3 deletions

View File

@ -79,9 +79,11 @@ package goutmp
import "C"
import (
"fmt"
"os/user"
"time"
"fmt"
"net"
"os/user"
"strings"
"time"
)
// UtmpEntry wraps the C struct utmpx
@ -89,6 +91,19 @@ type UtmpEntry struct {
entry C.struct_utmpx
}
// return remote client hostname or IP if host lookup fails
func GetHost(addr string) (h string) {
// Strip off the port after IP addr
hList, e := net.LookupAddr(strings.Split(addr,":")[0])
fmt.Printf("lookupAddr:%v\n", hList)
if e != nil {
h = strings.Split(addr,":")[0]
} else {
h = hList[0]
}
return
}
// Put a username and the originating host/IP to utmp
func Put_utmp(user string, host string) (UtmpEntry) {
var entry UtmpEntry