mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
36 lines
809 B
Go
36 lines
809 B
Go
//go:build linux && !android
|
|
|
|
package process
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
|
|
"github.com/sagernet/sing-box/log"
|
|
)
|
|
|
|
var _ Searcher = (*linuxSearcher)(nil)
|
|
|
|
type linuxSearcher struct {
|
|
logger log.ContextLogger
|
|
}
|
|
|
|
func NewSearcher(config Config) (Searcher, error) {
|
|
return &linuxSearcher{config.Logger}, nil
|
|
}
|
|
|
|
func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
|
|
socket, err := resolveSocketByNetlink(network, source, destination)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
processPath, err := resolveProcessNameByProcSearch(socket.INode, socket.UID)
|
|
if err != nil {
|
|
s.logger.DebugContext(ctx, "find process path: ", err)
|
|
}
|
|
return &Info{
|
|
UserId: int32(socket.UID),
|
|
ProcessPath: processPath,
|
|
}, nil
|
|
}
|