• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krfb

  • sources
  • kde-4.14
  • kdenetwork
  • krfb
  • krfb
sockethelpers.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2009 Collabora Ltd <info@collabora.co.uk>
3  @author George Goldberg <george.goldberg@collabora.co.uk>
4  Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
5  Copyright (C) 2001-2003 by Tim Jansen <tim@tjansen.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; see the file COPYING. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "sockethelpers.h"
24 
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
28 
29 QString peerAddress(int sock)
30 {
31 
32  const int ADDR_SIZE = 50;
33  struct sockaddr sa;
34  socklen_t salen = sizeof(struct sockaddr);
35 
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));
40  }
41 
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);
46  }
47 
48  return QString("not a network address");
49  }
50 
51  return QString("unable to determine...");
52 }
53 
54 unsigned short peerPort(int sock)
55 {
56 
57  struct sockaddr sa;
58  socklen_t salen = sizeof(struct sockaddr);
59 
60  if (getpeername(sock, &sa, &salen) == 0) {
61  struct sockaddr_in *si = (struct sockaddr_in *)&sa;
62  return ntohs(si->sin_port);
63  }
64 
65  return 0;
66 }
67 
68 QString localAddress(int sock)
69 {
70 
71  const int ADDR_SIZE = 50;
72  struct sockaddr sa;
73  socklen_t salen = sizeof(struct sockaddr);
74 
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));
79  }
80 
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);
85  }
86 
87  return QString("not a network address");
88  }
89 
90  return QString("unable to determine...");
91 }
92 
93 unsigned short localPort(int sock)
94 {
95 
96  struct sockaddr sa;
97  socklen_t salen = sizeof(struct sockaddr);
98 
99  if (getsockname(sock, &sa, &salen) == 0) {
100  struct sockaddr_in *si = (struct sockaddr_in *)&sa;
101  return ntohs(si->sin_port);
102  }
103 
104  return 0;
105 }
106 
localAddress
QString localAddress(int sock)
Definition: sockethelpers.cpp:68
peerPort
unsigned short peerPort(int sock)
Definition: sockethelpers.cpp:54
peerAddress
QString peerAddress(int sock)
Definition: sockethelpers.cpp:29
QString
localPort
unsigned short localPort(int sock)
Definition: sockethelpers.cpp:93
sockethelpers.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krfb

Skip menu "krfb"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal