Skip to content

Commit

Permalink
added locks for list methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Jul 23, 2023
1 parent 52bfc1a commit c4fba31
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions txeh.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func (h *Hosts) AddHost(addressRaw string, hostRaw string) {

// ListHostsByIP returns a list of hostnames associated with a given IP address
func (h *Hosts) ListHostsByIP(address string) []string {
h.Lock()
defer h.Unlock()

var hosts []string

for _, hsl := range h.hostFileLines {
Expand All @@ -300,6 +303,9 @@ func (h *Hosts) ListHostsByIP(address string) []string {

// ListAddressesByHost returns a list of IPs associated with a given hostname
func (h *Hosts) ListAddressesByHost(hostname string, exact bool) [][]string {
h.Lock()
defer h.Unlock()

var addresses [][]string

for _, hsl := range h.hostFileLines {
Expand All @@ -318,6 +324,9 @@ func (h *Hosts) ListAddressesByHost(hostname string, exact bool) [][]string {

// ListHostsByCIDR returns a list of IPs and hostnames associated with a given CIDR
func (h *Hosts) ListHostsByCIDR(cidr string) [][]string {
h.Lock()
defer h.Unlock()

var ipHosts [][]string

_, subnet, _ := net.ParseCIDR(cidr)
Expand Down

0 comments on commit c4fba31

Please sign in to comment.