1 /*=--------------------------------------------------------------------------=* 2 * NetAddress.h -- Interface definition for the BNetAddress class. 3 * 4 * Written by S.T. Mansfield (thephantom@mac.com) 5 *=--------------------------------------------------------------------------=* 6 * Copyright (c) 2002, The OpenBeOS project. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 * DEALINGS IN THE SOFTWARE. 25 *=--------------------------------------------------------------------------=* 26 */ 27 28 #ifndef _NETADDRESS_H 29 #define _NETADDRESS_H 30 31 #include <BeBuild.h> 32 #include <SupportDefs.h> 33 #include <Archivable.h> 34 #include <socket.h> 35 36 /* 37 * Empty forward declaration to satisfy the GetImpl method. 38 */ 39 class NLAddress; 40 41 class BNetAddress : public BArchivable 42 { 43 public: 44 BNetAddress( BMessage* archive ); 45 virtual ~BNetAddress(); 46 47 virtual status_t Archive( BMessage* into, bool deep = true ) const; 48 static BArchivable* Instantiate( BMessage* archive ); 49 50 BNetAddress( const char* hostname = 0, unsigned short port = 0 ); 51 BNetAddress( const struct sockaddr_in& sa ); 52 BNetAddress( in_addr addr, int port = 0 ); 53 BNetAddress( uint32 addr, int port = 0 ); 54 BNetAddress( const BNetAddress& refparam ); 55 BNetAddress( const char* hostname, const char* protocol, const char* service ); 56 57 BNetAddress& operator=( const BNetAddress& ); 58 59 status_t InitCheck(); 60 61 status_t SetTo( const char* hostname, const char* protocol, const char* service ); 62 status_t SetTo( const char* hostname = NULL, unsigned short port = 0 ); 63 status_t SetTo( const struct sockaddr_in& sa ); 64 status_t SetTo( in_addr addr, int port = 0 ); 65 status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 ); 66 67 status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const; 68 status_t GetAddr( struct sockaddr_in& sa ) const; 69 status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const; 70 71 inline NLAddress *GetImpl() const; 72 73 protected: 74 status_t m_init; 75 76 private: 77 virtual void _ReservedBNetAddressFBCCruft1(); 78 virtual void _ReservedBNetAddressFBCCruft2(); 79 virtual void _ReservedBNetAddressFBCCruft3(); 80 virtual void _ReservedBNetAddressFBCCruft4(); 81 virtual void _ReservedBNetAddressFBCCruft5(); 82 virtual void _ReservedBNetAddressFBCCruft6(); 83 84 // Private copy helper. 85 status_t clone( const BNetAddress& RefParam ); 86 87 int32 fFamily; // Encapsulation of sockaddr::sin_family 88 int32 fPort; // Encapsulation of sockaddr::sin_port 89 int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr 90 91 // Not used, here to maintain R5 binary compatiblilty. 92 int32 fPrivateData[6]; 93 }; 94 95 96 inline NLAddress* BNetAddress::GetImpl( void ) const 97 { 98 return NULL; 99 } 100 101 #endif // <-- #ifndef _NETADDRESS_H 102 103 104 /*=------------------------------------------------------------------- End -=*/ 105 106