mirror of
https://gogs.blitter.com/RLabs/goutmp
synced 2024-08-14 19:26:41 +00:00
GetHost() API
This commit is contained in:
parent
7ad2b5b340
commit
9047cf4dd3
1 changed files with 18 additions and 3 deletions
15
goutmp.go
15
goutmp.go
|
@ -80,7 +80,9 @@ import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,6 +91,19 @@ type UtmpEntry struct {
|
||||||
entry C.struct_utmpx
|
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
|
// Put a username and the originating host/IP to utmp
|
||||||
func Put_utmp(user string, host string) (UtmpEntry) {
|
func Put_utmp(user string, host string) (UtmpEntry) {
|
||||||
var entry UtmpEntry
|
var entry UtmpEntry
|
||||||
|
|
Loading…
Reference in a new issue