rcnetdb.h (2597B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 ** Base class definitions for network access functions (ref: prnetdb.h) 8 */ 9 10 #if defined(_RCNETDB_H) 11 #else 12 #define _RCNETDB_H 13 14 #include "rclock.h" 15 #include "rcbase.h" 16 17 #include <prnetdb.h> 18 19 class PR_IMPLEMENT(RCNetAddr): public RCBase 20 { 21 public: 22 typedef enum { 23 any = PR_IpAddrAny, /* assign logical INADDR_ANY */ 24 loopback = PR_IpAddrLoopback /* assign logical INADDR_LOOPBACK */ 25 } HostValue; 26 27 RCNetAddr(); /* default constructor is unit'd object */ 28 RCNetAddr(const RCNetAddr&); /* copy constructor */ 29 RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */ 30 RCNetAddr(const RCNetAddr&, PRUint16 port); 31 /* copy w/ port reassigment */ 32 33 virtual ~RCNetAddr(); 34 35 void operator=(const RCNetAddr&); 36 37 virtual PRBool operator==(const RCNetAddr&) const; 38 /* compare of all relavent fields */ 39 virtual PRBool EqualHost(const RCNetAddr&) const; 40 /* compare of just host field */ 41 42 43 public: 44 45 void operator=(const PRNetAddr*); /* construction from more primitive data */ 46 operator const PRNetAddr*() const; /* extraction of underlying representation */ 47 virtual PRStatus FromString(const char* string); 48 /* initialization from an ASCII string */ 49 virtual PRStatus ToString(char *string, PRSize size) const; 50 /* convert internal fromat to a string */ 51 52 private: 53 54 PRNetAddr address; 55 56 }; /* RCNetAddr */ 57 58 /* 59 ** Class: RCHostLookup 60 ** 61 ** Abstractions to look up host names and addresses. 62 ** 63 ** This is a stateful class. One looks up the host by name or by 64 ** address, then enumerates over a possibly empty array of network 65 ** addresses. The storage for the addresses is owned by the class. 66 */ 67 68 class RCHostLookup: public RCBase 69 { 70 public: 71 virtual ~RCHostLookup(); 72 73 RCHostLookup(); 74 75 virtual PRStatus ByName(const char* name); 76 virtual PRStatus ByAddress(const RCNetAddr&); 77 78 virtual const RCNetAddr* operator[](PRUintn); 79 80 private: 81 RCLock ml; 82 PRIntn max_index; 83 RCNetAddr* address; 84 85 RCHostLookup(const RCHostLookup&); 86 RCHostLookup& operator=(const RCHostLookup&); 87 }; 88 89 inline RCNetAddr::RCNetAddr(): RCBase() { } 90 inline RCNetAddr::operator const PRNetAddr*() const { 91 return &address; 92 } 93 94 95 #endif /* defined(_RCNETDB_H) */ 96 97 /* RCNetdb.h */