Skip to content

Commit d708204

Browse files
author
shadowy-pycoder
committed
Added basic ftp and http support
1 parent ad0ffe4 commit d708204

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

layers/ftp.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package layers
22

3-
// https://mavlink.io/zh/services/ftp.html
4-
// port 21 port 20
5-
type FTPMessage struct{}
3+
import "fmt"
4+
5+
type FTPMessage struct {
6+
payload string
7+
}
68

79
func (f *FTPMessage) String() string {
8-
return ""
10+
return fmt.Sprintf(`FTP Message:
11+
%s
12+
`, f.payload)
913
}
1014

1115
func (f *FTPMessage) Parse(data []byte) error {
16+
f.payload = bytesToStr(data)
1217
return nil
1318
}
1419

layers/http.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package layers
22

3+
import "fmt"
4+
35
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages
46
// port 80
5-
type HTTPMessage struct{}
7+
type HTTPMessage struct {
8+
payload string
9+
}
610

711
func (h *HTTPMessage) String() string {
8-
return ""
12+
return fmt.Sprintf(`HTTP Message:
13+
%s
14+
`, h.payload)
915
}
1016

1117
func (h *HTTPMessage) Parse(data []byte) error {
18+
h.payload = bytesToStr(data)
1219
return nil
1320
}
1421

layers/layers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var LayerMap = map[string]Layer{
1515
"ICMP": &ICMPSegment{},
1616
"ICMPv6": &ICMPv6Segment{},
1717
"DNS": &DNSMessage{},
18-
"FTP": &DNSMessage{},
18+
"FTP": &FTPMessage{},
1919
"HTTP": &HTTPMessage{},
2020
"SNMP": &SNMPMessage{},
2121
"SSH": &SSHMessage{},
@@ -49,6 +49,6 @@ func nextAppLayer(src, dst uint16) string {
4949
return layer
5050
}
5151

52-
func bytesToStr(myBytes []byte) string {
53-
return unsafe.String(unsafe.SliceData(myBytes), len(myBytes))
52+
func bytesToStr(b []byte) string {
53+
return unsafe.String(unsafe.SliceData(b), len(b))
5454
}

layers/snmp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package layers
22

33
// https://www.ranecommercial.com/legacy/pdf/ranenotes/SNMP_Simple_Network_Management_Protocol.pdf
4+
// https://wiki.wireshark.org/SNMP
45
// port 161, 162
56
type SNMPMessage struct{}
67

mshark.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (mw *Writer) WritePacket(timestamp time.Time, data []byte) error {
8181
mw.printPacket(next, layerNum)
8282
for {
8383
name, data := next.NextLayer()
84-
if name == "" {
84+
if name == "" || len(data) == 0 {
8585
return nil
8686
}
8787
next = layers.LayerMap[name]

0 commit comments

Comments
 (0)