further updates
This commit is contained in:
21
server/structs/file_transfer.go
Normal file
21
server/structs/file_transfer.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package structs
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
type SaprusFileTransfer struct {
|
||||
Flag [1]byte
|
||||
Sequence [2]byte
|
||||
Checksum [2]byte
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
func (c SaprusFileTransfer) Bytes() []byte {
|
||||
data := []byte{}
|
||||
data = append(data, c.Flag[0])
|
||||
data = append(data, c.Sequence[0], c.Sequence[1])
|
||||
data = append(data, c.Checksum[0], c.Checksum[1])
|
||||
data = append(data, c.Payload...)
|
||||
return data
|
||||
}
|
||||
|
||||
39
server/utils/file_transfer.go
Normal file
39
server/utils/file_transfer.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/google/gopacket"
|
||||
|
||||
"saprusserver/structs"
|
||||
)
|
||||
|
||||
func (c* SocketCall) FileTransferPacket(message string) gopacket.SerializeBuffer {
|
||||
eth, ip, udp := basePacket(c)
|
||||
|
||||
sapFile := structs.SaprusFileTransfer {
|
||||
Flag: [1]byte{0x11},
|
||||
Sequence: [2]byte{0x22, 0x33},
|
||||
Checksum: [2]byte{0x44, 0x44},
|
||||
Payload: []byte(message),
|
||||
}
|
||||
|
||||
sapHeader := structs.SaprusHeaderFrame {
|
||||
PacketType: [2]byte{0x88, 0x88},
|
||||
Length: c.saprusPayloadLength(sapFile.Bytes()),
|
||||
Payload: sapFile.Bytes(),
|
||||
}
|
||||
|
||||
buf := gopacket.NewSerializeBuffer()
|
||||
opts := gopacket.SerializeOptions {
|
||||
ComputeChecksums: true,
|
||||
FixLengths: true,
|
||||
}
|
||||
|
||||
udp.SetNetworkLayerForChecksum(&ip)
|
||||
err := gopacket.SerializeLayers(buf, opts, ð, &ip, &udp, gopacket.Payload(sapHeader.Bytes()))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
27
server/utils/packet_helper.go
Normal file
27
server/utils/packet_helper.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
func basePacket(c* SocketCall) (layers.Ethernet, layers.IPv4, layers.UDP) {
|
||||
eth := layers.Ethernet {
|
||||
EthernetType: layers.EthernetTypeIPv4,
|
||||
SrcMAC: c.Iface.HardwareAddr,
|
||||
DstMAC: layers.EthernetBroadcast,
|
||||
}
|
||||
ip := layers.IPv4 {
|
||||
Version: 4,
|
||||
TTL: 64,
|
||||
SrcIP: []byte{0, 0, 0, 0},
|
||||
DstIP: []byte{255, 255, 255, 255},
|
||||
Protocol: layers.IPProtocolUDP,
|
||||
}
|
||||
udp := layers.UDP {
|
||||
SrcPort: 6868,
|
||||
DstPort: 6767,
|
||||
}
|
||||
|
||||
return eth, ip, udp
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ func (c* SocketCall) saprusPayloadLength(pkt []byte) [2]byte{
|
||||
return length
|
||||
}
|
||||
|
||||
/*
|
||||
func (c* SocketCall)init(data string) {
|
||||
iface, _ := net.InterfaceByName("virbr0")
|
||||
conn, err := packet.Listen(iface, packet.Raw, int(layers.EthernetTypeIPv4), nil)
|
||||
@@ -96,7 +97,6 @@ func (c* SocketCall)init(data string) {
|
||||
DstPort: 6767,
|
||||
}
|
||||
|
||||
// FUCK THIS
|
||||
saprusPayloadLength := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(saprusPayloadLength, uint16(len(data)))
|
||||
var saprusPayloadLengthTwo [2]byte
|
||||
@@ -128,4 +128,4 @@ func (c* SocketCall)init(data string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user