diff options
author | cos <cos> | 2023-06-04 18:32:34 +0200 |
---|---|---|
committer | cos <cos> | 2023-06-04 18:32:37 +0200 |
commit | 7e8f5fc6faa5886f105cff67ee5a3d526b9e470f (patch) | |
tree | 2258d9ba55baae08531cbd2995c5c68ea2309cfe | |
parent | d2f186ea6b7b12fd80b764ba1048d1c5005beb2d (diff) | |
download | hisgle-master.zip |
Allows for having a host reachable over different interfaces, such as
e.g. somehost and somehost-wifi.
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | hisgle.go | 20 |
2 files changed, 15 insertions, 7 deletions
@@ -3,6 +3,6 @@ module netizen.se/hisgle go 1.14 require ( - github.com/mxk/go-sqlite v0.0.0-20140611214908-167da9432e1f + github.com/mattn/go-sqlite3 v1.14.17 github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 ) @@ -10,7 +10,7 @@ import ( "fmt" // _ "code.google.com/p/gosqlite/sqlite3" import ( "database/sql" - _ "github.com/mxk/go-sqlite/sqlite3" + _ "github.com/mattn/go-sqlite3" "github.com/pborman/getopt" ) @@ -40,26 +40,34 @@ func hosts(db *sql.DB, vlan int) { var ( ipv4 string name string + suffix *string alias string + hostpart string ) // CREATE TABLE devices (name, mac, interface); // CREATE TABLE addresses (mac, vlan, ipv4); - rows, err := db.Query("SELECT a.ipv4, d.name FROM addresses AS a JOIN " + - "devices AS d ON a.mac=d.mac WHERE vlan=?", vlan) + rows, err := db.Query("SELECT a.ipv4, d.name, d.suffix " + + "FROM addresses AS a JOIN devices AS d ON a.mac=d.mac WHERE vlan=?", + vlan) if err != nil { log.Fatal(err) } for rows.Next() { - err := rows.Scan(&ipv4, &name) + err := rows.Scan(&ipv4, &name, &suffix) if err != nil { log.Fatal(err) } - fmt.Print(ipv4, "\t", name) + if suffix != nil { + hostpart = name + "-" + *suffix + } else { + hostpart = name + } + fmt.Print(ipv4, "\t", hostpart) // CREATE TABLE aliases (alias, target); - rows, err := db.Query("SELECT alias FROM aliases WHERE target=?", name) + rows, err := db.Query("SELECT alias FROM aliases WHERE target=?", hostpart) if err != nil { log.Fatal(err) } |