Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | //krazy:excludeall=dpointer,inline (lightweight classes; kde3 support) |
---|---|
2 | /* -*- C++ -*- |
3 | * Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org> |
4 | * |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining |
7 | * a copy of this software and associated documentation files (the |
8 | * "Software"), to deal in the Software without restriction, including |
9 | * without limitation the rights to use, copy, modify, merge, publish, |
10 | * distribute, sublicense, and/or sell copies of the Software, and to |
11 | * permit persons to whom the Software is furnished to do so, subject to |
12 | * the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included |
15 | * in all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24 | */ |
25 | |
26 | #ifndef KSOCKETADDRESS_H |
27 | #define KSOCKETADDRESS_H |
28 | |
29 | #include <kdecore_export.h> |
30 | #include <QtCore/QByteArray> |
31 | |
32 | struct sockaddr; |
33 | struct sockaddr_in; |
34 | struct sockaddr_in6; |
35 | struct sockaddr_un; |
36 | |
37 | namespace KNetwork { |
38 | |
39 | class KIpAddress; |
40 | class KSocketAddress; |
41 | class KInetSocketAddress; |
42 | class KUnixSocketAddress; |
43 | |
44 | /** @class KIpAddress k3socketaddress.h k3socketaddress.h |
45 | * @brief An IP address. |
46 | * |
47 | * This class represents one IP address, version 4 or 6. This is only |
48 | * the address, not including port information or other data. |
49 | * |
50 | * It is not a good programming practice to create address from objects |
51 | * like this. Instead, prefer a more thorough function like |
52 | * KResolver::resolve(), which also handle extra information like scope |
53 | * ids. |
54 | * |
55 | * This is a light-weight class. Most of the member functions are inlined and |
56 | * there are no virtual functions. This object's size should be less than 20 |
57 | * bytes. Also note that there is no sharing of data. |
58 | * |
59 | * @author Thiago Macieira <thiago@kde.org> |
60 | * @deprecated Use KSocketFactory or KLocalSocket instead |
61 | */ |
62 | class KDECORE_EXPORT_DEPRECATED KIpAddress |
63 | { |
64 | public: |
65 | /** |
66 | * Default constructor. Creates an empty address. |
67 | * It defaults to IP version 4. |
68 | */ |
69 | inline KIpAddress() : m_version(0) |
70 | { } |
71 | |
72 | /** |
73 | * Copy constructor. Copies the data from the other |
74 | * object. |
75 | * |
76 | * Data is not shared. |
77 | * |
78 | * @param other the other |
79 | */ |
80 | inline KIpAddress(const KIpAddress& other) |
81 | { *this = other; } |
82 | |
83 | /** |
84 | * Creates an object from the given string representation. |
85 | * |
86 | * The IP version is guessed from the address format. |
87 | * |
88 | * @param addr the address |
89 | */ |
90 | inline KIpAddress(const QString& addr) |
91 | { setAddress(addr); } |
92 | |
93 | /** |
94 | * Creates an object from the given string representation. |
95 | * |
96 | * The IP version is guessed from the address format. |
97 | * |
98 | * @param addr the address |
99 | */ |
100 | inline KIpAddress(const char* addr) |
101 | { setAddress(addr); } |
102 | |
103 | /** |
104 | * Creates an object from the given raw data and IP version. |
105 | * |
106 | * @param addr the raw data |
107 | * @param version the IP version (4 or 6) |
108 | */ |
109 | inline KIpAddress(const void* addr, int version = 4) |
110 | { setAddress(addr, version); } |
111 | |
112 | /** |
113 | * This is a convenience constructor. Constructs an object |
114 | * from the given IPv4 address in the form of an integer. |
115 | * |
116 | * Note: do not write code to depend on IPv4 addresses being |
117 | * integer types. Instead, treat them as a special type, like |
118 | * a KIpAddress or the system's in_addr. |
119 | * |
120 | * @param ip4addr the IPv4 address |
121 | */ |
122 | inline KIpAddress(quint32 ip4addr) |
123 | { setAddress(&ip4addr, 4); } |
124 | |
125 | /** |
126 | * Destructor. This frees resources associated with this object. |
127 | * |
128 | * Note: destructor is non-virtual. The compiler will happily optimize it |
129 | * out of the way. |
130 | */ |
131 | inline ~KIpAddress() |
132 | { } |
133 | |
134 | /** |
135 | * Copy operator. |
136 | * |
137 | * Copies the data from the other object into this one. |
138 | * |
139 | * @param other the object to copy |
140 | */ |
141 | KIpAddress& operator =(const KIpAddress& other); |
142 | |
143 | /** |
144 | * Returns true if the two addresses match. |
145 | * This function performs a v4-mapped check. |
146 | * @see compare |
147 | */ |
148 | inline bool operator ==(const KIpAddress& other) const |
149 | { return compare(other, true); } |
150 | |
151 | /** |
152 | * Compares this address against the other, supplied one and return |
153 | * true if they match. The @p checkMapped parameter controls whether |
154 | * a check for an IPv6 v4-mapped address will be performed. |
155 | * |
156 | * An IPv6 v4-mapped address is an IPv6 address that is, for all purposes, |
157 | * equivalent to an IPv4 one. The default behaviour of this function |
158 | * is to take that into account. If you want a strict matching, |
159 | * pass @b false to the @p checkMapped parameter. |
160 | * |
161 | * @param other the other IP address |
162 | * @param checkMapped whether v4-mapped addresses will be taken into account |
163 | */ |
164 | bool compare(const KIpAddress& other, bool checkMapped = true) const; |
165 | |
166 | /** |
167 | * Retrieves the IP version in this object. |
168 | * |
169 | * @returns the version: 4 or 6 |
170 | */ |
171 | inline int version() const |
172 | { return m_version; } |
173 | |
174 | /** |
175 | * Returns true if this is an IPv4 address. |
176 | */ |
177 | inline bool isIPv4Addr() const |
178 | { return version() == 4; } |
179 | |
180 | /** |
181 | * Returns true if this is an IPv6 address. |
182 | */ |
183 | inline bool isIPv6Addr() const |
184 | { return version() == 6; } |
185 | |
186 | /** |
187 | * Sets the address to the given string representation. |
188 | * |
189 | * @return true if the address was successfully parsed; otherwise returns |
190 | * false and leaves the object unchanged. |
191 | */ |
192 | bool setAddress(const QString& address); |
193 | |
194 | /** |
195 | * Sets the address to the given string representation. |
196 | * |
197 | * @return true if the address was successfully parsed; otherwise returns |
198 | * false and leaves the object unchanged. |
199 | */ |
200 | bool setAddress(const char* address); |
201 | |
202 | /** |
203 | * Sets the address to the given raw binary representation. |
204 | * |
205 | * @param raw a pointer to the raw binary data |
206 | * @param version the IP version |
207 | * @return true if the address was successfully parsed; otherwise returns |
208 | * false and leaves the object unchanged. |
209 | */ |
210 | bool setAddress(const void* raw, int version = 4); |
211 | |
212 | /** |
213 | * Returns the address as a string. |
214 | */ |
215 | QString toString() const; |
216 | |
217 | /** |
218 | * Returns a pointer to binary raw data representing the address. |
219 | */ |
220 | inline const void *addr() const |
221 | { return m_data; } |
222 | |
223 | /** |
224 | * This is a convenience function. Returns the IPv4 address in a |
225 | * 32-bit integer. The result is only valid if isIPv4Addr() returns |
226 | * true. Alternatively, if the contained IPv6 address is a v4-mapped one |
227 | * and the @p convertMapped parameter is true, the result will also be |
228 | * valid. |
229 | * |
230 | * Note: you should not treat IP addresses as integers. Instead, |
231 | * use types defined for that purpose, such as KIpAddress or the |
232 | * system's in_addr type. |
233 | * |
234 | * @bug Check if byte ordering is done right |
235 | */ |
236 | inline quint32 IPv4Addr(bool convertMapped = true) const |
237 | { |
238 | return (convertMapped && isV4Mapped()) ? m_data[3] : m_data[0]; |
239 | } |
240 | |
241 | /*-- tests --*/ |
242 | |
243 | /** |
244 | * Returns true if this is the IPv4 or IPv6 unspecified address. |
245 | */ |
246 | inline bool isUnspecified() const |
247 | { return version() == 0 ? true : (*this == anyhostV4 || *this == anyhostV6); } |
248 | |
249 | /** |
250 | * Returns true if this is either the IPv4 or the IPv6 localhost address. |
251 | */ |
252 | inline bool isLocalhost() const |
253 | { return version() == 0 ? false : (*this == localhostV4 || *this == localhostV6); } |
254 | |
255 | /** |
256 | * This is an alias for isLocalhost(). |
257 | */ |
258 | inline bool isLoopback() const |
259 | { return isLocalhost(); } |
260 | |
261 | /** |
262 | * Returns true if this is an IPv4 class A address, i.e., |
263 | * from 0.0.0.0 to 127.255.255.255. |
264 | * |
265 | * This function does not test for v4-mapped addresses. |
266 | */ |
267 | inline bool isClassA() const |
268 | { return version() != 4 ? false : (IPv4Addr() & 0x80000000) == 0; } |
269 | |
270 | /** |
271 | * Returns true if this is an IPv4 class B address, i.e., one from |
272 | * 128.0.0.0 to 191.255.255.255. |
273 | * |
274 | * This function does not test for v4-mapped addresses. |
275 | */ |
276 | inline bool isClassB() const |
277 | { return version() != 4 ? false : (IPv4Addr() & 0xc0000000) == 0x80000000; } |
278 | |
279 | /** |
280 | * Returns true if this is an IPv4 class C address, i.e., one from |
281 | * 192.0.0.0 to 223.255.255.255. |
282 | * |
283 | * This function does not test for v4-mapped addresses. |
284 | */ |
285 | inline bool isClassC() const |
286 | { return version() != 4 ? false : (IPv4Addr() & 0xe0000000) == 0xc0000000; } |
287 | |
288 | /** |
289 | * Returns true if this is an IPv4 class D (a.k.a. multicast) address. |
290 | * |
291 | * Note: this function is not the same as isMulticast(). isMulticast also |
292 | * tests for IPv6 multicast addresses. |
293 | */ |
294 | inline bool isClassD() const |
295 | { return version() != 4 ? false : (IPv4Addr() & 0xf0000000) == 0xe0000000; } |
296 | |
297 | /** |
298 | * Returns true if this is a multicast address, be it IPv4 or IPv6. |
299 | */ |
300 | inline bool isMulticast() const |
301 | { |
302 | if (version() == 4) return isClassD(); |
303 | if (version() == 6) return ((quint8*)addr())[0] == 0xff; |
304 | return false; |
305 | } |
306 | |
307 | /** |
308 | * Returns true if this is an IPv6 link-local address. |
309 | */ |
310 | inline bool isLinkLocal() const |
311 | { |
312 | if (version() != 6) return false; |
313 | quint8* addr = (quint8*)this->addr(); |
314 | return (addr[0] & 0xff) == 0xfe && |
315 | (addr[1] & 0xc0) == 0x80; |
316 | } |
317 | |
318 | /** |
319 | * Returns true if this is an IPv6 site-local address. |
320 | */ |
321 | inline bool isSiteLocal() const |
322 | { |
323 | if (version() != 6) return false; |
324 | quint8* addr = (quint8*)this->addr(); |
325 | return (addr[0] & 0xff) == 0xfe && |
326 | (addr[1] & 0xc0) == 0xc0; |
327 | } |
328 | |
329 | /** |
330 | * Returns true if this is a global IPv6 address. |
331 | */ |
332 | inline bool isGlobal() const |
333 | { return version() != 6 ? false : !(isMulticast() || isLinkLocal() || isSiteLocal()); } |
334 | |
335 | /** |
336 | * Returns true if this is a v4-mapped IPv6 address. |
337 | */ |
338 | inline bool isV4Mapped() const |
339 | { |
340 | if (version() != 6) return false; |
341 | quint32* addr = (quint32*)this->addr(); |
342 | return addr[0] == 0 && addr[1] == 0 && |
343 | ((quint16*)&addr[2])[0] == 0 && |
344 | ((quint16*)&addr[2])[1] == 0xffff; |
345 | } |
346 | |
347 | /** |
348 | * Returns true if this is a v4-compat IPv6 address. |
349 | */ |
350 | inline bool isV4Compat() const |
351 | { |
352 | if (version() != 6 || isLocalhost()) return false; |
353 | quint32* addr = (quint32*)this->addr(); |
354 | return addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] != 0; |
355 | } |
356 | |
357 | /** |
358 | * Returns true if this is an IPv6 node-local multicast address. |
359 | */ |
360 | inline bool isMulticastNodeLocal() const |
361 | { return version() == 6 && isMulticast() && (((quint32*)addr())[0] & 0xf) == 0x1; } |
362 | |
363 | /** |
364 | * Returns true if this is an IPv6 link-local multicast address. |
365 | */ |
366 | inline bool isMulticastLinkLocal() const |
367 | { return version() == 6 && isMulticast() && (((quint32*)addr())[0] & 0xf) == 0x2; } |
368 | |
369 | /** |
370 | * Returns true if this is an IPv6 site-local multicast address. |
371 | */ |
372 | inline bool isMulticastSiteLocal() const |
373 | { return version() == 6 && isMulticast() && (((quint32*)addr())[0] & 0xf) == 0x5; } |
374 | |
375 | /** |
376 | * Returns true if this is an IPv6 organisational-local multicast address. |
377 | */ |
378 | inline bool isMulticastOrgLocal() const |
379 | { return version() == 6 && isMulticast() && (((quint32*)addr())[0] & 0xf) == 0x8; } |
380 | |
381 | /** |
382 | * Returns true if this is an IPv6 global multicast address. |
383 | */ |
384 | inline bool isMulticastGlobal() const |
385 | { return version() == 6 && isMulticast() && (((quint32*)addr())[0] & 0xf) == 0xe; } |
386 | |
387 | protected: |
388 | quint32 m_data[4]; // 16 bytes, needed for an IPv6 address |
389 | |
390 | char m_version; |
391 | |
392 | public: |
393 | /// localhost in IPv4 (127.0.0.1) |
394 | static const KIpAddress localhostV4; |
395 | /// the any host or undefined address in IPv4 (0.0.0.0) |
396 | static const KIpAddress anyhostV4; |
397 | |
398 | /// localhost in IPv6 (::1) |
399 | static const KIpAddress localhostV6; |
400 | /// the any host or undefined address in IPv6 (::) |
401 | static const KIpAddress anyhostV6; |
402 | }; |
403 | |
404 | |
405 | class KSocketAddressData; |
406 | /** @class KSocketAddress k3socketaddress.h k3socketaddress.h |
407 | * @brief A generic socket address. |
408 | * |
409 | * This class holds one generic socket address. |
410 | * |
411 | * @author Thiago Macieira <thiago@kde.org> |
412 | * @deprecated Use KSocketFactory or KLocalSocket instead |
413 | */ |
414 | class KDECORE_EXPORT_DEPRECATED KSocketAddress //krazy:exclude=dpointer (we got one, just not called Private) |
415 | { |
416 | public: |
417 | /** |
418 | * Default constructor. |
419 | * |
420 | * Creates an empty object |
421 | */ |
422 | KSocketAddress(); |
423 | |
424 | /** |
425 | * Creates this object with the given data. |
426 | * The raw socket address is copied into this object. |
427 | * |
428 | * @param sa the socket address structure |
429 | * @param len the socket address length |
430 | */ |
431 | KSocketAddress(const sockaddr* sa, quint16 len); |
432 | |
433 | /** |
434 | * Copy constructor. This creates a copy of the other |
435 | * object. |
436 | * |
437 | * Data is not shared. |
438 | * |
439 | * @param other the object to copy from |
440 | */ |
441 | KSocketAddress(const KSocketAddress& other); |
442 | |
443 | /** |
444 | * Destructor. Frees any associated resources. |
445 | */ |
446 | virtual ~KSocketAddress(); |
447 | |
448 | /** |
449 | * Performs a shallow copy of the other object into this one. |
450 | * Data will be copied. |
451 | * |
452 | * @param other the object to copy from |
453 | */ |
454 | KSocketAddress& operator =(const KSocketAddress& other); |
455 | |
456 | /** |
457 | * Returns the socket address structure, to be passed down to |
458 | * low level functions. |
459 | * |
460 | * Note that this function returns NULL for invalid or empty sockets, |
461 | * so you may use to to test for validity. |
462 | */ |
463 | const sockaddr* address() const; |
464 | |
465 | /** |
466 | * Returns the socket address structure, to be passed down to |
467 | * low level functions. |
468 | * |
469 | * Note that this function returns NULL for invalid or empty sockets, |
470 | * so you may use to to test for validity. |
471 | * |
472 | * The returned value, if not NULL, is an internal buffer which is guaranteed |
473 | * to be at least length() bytes long. |
474 | */ |
475 | sockaddr* address(); |
476 | |
477 | /** |
478 | * Sets the address to the given address. |
479 | * The raw socket address is copied into this object. |
480 | * |
481 | * @param sa the socket address structure |
482 | * @param len the socket address length |
483 | */ |
484 | KSocketAddress& setAddress(const sockaddr *sa, quint16 len); |
485 | |
486 | /** |
487 | * Returns the socket address structure, to be passed down to |
488 | * low level functions. |
489 | */ |
490 | inline operator const sockaddr*() const |
491 | { return address(); } |
492 | |
493 | /** |
494 | * Returns the length of this socket address structure. |
495 | */ |
496 | quint16 length() const; |
497 | |
498 | /** |
499 | * Sets the length of this socket structure. |
500 | * |
501 | * Use this function with care. It allows you to resize the internal |
502 | * buffer to fit needs. This function should not be used except for handling |
503 | * unknown socket address structures. |
504 | * |
505 | * Also note that this function may invalidate the socket if a known |
506 | * family is set (Internet or Unix socket) and the new length would be |
507 | * too small to hold the system's sockaddr_* structure. If unsure, reset |
508 | * the family: |
509 | * |
510 | * \code |
511 | * KSocketAddress qsa; |
512 | * [...] |
513 | * qsa.setFamily(AF_UNSPEC).setLength(newlen); |
514 | * \endcode |
515 | * |
516 | * @param len the new length |
517 | */ |
518 | KSocketAddress& setLength(quint16 len); |
519 | |
520 | /** |
521 | * Returns the family of this address. |
522 | * @return the family of this address, AF_UNSPEC if it's undefined |
523 | */ |
524 | int family() const; |
525 | |
526 | /** |
527 | * Sets the family of this object. |
528 | * |
529 | * Note: setting the family will probably invalidate any address data |
530 | * contained in this object. Use this function with care. |
531 | * |
532 | * @param family the new family to set |
533 | */ |
534 | virtual KSocketAddress& setFamily(int family); |
535 | |
536 | /** |
537 | * Returns the IANA family number of this address. |
538 | * @return the IANA family number of this address (1 for AF_INET. |
539 | * 2 for AF_INET6, otherwise 0) |
540 | */ |
541 | inline int ianaFamily() const |
542 | { return ianaFamily(family()); } |
543 | |
544 | /** |
545 | * Returns true if this equals the other socket. |
546 | * |
547 | * Socket addresses are considered matching if and only if all data is the same. |
548 | * |
549 | * @param other the other socket |
550 | * @return true if both sockets are equal |
551 | */ |
552 | bool operator ==(const KSocketAddress& other) const; |
553 | |
554 | /** |
555 | * Returns the node name of this socket. |
556 | * |
557 | * In the case of Internet sockets, this is string representation of the IP address. |
558 | * The default implementation returns QString(). |
559 | * |
560 | * @return the node name, can be QString() |
561 | * @bug use KResolver to resolve unknown families |
562 | */ |
563 | virtual QString nodeName() const; |
564 | |
565 | /** |
566 | * Returns the service name for this socket. |
567 | * |
568 | * In the case of Internet sockets, this is the port number. |
569 | * The default implementation returns QString(). |
570 | * |
571 | * @return the service name, can be QString() |
572 | * @bug use KResolver to resolve unknown families |
573 | */ |
574 | virtual QString serviceName() const; |
575 | |
576 | /** |
577 | * Returns this socket address as a string suitable for |
578 | * printing. Family, node and service are part of this address. |
579 | * |
580 | * @bug use KResolver to resolve unknown families |
581 | */ |
582 | virtual QString toString() const; |
583 | |
584 | /** |
585 | * Returns an object reference that can be used to manipulate this socket |
586 | * as an Internet socket address. Both objects share the same data. |
587 | */ |
588 | KInetSocketAddress& asInet(); |
589 | |
590 | /** |
591 | * Returns an object is equal to this object's data, but they don't share it. |
592 | */ |
593 | KInetSocketAddress asInet() const; |
594 | |
595 | /** |
596 | * Returns an object reference that can be used to manipulate this socket |
597 | * as a Unix socket address. Both objects share the same data. |
598 | */ |
599 | KUnixSocketAddress& asUnix(); |
600 | |
601 | /** |
602 | * Returns an object is equal to this object's data, but they don't share it. |
603 | */ |
604 | KUnixSocketAddress asUnix() const; |
605 | |
606 | protected: |
607 | /// @internal |
608 | /// private data |
609 | KSocketAddressData *d; |
610 | |
611 | /// @internal |
612 | /// extra constructor |
613 | KSocketAddress(KSocketAddressData* d); |
614 | |
615 | public: // static |
616 | /** |
617 | * Returns the IANA family number of the given address family. |
618 | * Returns 0 if there is no corresponding IANA family number. |
619 | * @param af the address family, in AF_* constants |
620 | * @return the IANA family number of this address (1 for AF_INET. |
621 | * 2 for AF_INET6, otherwise 0) |
622 | */ |
623 | static int ianaFamily(int af); |
624 | |
625 | /** |
626 | * Returns the address family of the given IANA family number. |
627 | * @return the address family, AF_UNSPEC for unknown IANA family numbers |
628 | */ |
629 | static int fromIanaFamily(int iana); |
630 | }; |
631 | |
632 | |
633 | /** @class KInetSocketAddress k3socketaddress.h k3socketaddress.h |
634 | * @brief an Internet socket address |
635 | * |
636 | * An Inet (IPv4 or IPv6) socket address |
637 | * |
638 | * This is an IPv4 or IPv6 address of the Internet. |
639 | * |
640 | * @author Thiago Macieira <thiago@kde.org> |
641 | * @deprecated Use KSocketFactory or KLocalSocket instead |
642 | */ |
643 | class KDECORE_EXPORT_DEPRECATED KInetSocketAddress: public KSocketAddress |
644 | { |
645 | friend class KSocketAddress; |
646 | public: |
647 | /** |
648 | * Public constructor. Creates an empty object. |
649 | */ |
650 | KInetSocketAddress(); |
651 | |
652 | /** |
653 | * Creates an object from raw data. |
654 | * |
655 | * Note: if the socket address @p sa does not contain a valid Internet |
656 | * socket (IPv4 or IPv6), this object will be empty. |
657 | * |
658 | * @param sa the sockaddr structure |
659 | * @param len the structure's length |
660 | */ |
661 | KInetSocketAddress(const sockaddr* sa, quint16 len); |
662 | |
663 | /** |
664 | * Creates an object from an IP address and port. |
665 | * |
666 | * @param host the IP address |
667 | * @param port the port number |
668 | */ |
669 | KInetSocketAddress(const KIpAddress& host, quint16 port); |
670 | |
671 | /** |
672 | * Copy constructor. |
673 | * |
674 | * Data is not shared. |
675 | * |
676 | * @param other the other object |
677 | */ |
678 | KInetSocketAddress(const KInetSocketAddress& other); |
679 | |
680 | /** |
681 | * Copy constructor. |
682 | * |
683 | * If the other, generic socket address contains an Internet address, |
684 | * it will be copied. Otherwise, this object will be empty. |
685 | * |
686 | * @param other the other object |
687 | */ |
688 | KInetSocketAddress(const KSocketAddress& other); |
689 | |
690 | /** |
691 | * Destroys this object. |
692 | */ |
693 | virtual ~KInetSocketAddress(); |
694 | |
695 | /** |
696 | * Copy operator. |
697 | * |
698 | * Copies the other object into this one. |
699 | * |
700 | * @param other the other object |
701 | */ |
702 | KInetSocketAddress& operator =(const KInetSocketAddress& other); |
703 | |
704 | /** |
705 | * Cast operator to sockaddr_in. |
706 | */ |
707 | inline operator const sockaddr_in*() const |
708 | { return (const sockaddr_in*)address(); } |
709 | |
710 | /** |
711 | * Cast operator to sockaddr_in6. |
712 | */ |
713 | inline operator const sockaddr_in6*() const |
714 | { return (const sockaddr_in6*)address(); } |
715 | |
716 | /** |
717 | * Returns the IP version of the address this object holds. |
718 | * |
719 | * @return 4 or 6, if IPv4 or IPv6, respectively; 0 if this object is empty |
720 | */ |
721 | int ipVersion() const; |
722 | |
723 | /** |
724 | * Returns the IP address component. |
725 | */ |
726 | KIpAddress ipAddress() const; |
727 | |
728 | /** |
729 | * Sets the IP address to the given raw address. |
730 | * |
731 | * This call will preserve port numbers across IP versions, but will lose |
732 | * IPv6 specific data if the address is set to IPv4. |
733 | * |
734 | * @param addr the address to set to |
735 | * @return a reference to itself |
736 | */ |
737 | KInetSocketAddress& setHost(const KIpAddress& addr); |
738 | |
739 | /** |
740 | * Retrieves the port number stored in this object. |
741 | * |
742 | * @return a port number in the range 0 to 65535, inclusive. An empty or |
743 | * invalid object will have a port number of 0. |
744 | */ |
745 | quint16 port() const; |
746 | |
747 | /** |
748 | * Sets the port number. If this object is empty, this function will default to |
749 | * creating an IPv4 address. |
750 | * |
751 | * @param port the port number to set |
752 | * @return a reference to itself |
753 | */ |
754 | KInetSocketAddress& setPort(quint16 port); |
755 | |
756 | /** |
757 | * Converts this object to an IPv4 socket address. It has no effect if the object |
758 | * is already an IPv4 socket address. |
759 | * |
760 | * If this object is an IPv6 address, the port number is preserved. All other information |
761 | * is lost. |
762 | * |
763 | * @return a reference to itself |
764 | */ |
765 | KInetSocketAddress& makeIPv4(); |
766 | |
767 | /** |
768 | * Converts this object to an IPv6 socket address. It has no effect if the object |
769 | * is already an IPv6 socket address. |
770 | * |
771 | * If this object is an IPv4 address, the port number is preserved. |
772 | * |
773 | * @return a reference to itself |
774 | */ |
775 | KInetSocketAddress& makeIPv6(); |
776 | |
777 | /** |
778 | * Returns the flowinfo information from the IPv6 socket address. |
779 | * |
780 | * @return the flowinfo information or 0 if this object is empty or IPv4 |
781 | */ |
782 | quint32 flowinfo() const; |
783 | |
784 | /** |
785 | * Sets the flowinfo information for an IPv6 socket address. If this is not |
786 | * an IPv6 socket address, this function converts it to one. See makeIPv6. |
787 | * |
788 | * @param flowinfo the flowinfo to set |
789 | * @return a reference to itself |
790 | */ |
791 | KInetSocketAddress& setFlowinfo(quint32 flowinfo); |
792 | |
793 | /** |
794 | * Returns the scope id this IPv6 socket is bound to. |
795 | * |
796 | * @return the scope id, or 0 if this is not an IPv6 object |
797 | */ |
798 | int scopeId() const; |
799 | |
800 | /** |
801 | * Sets the scope id for this IPv6 object. If this is not an IPv6 socket |
802 | * address, this function converts it to one. See makeIPv6 |
803 | * |
804 | * @param scopeid the scopeid to set |
805 | * @return a reference to itself |
806 | */ |
807 | KInetSocketAddress& setScopeId(int scopeid); |
808 | |
809 | protected: |
810 | /// @internal |
811 | /// extra constructor |
812 | KInetSocketAddress(KSocketAddressData* d); |
813 | |
814 | private: |
815 | void update(); |
816 | }; |
817 | |
818 | /* |
819 | * External definition |
820 | */ |
821 | |
822 | /** @class KUnixSocketAddress k3socketaddress.h k3socketaddress.h |
823 | * @brief A Unix (local) socket address. |
824 | * |
825 | * This is a Unix socket address. |
826 | * |
827 | * Note that this class uses QStrings to represent filenames, which means |
828 | * the proper encoding is used to translate into valid filesystem file names. |
829 | * |
830 | * @author Thiago Macieira <thiago@kde.org> |
831 | * @deprecated Use KSocketFactory or KLocalSocket instead |
832 | */ |
833 | class KDECORE_EXPORT_DEPRECATED KUnixSocketAddress: public KSocketAddress |
834 | { |
835 | friend class KSocketAddress; |
836 | public: |
837 | /** |
838 | * Default constructor. Creates an empty object. |
839 | */ |
840 | KUnixSocketAddress(); |
841 | |
842 | /** |
843 | * Creates this object with the given raw data. If |
844 | * the sockaddr structure does not contain a Local namespace |
845 | * (Unix) socket, this object will be created empty. |
846 | * |
847 | * @param sa the socket address structure |
848 | * @param len the structure's length |
849 | */ |
850 | KUnixSocketAddress(const sockaddr* sa, quint16 len); |
851 | |
852 | /** |
853 | * Copy constructor. Creates a copy of the other object, |
854 | * sharing the data explicitly. |
855 | * |
856 | * @param other the other object |
857 | */ |
858 | KUnixSocketAddress(const KUnixSocketAddress& other); |
859 | |
860 | /** |
861 | * Constructs an object from the given pathname. |
862 | */ |
863 | KUnixSocketAddress(const QString& pathname); |
864 | |
865 | /** |
866 | * Destructor. |
867 | */ |
868 | virtual ~KUnixSocketAddress(); |
869 | |
870 | /** |
871 | * Copy operator. Copies the contents of the other object into |
872 | * this one. Data is explicitly shared. |
873 | * |
874 | * @param other the other |
875 | */ |
876 | KUnixSocketAddress& operator =(const KUnixSocketAddress& other); |
877 | |
878 | /** |
879 | * Cast operator to sockaddr_un. |
880 | */ |
881 | inline operator const sockaddr_un*() const |
882 | { return (const sockaddr_un*)address(); } |
883 | |
884 | /** |
885 | * Returns the pathname associated with this object. Will return |
886 | * QString() if this object is empty. |
887 | */ |
888 | QString pathname() const; |
889 | |
890 | /** |
891 | * Sets the pathname for the object. |
892 | * |
893 | * @return a reference to itself |
894 | */ |
895 | KUnixSocketAddress& setPathname(const QString& path); |
896 | |
897 | protected: |
898 | /// @internal |
899 | /// extra constructor |
900 | KUnixSocketAddress(KSocketAddressData* d); |
901 | }; |
902 | |
903 | } // namespace KNetwork |
904 | |
905 | #endif |
906 |
Warning: That file was not part of the compilation database. It may have many parsing errors.