3 #include <boost/filesystem.hpp>
4 #include <boost/format.hpp>
6 #include <netinet/in.h>
7 #include <sys/socket.h>
15 struct sockaddr_storage addr;
16 socklen_t addr_size =
sizeof(addr);
17 const int getpeername_result = getpeername(fd, (
struct sockaddr *)&addr, &addr_size);
18 if (getpeername_result != 0) {
19 if (errno == ENOTCONN) {
25 char ipstr[INET6_ADDRSTRLEN] = {};
26 if (addr.ss_family == AF_INET) {
27 struct sockaddr_in *s = (
struct sockaddr_in *)&addr;
28 inet_ntop(AF_INET, &s->sin_addr, ipstr,
sizeof(ipstr));
29 }
else if (addr.ss_family == AF_INET6) {
30 struct sockaddr_in6 *s = (
struct sockaddr_in6 *)&addr;
31 inet_ntop(AF_INET6, &s->sin6_addr, ipstr,
sizeof(ipstr));
40 const boost::filesystem::directory_iterator
end;
41 boost::filesystem::directory_iterator it(
"/proc/self/fd");
42 for ( ; it !=
end; ++it) {
43 if (boost::filesystem::is_symlink(it->path())) {
44 boost::filesystem::path symlink_contents = boost::filesystem::read_symlink(it->path());
45 if (!symlink_contents.string().compare(0, 8,
"socket:[")) {
46 ret.push_back(atoi(it->path().filename().string().c_str()));
50 }
catch (
const boost::filesystem::filesystem_error&
e) {