Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "net/http"
- "github.com/google/gopacket/layers"
- )
- //SaveTCPLayer saves data from TCP fields
- func SaveTCPLayer(w http.ResponseWriter, req *http.Request) layers.TCP {
- var (
- tcp layers.TCP
- )
- tcp.SrcPort = layers.TCPPort(StringToUint16(req.FormValue("tcpsrcPort")))
- tcp.DstPort = layers.TCPPort(StringToUint16(req.FormValue("tcpdstPort")))
- tcp.Seq = StringToUint32(req.FormValue("tcpseq"))
- tcp.Ack = StringToUint32(req.FormValue("tcpack"))
- tcp.DataOffset = StringToUint8(req.FormValue("tcpoffset"))
- tcp.FIN = RadioToBool(req.FormValue("finflag"))
- tcp.SYN = RadioToBool(req.FormValue("synflag"))
- tcp.RST = RadioToBool(req.FormValue("rstflag"))
- tcp.PSH = RadioToBool(req.FormValue("pshflag"))
- tcp.ACK = RadioToBool(req.FormValue("ackflag"))
- tcp.URG = RadioToBool(req.FormValue("urgflag"))
- tcp.ECE = RadioToBool(req.FormValue("eceflag"))
- tcp.CWR = RadioToBool(req.FormValue("cwrflag"))
- tcp.NS = RadioToBool(req.FormValue("nsflag"))
- tcp.Window = StringToUint16(req.FormValue("window"))
- tcp.Checksum = StringToUint16(req.FormValue("checksumtcp"))
- tcp.Options = append(tcp.Options, layers.TCPOption{
- OptionType: layers.TCPOptionKind(StringToUint8(req.FormValue("tcpoptionType"))),
- OptionLength: StringToUint8(req.FormValue("tcpoptionLength")),
- OptionData: []byte(req.FormValue("tcpoptionData")),
- })
- return tcp
- }
- //SaveUDPLayer saves data from UDP fields
- func SaveUDPLayer(w http.ResponseWriter, req *http.Request) layers.UDP {
- var (
- udp layers.UDP
- )
- udp.Length = StringToUint16(req.FormValue("udplength"))
- udp.Checksum = StringToUint16(req.FormValue("udpchecksum"))
- udp.SrcPort = layers.UDPPort(StringToUint16(req.FormValue("udpsrcPort")))
- udp.DstPort = layers.UDPPort(StringToUint16(req.FormValue("udpdstPort")))
- return udp
- }
- //SaveICMPLayer saves data fro m ICMP fields
- func SaveICMPLayer(w http.ResponseWriter, req *http.Request) layers.ICMPv4 {
- var (
- icmp layers.ICMPv4
- )
- icmp.TypeCode = layers.CreateICMPv4TypeCode(8, 0)
- icmp.Id = StringToUint16(req.FormValue("icmpid"))
- icmp.Seq = StringToUint16(req.FormValue("icmpseq"))
- icmp.Checksum = StringToUint16(req.FormValue("icmpchecksum"))
- //icmp.TypeCode = layers.ICMPv4TypeCode(StringToUint16(req.FormValue("typecode")))
- return icmp
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement