Skip to content

Commit a34d022

Browse files
committed
common: unexport IpStrToUint32 method
1 parent ea781bd commit a34d022

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

common/types.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package common
1919

2020
import (
21-
"encoding/binary"
2221
"errors"
23-
"net"
2422
"time"
2523
)
2624

@@ -78,16 +76,3 @@ type Metric interface {
7876
SetLast(last int64)
7977
IsZero() bool
8078
}
81-
82-
// IPStrToUint32 converts IP string to 32bits
83-
func IPStrToUint32(ipAddr string) (uint32, error) {
84-
ip := net.ParseIP(ipAddr)
85-
if ip == nil {
86-
return 0, errors.New("wrong ipAddr format")
87-
}
88-
ip = ip.To4()
89-
if ip == nil {
90-
return 0, errors.New("wrong ipAddr format")
91-
}
92-
return binary.BigEndian.Uint32(ip), nil
93-
}

flow/probes/targets/netflow_v5.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package targets
2020
import (
2121
"bytes"
2222
"encoding/binary"
23+
"errors"
2324
"math"
2425
"net"
2526
"sync"
@@ -54,20 +55,32 @@ func (nf *NetFlowV5Target) SendPacket(packet gopacket.Packet, bpf *flow.BPF) {
5455
func (nf *NetFlowV5Target) sendFlowBulk(flows []*flow.Flow, now time.Time) {
5556
records := new(bytes.Buffer)
5657

58+
ipStrToUint32 := func(ipAddr string) (uint32, error) {
59+
ip := net.ParseIP(ipAddr)
60+
if ip == nil {
61+
return 0, errors.New("wrong ipAddr format")
62+
}
63+
ip = ip.To4()
64+
if ip == nil {
65+
return 0, errors.New("wrong ipAddr format")
66+
}
67+
return binary.BigEndian.Uint32(ip), nil
68+
}
69+
5770
var nFlows uint16
5871
for _, f := range flows {
5972
if f.Network == nil {
6073
continue
6174
}
6275

6376
// Source IP Address
64-
ipA, err := common.IPStrToUint32(f.Network.A)
77+
ipA, err := ipStrToUint32(f.Network.A)
6578
if err != nil {
6679
continue
6780
}
6881

6982
// Destination IP Address
70-
ipB, err := common.IPStrToUint32(f.Network.B)
83+
ipB, err := ipStrToUint32(f.Network.B)
7184
if err != nil {
7285
continue
7386
}

0 commit comments

Comments
 (0)