mirror of
https://github.com/maride/pancap.git
synced 2026-04-13 18:45:46 +00:00
Move common code into new package, 'common'
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
package dhcpv4
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Appends the appendee to the array if it does not contain appendee yet
|
||||
func appendIfUnique(appendee string, array []string) []string {
|
||||
// Iterate over all elements and check values
|
||||
for _, elem := range array {
|
||||
if elem == appendee {
|
||||
// ... found. Stop here
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
// None found, append
|
||||
return append(array, appendee)
|
||||
}
|
||||
|
||||
// Prints each element, along with a small ASCII tree
|
||||
func printTree(strarr []string) {
|
||||
// iterate over each element
|
||||
for iter, elem := range strarr {
|
||||
// check if we got the last element
|
||||
if iter < len(strarr) - 1 {
|
||||
fmt.Printf("|- %s\n", elem)
|
||||
} else {
|
||||
fmt.Printf("'- %s\n\n", elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package dhcpv4
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.darknebu.la/maride/pancap/common"
|
||||
"github.com/google/gopacket/layers"
|
||||
"log"
|
||||
)
|
||||
@@ -71,7 +72,7 @@ func printHostnames() {
|
||||
}
|
||||
|
||||
// and print it as a tree.
|
||||
printTree(tmparr)
|
||||
common.PrintTree(tmparr)
|
||||
}
|
||||
|
||||
// Adds the given hostname to the hostname array, or patches an existing entry if found
|
||||
|
||||
@@ -2,6 +2,7 @@ package dhcpv4
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.darknebu.la/maride/pancap/common"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
@@ -11,11 +12,11 @@ var (
|
||||
|
||||
// Processes the DHCP request packet handed over
|
||||
func processRequestPacket(dhcppacket layers.DHCPv4) {
|
||||
requestMAC = appendIfUnique(dhcppacket.ClientHWAddr.String(), requestMAC)
|
||||
requestMAC = common.AppendIfUnique(dhcppacket.ClientHWAddr.String(), requestMAC)
|
||||
}
|
||||
|
||||
// Prints the summary of all DHCP request packets
|
||||
func printRequestSummary() {
|
||||
fmt.Printf("%d unique DHCP requests\n", len(requestMAC))
|
||||
printTree(requestMAC)
|
||||
common.PrintTree(requestMAC)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dhcpv4
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.darknebu.la/maride/pancap/common"
|
||||
"github.com/google/gopacket/layers"
|
||||
"log"
|
||||
)
|
||||
@@ -30,7 +31,7 @@ func printResponseSummary() {
|
||||
}
|
||||
|
||||
// Draw as tree
|
||||
printTree(tmpaddr)
|
||||
common.PrintTree(tmpaddr)
|
||||
}
|
||||
|
||||
// Adds a new response entry. If an IP address was already issued or a MAC asks multiple times for DNS, the case is examined further
|
||||
|
||||
Reference in New Issue
Block a user