Hello All,
I have a project where I need to receive Netflow V5 Packets and extract the Source and Destination IP Addresses inside the PDUs - I'm using B4J on Windows 10
Problem: Extracting the Netflow packet Header fields seems to work okay but when I get to the PDUs I cannot find the Source and Destination Addresses which should start on Byte 24.
Below is part of the code I'm using to extract the fields from the Packet - have been stuck on this for a while and would appreciate any recommendations (Attached is the Netflow V5 Packet structure for easy reference)
I have a project where I need to receive Netflow V5 Packets and extract the Source and Destination IP Addresses inside the PDUs - I'm using B4J on Windows 10
Problem: Extracting the Netflow packet Header fields seems to work okay but when I get to the PDUs I cannot find the Source and Destination Addresses which should start on Byte 24.
Below is part of the code I'm using to extract the fields from the Packet - have been stuck on this for a while and would appreciate any recommendations (Attached is the Netflow V5 Packet structure for easy reference)
B4X:
Sub Process_Globals
Dim UDPSocket1 As UDPSocket
End Sub
Sub AppStart (Args() As String)
UDPSocket1.Initialize("UDP", 2055, 10000)
StartMessageLoop
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
'msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "ASCII")
Log("Message received: " & msg)
Log("PACKET LENGTH:" & Packet.Length)
Log("PACKET OFFSET:" & Packet.Offset)
Log("PACKET STRING:" & Packet.toString)
'''''''''''
Dim raf As RandomAccessFile
raf.Initialize3(Packet.Data, False)
Dim versionnumber As Short
versionnumber = raf.readshort(0)
Log("versionnumber: " & versionnumber) 'this works ok
Dim pducount As Short
pducount = raf.ReadShort(2)
Log("pducount: " & pducount) 'this works ok
Dim sysuptime As Int
sysuptime = raf.ReadInt(4)
Log("sysuptime: " & sysuptime) 'this works ok
Dim unix_secs As Int
unix_secs = raf.readint(8)
Log("unix_secs: " & unix_secs) 'this works ok
Dim unix_nsecs As Int
unix_nsecs = raf.readint(12)
Log("unix_nsecs: " & unix_nsecs) 'this works ok
Dim flowseq As Int
flowseq = raf.readint(16)
Log("flowseq: " & flowseq) 'this works ok
Dim eng_type As Int
eng_type = raf.ReadShort(20)
Log("eng_type: " & eng_type) 'this works ok
Dim eng_id As Char
eng_id = raf.ReadShort(21)
Log("eng_id: " & eng_id) 'this works ok
Dim samp_interval As Short
samp_interval = raf.ReadShort(22)
Log("samp_interval: " & samp_interval) 'this works ok
Log("End of Header, Begin First PDU")
Dim SrcIP As Int 'This Does Not Work cannot seem to read IP Address (in decimal)
SrcIP = raf.readint(24) 'Have tried reading from multiple locations - none seem to produce the IP Address
Log("SrcIP: " & SrcIP)
Dim DstIP As Int 'This Does Not Work cannot seem to read IP Address (in decimal)
SrcIP = raf.readint(28) 'Have tried reading from multiple locations - none seem to produce the IP Address
Log("DstIP: " & DstIP)
Log("End Of First PDU")
'process subsequent PDUs with a loop
End Sub