-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtester.go
More file actions
78 lines (60 loc) · 2.12 KB
/
tester.go
File metadata and controls
78 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/phaxio/sip_parser"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"strings"
)
func runTestZone(){
fmt.Println("We're in test zone")
if handle, err := pcap.OpenOffline("/home/jnankin/Desktop/test.pcap"); err != nil {
panic(err)
} else {
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packetSource.Packets() {
if packet.Layer(layers.LayerTypeTCP) != nil {
appLayer := packet.ApplicationLayer()
fmt.Println("APP LAYER: \n" + string(appLayer.Payload()) + "\n\n");
sipMessage := sipparser.ParseMsg(string(appLayer.Payload()))
fmt.Println("SIP BODY: \n" + sipMessage.Body + "\n\n");
fmt.Println("Content length: \n" + sipMessage.ContentLength + "\n\n");
/*SIP PDU detection: 1st Line contains SIP/2.0
foreach line, if it's a content length, set it.
add each line to the current sip message
if the line is blank:
if I have a content length:
add content length more bytes from the message to the current sip message
add the current message to the list of messages found
if there are still messages in the buffer, the packet is fragmented and we need more messages
*/
}
}
}
}
func splitForSipMessages(packetBody string) []string, bool {
var messages []string
var currentBody := packetBody
for sipMessage, remainingBody := readSipMessageFromString(currentBody){
if sipMessage == "" && len(remainingBody) > 0 {
panic("There's a problem")
} else if sipMessage == "" && remainingBody == "" {
return messages, true
}
else {
//add the sip message
if remainingBody != "" {
return messages, false
}
}
}
}
func readSipMessageFromString(packetBody string) parsedMessage, remainingBody {
lines := strings.Split(packetBody, "\r\n")
contentLength := 0
//get index of a double line
//if the first line of this returned text does not contain SIP, just return
//get content length
//return the string from 0 until index + 4 + contentLength, and another string starting from then to the end
}