Skip to content

Commit e132d29

Browse files
committed
1.go test用flag太麻烦,改用直测先。
2.兼容linux和windows,在使用网卡名选择的时候先都支持name和description
1 parent 77aa5ad commit e132d29

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"go.inferGopath": false
3+
}

producer/random_packet_generator.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package producer
33
import (
44
"flow-generator/util"
55
"fmt"
6-
"github.com/google/gopacket"
7-
"github.com/google/gopacket/layers"
8-
"github.com/google/gopacket/pcap"
96
"log"
107
"net"
118
"sync"
129
"sync/atomic"
1310
"time"
11+
12+
"github.com/google/gopacket"
13+
"github.com/google/gopacket/layers"
14+
"github.com/google/gopacket/pcap"
1415
)
1516

1617
type WorkStatus int
@@ -216,7 +217,7 @@ func (s *sender) Init(config map[string]string) {
216217
}
217218

218219
for _, value := range devices {
219-
if value.Description == nicName {
220+
if value.Name == nicName || value.Description == nicName { //为了兼容windows和linux
220221
//Open device
221222
s.handler, err = pcap.OpenLive(value.Name, snapshot_len, promiscuous, timeout)
222223
if err != nil {
@@ -226,7 +227,7 @@ func (s *sender) Init(config map[string]string) {
226227
fmt.Println(value.Name, ":", value.Description)
227228
}
228229
if s.handler == nil {
229-
log.Panic("Init handle in sender is nil")
230+
log.Panic("Init handle in sender is nil,can not find the nic named " + nicName)
230231
}
231232
}
232233

producer/random_packet_generator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package producer
22

33
import (
4-
"flag"
54
"flow-generator/log"
65
"testing"
76
)
87

98
func TestRandPktGenerator_Run(t *testing.T) {
10-
var nic string
11-
flag.StringVar(&nic, "i", "", "nic which sending packets")
9+
// var nic string
10+
// flag.StringVar(&nic, "i", "", "nic which sending packets")
1211

13-
flag.Parse()
12+
nic := "enp10s0"
13+
// flag.Parse()
1414
if len(nic) == 0 {
1515
log.Panic("Var port name([-i]) is empty.")
1616
}

0 commit comments

Comments
 (0)