00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
#ifndef _PIPSOCKET
00240
#define _PIPSOCKET
00241
00242
#ifdef P_USE_PRAGMA
00243
#pragma interface
00244
#endif
00245
00246
#include <ptlib/socket.h>
00247
00255 class PIPSocket :
public PSocket
00256 {
00257
PCLASSINFO(
PIPSocket,
PSocket);
00258
protected:
00259
00260
00261
00262
PIPSocket();
00263
00264
public:
00268 class Address :
public PObject {
00269
public:
00270
00273
00274
Address();
00275
00279
Address(
const PString & dotNotation);
00280
00282
Address(PINDEX len,
const BYTE * bytes);
00283
00285
Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
00286
00288
Address(DWORD dw);
00289
00291
Address(
const in_addr & addr);
00292
00293
#if P_HAS_IPV6
00294
00295
Address(
const in6_addr & addr);
00296
00299
Address(
const int ai_family,
const int ai_addrlen,
struct sockaddr *ai_addr);
00300
#endif
00301
00302
#ifdef __NUCLEUS_NET__
00303
Address(
const struct id_struct & addr);
00304
Address &
operator=(
const struct id_struct & addr);
00305
#endif
00306
00308
Address &
operator=(
const in_addr & addr);
00309
00310
#if P_HAS_IPV6
00311
00312
Address &
operator=(
const in6_addr & addr);
00313
#endif
00314
00316
Address &
operator=(
const PString & dotNotation);
00317
00319
Address &
operator=(DWORD dw);
00321
00323 Comparison
Compare(
const PObject & obj)
const;
00324 bool operator==(
const Address & addr)
const {
return Compare(addr) == EqualTo; }
00325 bool operator!=(
const Address & addr)
const {
return Compare(addr) != EqualTo; }
00326
#if P_HAS_IPV6
00327
bool operator==(in6_addr & addr)
const;
00328
bool operator!=(in6_addr & addr)
const {
return !operator==(addr); }
00329
#endif
00330
bool operator==(in_addr & addr)
const;
00331 bool operator!=(in_addr & addr)
const {
return !
operator==(addr); }
00332
bool operator==(DWORD dw)
const;
00333 bool operator!=(DWORD dw)
const {
return !
operator==(dw); }
00334
#ifdef P_VXWORKS
00335
bool operator==(
long unsigned int u)
const {
return operator==((DWORD)u); }
00336
bool operator!=(
long unsigned int u)
const {
return !operator==((DWORD)u); }
00337
#endif
00338
#ifdef _WIN32
00339
bool operator==(
unsigned u)
const {
return operator==((DWORD)u); }
00340
bool operator!=(
unsigned u)
const {
return !
operator==((DWORD)u); }
00341
#endif
00342
#ifdef P_RTEMS
00343
bool operator==(u_long u)
const {
return operator==((DWORD)u); }
00344
bool operator!=(u_long u)
const {
return !
operator==((DWORD)u); }
00345
#endif
00346
#ifdef __BEOS__
00347
bool operator==(in_addr_t a)
const {
return operator==((DWORD)a); }
00348
bool operator!=(in_addr_t a)
const {
return !
operator==((DWORD)a); }
00349
#endif
00350 bool operator==(
int i)
const {
return operator==((DWORD)i); }
00351 bool operator!=(
int i)
const {
return !
operator==((DWORD)i); }
00352
00354
PString AsString() const;
00355
00357 BOOL FromString(
00358 const
PString & str
00359 );
00360
00362 operator
PString() const;
00363
00365 operator in_addr() const;
00366
00367 #if P_HAS_IPV6
00369 operator in6_addr() const;
00370 #endif
00371
00373 operator DWORD() const;
00374
00376 BYTE Byte1() const;
00377
00379 BYTE Byte2() const;
00380
00382 BYTE Byte3() const;
00383
00385 BYTE Byte4() const;
00386
00388 BYTE operator[](PINDEX idx) const;
00389
00391 PINDEX GetSize() const;
00392
00394 const
char * GetPointer()
const {
return (
const char *)&
v; }
00395
00397 unsigned GetVersion()
const {
return version; }
00398
00400 BOOL
IsValid() const;
00401 BOOL IsAny();
00402
00404 BOOL IsLoopback() const;
00405
00407 BOOL IsBroadcast() const;
00408
00409
00410
00411
00412
00413
00414 BOOL IsRFC1918()
const
00415
{
return (
Byte1() == 10)
00416 ||
00417 (
00418 (
Byte1() == 172)
00419 &&
00420 (
Byte2() >= 16) && (
Byte2() <= 31)
00421 )
00422 ||
00423 (
00424 (
Byte1() == 192)
00425 &&
00426 (
Byte2() == 168)
00427 );
00428 }
00429
00430
#if P_HAS_IPV6
00431
00432 BOOL IsV4Mapped() const;
00433 #endif
00434
00435 static const
Address & GetLoopback();
00436 #if P_HAS_IPV6
00437 static const
Address & GetLoopback6();
00438 static const
Address & GetAny6();
00439 #endif
00440 static const
Address & GetBroadcast();
00441
00442 protected:
00444 union {
00445 in_addr
four;
00446
#if P_HAS_IPV6
00447
in6_addr six;
00448
#endif
00449
} v;
00450 unsigned version;
00451
00453
friend ostream &
operator<<(ostream & s,
const Address & a);
00454
00456
friend istream &
operator>>(istream & s,
Address & a);
00457 };
00458
00459
00467
virtual PString GetName() const;
00468
00469
00470
00471
00472
00473
00474 static
int GetDefaultIpAddressFamily();
00475 static
void SetDefaultIpAddressFamily(
int ipAdressFamily);
00476 static
void SetDefaultIpAddressFamilyV4();
00477 #if P_HAS_IPV6
00478 static
void SetDefaultIpAddressFamilyV6();
00479 static BOOL IsIpAddressFamilyV6Supported();
00480 #endif
00481 static
PIPSocket::
Address GetDefaultIpAny();
00482
00483
00484 virtual BOOL OpenSocket(
00485
int ipAdressFamily=PF_INET
00486 ) = 0;
00487
00488
00489
00501 virtual BOOL Connect(
00502 const
PString & address
00503 );
00504 virtual BOOL Connect(
00505 const
Address & addr
00506 );
00507 virtual BOOL Connect(
00508 WORD localPort,
00509 const
Address & addr
00510 );
00511 virtual BOOL Connect(
00512 const
Address & iface,
00513 const
Address & addr
00514 );
00515 virtual BOOL Connect(
00516 const
Address & iface,
00517 WORD localPort,
00518 const
Address & addr
00519 );
00520
00536 virtual BOOL Listen(
00537
unsigned queueSize = 5,
00538 WORD port = 0,
00539 Reusability reuse = AddressIsExclusive
00540 );
00541 virtual BOOL Listen(
00542 const
Address & bind,
00543
unsigned queueSize = 5,
00544 WORD port = 0,
00545 Reusability reuse = AddressIsExclusive
00546 );
00547
00548
00549
00557 static
PString GetHostName();
00558 static
PString GetHostName(
00559 const
PString & hostname
00560 );
00561 static
PString GetHostName(
00562 const
Address & addr
00563 );
00564
00571 static BOOL GetHostAddress(
00572
Address & addr
00573 );
00574 static BOOL GetHostAddress(
00575 const
PString & hostname,
00576
00577
00578
00579
Address & addr
00580 );
00581
00589 static
PStringArray GetHostAliases(
00590 const
PString & hostname
00591
00592
00593
00594 );
00595 static
PStringArray GetHostAliases(
00596 const
Address & addr
00597
00598
00599
00600 );
00601
00609 static BOOL IsLocalHost(
00610 const
PString & hostname
00611
00612
00613
00614 );
00615
00621 virtual BOOL GetLocalAddress(
00622
Address & addr
00623 );
00624 virtual BOOL GetLocalAddress(
00625
Address & addr,
00626 WORD & port
00627 );
00628
00635 virtual BOOL GetPeerAddress(
00636
Address & addr
00637 );
00638 virtual BOOL GetPeerAddress(
00639
Address & addr,
00640 WORD & port
00641 );
00642
00648
PString GetLocalHostName();
00649
00655
PString GetPeerHostName();
00656
00659 static
void ClearNameCache();
00660
00672 static BOOL GetGatewayAddress(
00673
Address & addr
00674 );
00675
00688 static
PString GetGatewayInterface();
00689
00693 class
RouteEntry : public
PObject
00694 {
00695
PCLASSINFO(
RouteEntry, PObject);
00696
public:
00698 RouteEntry(
const Address & addr) : network(addr) { }
00699
00701 Address GetNetwork()
const {
return network; }
00702
00704 Address GetNetMask()
const {
return net_mask; }
00705
00707 Address GetDestination()
const {
return destination; }
00708
00710 const PString & GetInterface()
const {
return interfaceName; }
00711
00713 long GetMetric()
const {
return metric; }
00714
00715
protected:
00716 Address network;
00717 Address net_mask;
00718 Address destination;
00719 PString interfaceName;
00720 long metric;
00721
00722
friend class PIPSocket;
00723 };
00724
00725
PLIST(RouteTable,
RouteEntry);
00726
00732
static BOOL
GetRouteTable(
00733 RouteTable & table
00734 );
00735
00736
00740 class InterfaceEntry :
public PObject
00741 {
00742
PCLASSINFO(
InterfaceEntry,
PObject)
00743
00744
public:
00746
InterfaceEntry(
00747
const PString & _name,
00748
const Address & _addr,
00749
const Address & _mask,
00750
const PString & _macAddr
00751 );
00752
00754
virtual void PrintOn(
00755 ostream &strm
00756 )
const;
00757
00759 const PString &
GetName()
const {
return name; }
00760
00762 Address GetAddress()
const {
return ipAddr; }
00763
00765 Address GetNetMask()
const {
return netMask; }
00766
00768 const PString &
GetMACAddress()
const {
return macAddr; }
00769
00770
protected:
00771 PString name;
00772 Address ipAddr;
00773 Address netMask;
00774 PString macAddr;
00775 };
00776
00777
PLIST(InterfaceTable,
InterfaceEntry);
00778
00784
static BOOL
GetInterfaceTable(
00785 InterfaceTable & table
00786 );
00787
00788
00789
00790
#ifdef _WIN32
00791
#include "msos/ptlib/ipsock.h"
00792
#else
00793
#include "unix/ptlib/ipsock.h"
00794
#endif
00795
};
00796
00797
#endif
00798
00799
00800