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
21
goutmp.go
21
goutmp.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue