Skip to content

Commit 90dbef7

Browse files
authored
Merge pull request #670 from hanlins/fix/OSDevice
Fix nil pointer refering initializing OS devices
2 parents f1f3ff1 + d97bf58 commit 90dbef7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

flow/flow.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,15 @@ func SetReceiver(portId uint16) (OUT *Flow, err error) {
904904
// Creates RAW socket, returns new opened flow with received packets.
905905
func SetReceiverOS(device string) (*Flow, error) {
906906
v, ok := ioDevices[device]
907-
socketID := v.(int)
907+
var socketID int
908908
if !ok {
909909
socketID = low.InitDevice(device)
910910
if socketID == -1 {
911911
return nil, common.WrapWithNFError(nil, "Can't initialize socket", common.BadSocket)
912912
}
913913
ioDevices[device] = socketID
914+
} else {
915+
socketID = v.(int)
914916
}
915917
rings := low.CreateRings(burstSize*sizeMultiplier, 1)
916918
addOSReceiver(socketID, rings)
@@ -925,13 +927,15 @@ func SetSenderOS(IN *Flow, device string) error {
925927
return err
926928
}
927929
v, ok := ioDevices[device]
928-
socketID := v.(int)
930+
var socketID int
929931
if !ok {
930932
socketID = low.InitDevice(device)
931933
if socketID == -1 {
932934
return common.WrapWithNFError(nil, "Can't initialize socket", common.BadSocket)
933935
}
934936
ioDevices[device] = socketID
937+
} else {
938+
socketID = v.(int)
935939
}
936940
addSenderOS(socketID, finishFlow(IN), IN.inIndexNumber)
937941
return nil

0 commit comments

Comments
 (0)