{"id":29151378,"url":"https://github.com/karpeleslab/peerinfo","last_synced_at":"2025-07-01T00:09:11.124Z","repository":{"id":57574855,"uuid":"354327104","full_name":"KarpelesLab/peerinfo","owner":"KarpelesLab","description":"Return information from a local peer connected to a TCP socket","archived":false,"fork":false,"pushed_at":"2023-04-15T03:54:17.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T00:09:08.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KarpelesLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-03T15:30:57.000Z","updated_at":"2023-04-15T03:26:02.000Z","dependencies_parsed_at":"2024-06-20T09:27:09.720Z","dependency_job_id":"3ca2beef-70b5-4a2c-958d-20592947fc90","html_url":"https://github.com/KarpelesLab/peerinfo","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/KarpelesLab/peerinfo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fpeerinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fpeerinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fpeerinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fpeerinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KarpelesLab","download_url":"https://codeload.github.com/KarpelesLab/peerinfo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fpeerinfo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262870876,"owners_count":23377314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-01T00:09:05.609Z","updated_at":"2025-07-01T00:09:11.075Z","avatar_url":"https://github.com/KarpelesLab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/KarpelesLab/peerinfo?status.svg)](https://godoc.org/github.com/KarpelesLab/peerinfo)\n\n# peerinfo\n\nGrab information about the process of a connected TCP socket.\n\nThis allows doing stuff we typically do with unix sockets with programs that\ndo not allow unix sockets.\n\nIt's all qemu's fault by the way, see https://bugs.launchpad.net/bugs/1903470\n\n## Usage\n\nCalling `peerinfo.Find` will return details on the process owning the given\nsocket address on the local machine. This is done by reading files in `/proc`\nso this library is linux only.\n\n```go\nimport \"github.com/KarpelesLab/peerinfo\"\n\nfunc xxx(c net.Conn) {\n\t// remote and local are reversed as we want to remote side of the socket\n\tci, err := peerinfo.Find(c.RemoteAddr(), c.LocalAddr())\n\t\n\t// check err, etc...\n}\n```\n\n## With Unix sockets?\n\nGo notoriously lacks a way to get the peer's information on a unix socket. As\nit turns out, an issue was opened in 2010 about this (get `SO_PEERCRED`\ninformation from an open socket), but was hijacked into sending FDs and\ncredentials over unix sockets and the original issue was cast aside for [the\nissue to be finally closed in 2017 without a proper resolution](https://github.com/golang/go/issues/1101#issuecomment-339649510).\n\nBecause of this, this package will also provide a method to obtain peer\ncredentials based on a `net.UnixConn`. Maybe one day Go will have a proper API\nto perform this.\n\nYou can either directly query info with `peerinfo.UnixPeer()` if you know it\nwill be a unix conn, or let `peerinfo` detect the type of connection.\n\n```go\nimport \"github.com/KarpelesLab/peerinfo\"\n\nfunc xxx(c net.Conn) {\n\t// just pass the connection and it'll be automatic\n\tci, err := peerinfo.FindPeer(c)\n\tif err != nil {\n\t\t...\n\t}\n\n\t// can use ci.Pid, ci.GetUid(), ci.GetGid()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fpeerinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarpeleslab%2Fpeerinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fpeerinfo/lists"}