mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 09:41:09 +08:00
update lsof code
This commit is contained in:
10
common/lsof/lsof.go
Normal file
10
common/lsof/lsof.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package lsof
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotFound = errors.New("not found")
|
||||||
|
ErrNotImplemented = errors.New("not implemented")
|
||||||
|
)
|
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
package lsof
|
package lsof
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetCommandNameBySocket(network string, addr string, port uint16) (string, error) {
|
func GetCommandNameBySocket(network string, addr string, port uint16) (string, error) {
|
||||||
return "", errors.New("not implemented")
|
return "", ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e
|
|||||||
// listen on the same udp port. Moreover, if
|
// listen on the same udp port. Moreover, if
|
||||||
// the application closes the socket immediately
|
// the application closes the socket immediately
|
||||||
// after sending out the packet (e.g. it just
|
// after sending out the packet (e.g. it just
|
||||||
// uploading data but not receving any data),
|
// uploading data but not receiving any data),
|
||||||
// we may not be able to find it.
|
// we may not be able to find it.
|
||||||
pattern = fmt.Sprintf("-i%s:%d", network, port)
|
pattern = fmt.Sprintf("-i%s:%d", network, port)
|
||||||
default:
|
default:
|
||||||
@@ -38,8 +38,8 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e
|
|||||||
// sockets in the list, just take
|
// sockets in the list, just take
|
||||||
// the first one for simplicity.
|
// the first one for simplicity.
|
||||||
if strings.HasPrefix(line, "c") {
|
if strings.HasPrefix(line, "c") {
|
||||||
return line[1:len(line)], nil
|
return line[1:], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", errors.New("not found")
|
return "", ErrNotFound
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
package lsof
|
package lsof
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -24,7 +23,7 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e
|
|||||||
return getNameByPid(uint32(row.OwningPid))
|
return getNameByPid(uint32(row.OwningPid))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", errors.New("not found")
|
return "", ErrNotFound
|
||||||
case "udp":
|
case "udp":
|
||||||
var udpTable win.MIB_UDPTABLE_OWNER_PID
|
var udpTable win.MIB_UDPTABLE_OWNER_PID
|
||||||
err := getUdpTable(
|
err := getUdpTable(
|
||||||
@@ -56,9 +55,9 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return "", errors.New("not found")
|
return "", ErrNotFound
|
||||||
default:
|
default:
|
||||||
return "", errors.New("not found")
|
return "", ErrNotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user