Skip to content

Commit

Permalink
Fix: some channel closing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adedayo committed Mar 6, 2019
1 parent e4b0e01 commit e448c77
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions portscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,31 +521,36 @@ func listenForACKPackets(handle *pcap.Handle, route routeFinder, config ScanConf
go func() {
defer close(out)
for {
packet, err := packetSource.NextPacket()
if err == io.EOF {
select {
case <-stop:
return
}
if err != nil {
if err.Error() == pcap.NextErrorTimeoutExpired.Error() {
continue
default:
packet, err := packetSource.NextPacket()
if err == io.EOF {
return
}
return
}
parser.DecodeLayers(packet.Data(), &decodedLayers)
for _, lyr := range decodedLayers {
//Look for TCP ACK
if lyr.Contains(layers.LayerTypeTCP) {
ack := PortACK{
Host: ip.SrcIP.String(),
Port: strings.Split(tcp.SrcPort.String(), "(")[0],
SYN: tcp.SYN,
RST: tcp.RST,
if err != nil {
if err.Error() == pcap.NextErrorTimeoutExpired.Error() {
continue
}
output <- ack
if !config.Quiet && ack.IsOpen() {
fmt.Printf("%s:%s (%s) is %s\n", ack.Host, ack.Port, ack.GetServiceName(), ack.Status())
return
}
parser.DecodeLayers(packet.Data(), &decodedLayers)
for _, lyr := range decodedLayers {
//Look for TCP ACK
if lyr.Contains(layers.LayerTypeTCP) {
ack := PortACK{
Host: ip.SrcIP.String(),
Port: strings.Split(tcp.SrcPort.String(), "(")[0],
SYN: tcp.SYN,
RST: tcp.RST,
}
output <- ack
if !config.Quiet && ack.IsOpen() {
fmt.Printf("%s:%s (%s) is %s\n", ack.Host, ack.Port, ack.GetServiceName(), ack.Status())
}
break
}
break
}
}
}
Expand Down

0 comments on commit e448c77

Please sign in to comment.