This commit is contained in:
crusader 2018-09-03 16:59:17 +09:00
parent 60e5f1c7c3
commit bf7500671e
4 changed files with 50 additions and 50 deletions

View File

@ -109,7 +109,7 @@ func sendUDP4(discoverySession session.DiscoverySession, ps pcap.PCapScanner, ho
addr := &net.UDPAddr{IP: ip.To4(), Port: portNumber} addr := &net.UDPAddr{IP: ip.To4(), Port: portNumber}
for i := 0; i < _matcher.PacketCount(); i++ { for i := 0; i < _matcher.PacketCount(); i++ {
p := _matcher.Packet(i) p := _matcher.Packet(i)
if _, err := conn.WriteToUDP(p.Bytes(), addr); err != nil { if _, err := conn.WriteToUDP(p.Buffer, addr); err != nil {
log.Print("UDP write error", err) log.Print("UDP write error", err)
} }
} }

View File

@ -107,7 +107,7 @@ LOOP:
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err { if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
return nil return nil
} }
_, err := conn.Write(_packet.Bytes()) _, err := conn.Write(_packet.Buffer)
if nil != err { if nil != err {
return nil return nil
} }
@ -164,7 +164,7 @@ LOOP:
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err { if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
break INNER_LOOP break INNER_LOOP
} }
_, err := conn.Write(_packet.Bytes()) _, err := conn.Write(_packet.Buffer)
if nil != err { if nil != err {
break INNER_LOOP break INNER_LOOP
} }
@ -181,7 +181,7 @@ LOOP:
break INNER_LOOP break INNER_LOOP
} }
// log.Printf("res: %s", string(buf[:n])) log.Printf("res: %s", string(buf[:n]))
if err := matcher.Match(info, j+1, osm.NewPacket(buf, n)); err == nil { if err := matcher.Match(info, j+1, osm.NewPacket(buf, n)); err == nil {
if packetCount-1 == j { if packetCount-1 == j {

View File

@ -49,17 +49,17 @@ func Test_scanTCP(t *testing.T) {
args args args args
wantErr bool wantErr bool
}{ }{
{ // {
name: "80", // name: "80",
args: args{ // args: args{
discoverySession: s, // discoverySession: s,
targetPort: __test.Port( // targetPort: __test.Port(
targetHost, // targetHost,
"80", // "80",
), // ),
}, // },
wantErr: false, // wantErr: false,
}, // },
{ {
name: "139", name: "139",
args: args{ args: args{
@ -71,39 +71,39 @@ func Test_scanTCP(t *testing.T) {
}, },
wantErr: false, wantErr: false,
}, },
{ // {
name: "443", // name: "443",
args: args{ // args: args{
discoverySession: s, // discoverySession: s,
targetPort: __test.Port( // targetPort: __test.Port(
targetHost, // targetHost,
"443", // "443",
), // ),
}, // },
wantErr: false, // wantErr: false,
}, // },
{ // {
name: "445", // name: "445",
args: args{ // args: args{
discoverySession: s, // discoverySession: s,
targetPort: __test.Port( // targetPort: __test.Port(
targetHost, // targetHost,
"445", // "445",
), // ),
}, // },
wantErr: false, // wantErr: false,
}, // },
{ // {
name: "548", // name: "548",
args: args{ // args: args{
discoverySession: s, // discoverySession: s,
targetPort: __test.Port( // targetPort: __test.Port(
targetHost, // targetHost,
"548", // "548",
), // ),
}, // },
wantErr: false, // wantErr: false,
}, // },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -39,7 +39,7 @@ func processPrepacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
n, _ := conn.Read(bytes) n, _ := conn.Read(bytes)
p := csm.NewPacket(bytes, n) p := csm.NewPacket(bytes, n)
_, err := conn.Write(m.Packet(i).Bytes()) _, err := conn.Write(m.Packet(i).Buffer)
if err != nil { if err != nil {
ch <- &Res{nil, err} ch <- &Res{nil, err}
close(ch) close(ch)
@ -57,7 +57,7 @@ func processPrepacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
func processPostpacket(ch chan *Res, conn net.Conn, m csm.Matcher) { func processPostpacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
for i := 0; i < m.PacketCount(); i++ { for i := 0; i < m.PacketCount(); i++ {
_, err := conn.Write(m.Packet(i).Bytes()) _, err := conn.Write(m.Packet(i).Buffer)
if err != nil { if err != nil {
ch <- &Res{nil, err} ch <- &Res{nil, err}
close(ch) close(ch)