krfb
Go to the documentation of this file.
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
32 const int ADDR_SIZE = 50;
34 socklen_t salen =
sizeof(
struct sockaddr);
36 if (getpeername(sock, &sa, &salen) == 0) {
37 if (sa.sa_family == AF_INET) {
38 struct sockaddr_in *si = (
struct sockaddr_in *)&sa;
39 return QString(inet_ntoa(si->sin_addr));
42 if (sa.sa_family == AF_INET6) {
43 char inetbuf[ADDR_SIZE];
44 inet_ntop(sa.sa_family, &sa, inetbuf, ADDR_SIZE);
45 return QString(inetbuf);
48 return QString(
"not a network address");
51 return QString(
"unable to determine...");
58 socklen_t salen =
sizeof(
struct sockaddr);
60 if (getpeername(sock, &sa, &salen) == 0) {
61 struct sockaddr_in *si = (
struct sockaddr_in *)&sa;
62 return ntohs(si->sin_port);
71 const int ADDR_SIZE = 50;
73 socklen_t salen =
sizeof(
struct sockaddr);
75 if (getsockname(sock, &sa, &salen) == 0) {
76 if (sa.sa_family == AF_INET) {
77 struct sockaddr_in *si = (
struct sockaddr_in *)&sa;
78 return QString(inet_ntoa(si->sin_addr));
81 if (sa.sa_family == AF_INET6) {
82 char inetbuf[ADDR_SIZE];
83 inet_ntop(sa.sa_family, &sa, inetbuf, ADDR_SIZE);
84 return QString(inetbuf);
87 return QString(
"not a network address");
90 return QString(
"unable to determine...");
97 socklen_t salen =
sizeof(
struct sockaddr);
99 if (getsockname(sock, &sa, &salen) == 0) {
100 struct sockaddr_in *si = (
struct sockaddr_in *)&sa;
101 return ntohs(si->sin_port);
QString localAddress(int sock)
unsigned short peerPort(int sock)
QString peerAddress(int sock)
unsigned short localPort(int sock)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:10 by
doxygen 1.8.7 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.