Skip to content

Commit

Permalink
Rename scan.Request variables
Browse files Browse the repository at this point in the history
  • Loading branch information
v-byte-cpu committed Apr 1, 2021
1 parent 8e48ca3 commit 64592ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions pkg/scan/arp/arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func NewPacketFiller() *PacketFiller {
return &PacketFiller{}
}

func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request) error {
func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, r *scan.Request) error {
eth := &layers.Ethernet{
SrcMAC: pair.SrcMAC,
SrcMAC: r.SrcMAC,
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
EthernetType: layers.EthernetTypeARP,
}
Expand All @@ -94,10 +94,10 @@ func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request) e
HwAddressSize: uint8(6),
ProtAddressSize: uint8(4),
Operation: layers.ARPRequest,
SourceHwAddress: pair.SrcMAC,
SourceProtAddress: pair.SrcIP,
SourceHwAddress: r.SrcMAC,
SourceProtAddress: r.SrcIP,
DstHwAddress: net.HardwareAddr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
DstProtAddress: pair.DstIP.To4(),
DstProtAddress: r.DstIP.To4(),
}

var opt gopacket.SerializeOptions
Expand Down
10 changes: 5 additions & 5 deletions pkg/scan/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type PacketFiller interface {
Fill(packet gopacket.SerializeBuffer, pair *Request) error
Fill(packet gopacket.SerializeBuffer, r *Request) error
}

type PacketGenerator interface {
Expand All @@ -34,17 +34,17 @@ func (g *packetGenerator) Packets(ctx context.Context, in <-chan *Request) <-cha
select {
case <-ctx.Done():
return
case pair, ok := <-in:
case r, ok := <-in:
if !ok {
return
}
if pair.Err != nil {
writeBufToChan(ctx, out, &packet.BufferData{Err: pair.Err})
if r.Err != nil {
writeBufToChan(ctx, out, &packet.BufferData{Err: r.Err})
continue
}
// TODO buffer pool
buf := gopacket.NewSerializeBuffer()
if err := g.filler.Fill(buf, pair); err != nil {
if err := g.filler.Fill(buf, r); err != nil {
writeBufToChan(ctx, out, &packet.BufferData{Err: err})
continue
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/scan/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ func NewPacketFiller(opts ...PacketFillerOption) *PacketFiller {
return f
}

func (f *PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request) (err error) {
func (f *PacketFiller) Fill(packet gopacket.SerializeBuffer, r *scan.Request) (err error) {
eth := &layers.Ethernet{
SrcMAC: pair.SrcMAC,
DstMAC: pair.DstMAC,
SrcMAC: r.SrcMAC,
DstMAC: r.DstMAC,
EthernetType: layers.EthernetTypeIPv4,
}

Expand All @@ -250,15 +250,15 @@ func (f *PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request)
Flags: layers.IPv4DontFragment,
TTL: 64,
Protocol: layers.IPProtocolTCP,
SrcIP: pair.SrcIP,
DstIP: pair.DstIP,
SrcIP: r.SrcIP,
DstIP: r.DstIP,
}

tcp := &layers.TCP{
// emulate Linux default ephemeral ports range: 32768 60999
// cat /proc/sys/net/ipv4/ip_local_port_range
SrcPort: layers.TCPPort(32768 + rand.Intn(61000-32768)),
DstPort: layers.TCPPort(pair.DstPort),
DstPort: layers.TCPPort(r.DstPort),
Seq: rand.Uint32(),
SYN: f.SYN,
ACK: f.ACK,
Expand Down
12 changes: 6 additions & 6 deletions pkg/scan/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func NewPacketFiller() *PacketFiller {
return &PacketFiller{}
}

func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request) (err error) {
func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, r *scan.Request) (err error) {
eth := &layers.Ethernet{
SrcMAC: pair.SrcMAC,
DstMAC: pair.DstMAC,
SrcMAC: r.SrcMAC,
DstMAC: r.DstMAC,
EthernetType: layers.EthernetTypeIPv4,
}

Expand All @@ -106,15 +106,15 @@ func (*PacketFiller) Fill(packet gopacket.SerializeBuffer, pair *scan.Request) (
Flags: layers.IPv4DontFragment,
TTL: 64,
Protocol: layers.IPProtocolUDP,
SrcIP: pair.SrcIP,
DstIP: pair.DstIP,
SrcIP: r.SrcIP,
DstIP: r.DstIP,
}

udp := &layers.UDP{
// emulate Linux default ephemeral ports range: 32768 60999
// cat /proc/sys/net/ipv4/ip_local_port_range
SrcPort: layers.UDPPort(32768 + rand.Intn(61000-32768)),
DstPort: layers.UDPPort(pair.DstPort),
DstPort: layers.UDPPort(r.DstPort),
}

if err = udp.SetNetworkLayerForChecksum(ip); err != nil {
Expand Down

0 comments on commit 64592ff

Please sign in to comment.