Re-written by Scott Mansfield <[email protected]>

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1548 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2002-10-16 22:54:05 +00:00
parent f19a36df3e
commit ae68bb3273
+106 -113
View File
@@ -1,113 +1,106 @@
//------------------------------------------------------------------------------ /*=--------------------------------------------------------------------------=*
// Copyright (c) 2001-2002, OpenBeOS * NetAddress.h -- Interface definition for the BNetAddress class.
// *
// Permission is hereby granted, free of charge, to any person obtaining a * Written by S.T. Mansfield ([email protected])
// copy of this software and associated documentation files (the "Software"), *
// to deal in the Software without restriction, including without limitation * Remarks:
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Mr. Phipps, put that fish away, dude.
// and/or sell copies of the Software, and to permit persons to whom the *=--------------------------------------------------------------------------=*
// Software is furnished to do so, subject to the following conditions: * Copyright (c) 2002, The OpenBeOS project.
// *
// The above copyright notice and this permission notice shall be included in * Permission is hereby granted, free of charge, to any person obtaining a
// all copies or substantial portions of the Software. * copy of this software and associated documentation files (the "Software"),
// * to deal in the Software without restriction, including without limitation
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * the rights to use, copy, modify, merge, publish, distribute, sublicense,
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * and/or sell copies of the Software, and to permit persons to whom the
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * Software is furnished to do so, subject to the following conditions:
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * The above copyright notice and this permission notice shall be included in
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * all copies or substantial portions of the Software.
// DEALINGS IN THE SOFTWARE. *
//------------------------------------------------------------------------------ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#ifndef _NETADDRESS_H * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#define _NETADDRESS_H * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#include <BeBuild.h> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#include <SupportDefs.h> * DEALINGS IN THE SOFTWARE.
#include <Archivable.h> *=--------------------------------------------------------------------------=*
*/
#include <sys/socket.h>
#include <netinet/in.h> #ifndef NETADDRESS_H
#define NETADDRESS_H
/*
* BNetAddress #include <Archivable.h>
* #include <Errors.h>
* This class is used to represent network addresses, and provide access #include <Application.h>
* to a network address in a variety of formats. BNetAddress provides various ways #include <Message.h>
* to get and set a network address, converting to or from the chosen representation
* into a generic internal one. /*
*/ * Empty forward declaration to satisfy the GetImpl method.
*/
class NLAddress; class NLAddress;
class BNetAddress : public BArchivable class BNetAddress : public BArchivable
{ {
public: public:
BNetAddress( BMessage* archive );
BNetAddress(BMessage *archive); virtual ~BNetAddress( void );
virtual ~BNetAddress();
virtual status_t Archive( BMessage* into, bool deep = true ) const;
virtual status_t Archive(BMessage *into, bool deep = true) const; static BArchivable* Instantiate( BMessage* archive );
static BArchivable *Instantiate(BMessage *archive);
BNetAddress( const char* hostname = NULL, unsigned short port = 0 );
BNetAddress(const char *hostname = 0, unsigned short port = 0); BNetAddress( const struct sockaddr_in& sa );
BNetAddress(const struct sockaddr_in &sa); BNetAddress( in_addr addr, int port = 0 );
BNetAddress(in_addr addr, int port = 0); BNetAddress( uint32 addr, int port = 0 );
BNetAddress(uint32 addr, int port = 0 ); BNetAddress( const BNetAddress& refparam );
BNetAddress(const BNetAddress &); BNetAddress( const char* hostname, const char* protocol, const char* service );
BNetAddress(const char *hostname, const char *protocol, const char *service);
BNetAddress& operator=( const BNetAddress& );
BNetAddress &operator=(const BNetAddress &);
status_t InitCheck( void ) const;
/*
* It is important to call InitCheck() after creating an instance of this class. status_t SetTo( const char* hostname, const char* protocol, const char* service );
*/ status_t SetTo( const char* hostname = NULL, unsigned short port = 0 );
status_t InitCheck(); status_t SetTo( const struct sockaddr_in& sa );
status_t SetTo( in_addr addr, int port = 0 );
/* status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 );
* BNetAddress::set() sets the internal address representation to refer
* to the internet address specified by the passed-in data. status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const;
* Returns true if successful, false otherwise. status_t GetAddr( struct sockaddr_in& sa ) const;
*/ status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const;
status_t SetTo(const char *hostname, const char *protocol, const char *service);
status_t SetTo(const char *hostname = 0, unsigned short port = 0); inline NLAddress *GetImpl( void ) const;
status_t SetTo(const struct sockaddr_in &sa);
status_t SetTo(in_addr addr, int port = 0); protected:
status_t SetTo(uint32 addr=INADDR_ANY, int port = 0); // Attributes.
status_t fInitialized;
/*
* BNetAddress::get() converts the internal internet address representation // Class-specific attributes. Basically re-encapsulate the saddr_in
* into the specified form and returns it by filling in the passed-in parameters. // struct (the POSiX version, hopefully). We can be inheritance-friendly
* Returns true if successful, false otherwise. // here and still not break binary compatibility with R5.
*/ int32 fFamily; // Encapsulation of sockaddr::sin_family
status_t GetAddr(char *hostname = 0, unsigned short *port = 0) const; int32 fPort; // Encapsulation of sockaddr::sin_port
status_t GetAddr(struct sockaddr_in &sa) const; int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr
status_t GetAddr(in_addr &addr, unsigned short *port = 0) const;
private:
inline NLAddress *GetImpl() const; // Private copy helper.
status_t clone( const BNetAddress& RefParam );
protected:
status_t m_init; // Not used, here to maintain R5 binary compatiblilty.
int32 fPrivateData[6];
private: };
virtual void _ReservedBNetAddressFBCCruft1();
virtual void _ReservedBNetAddressFBCCruft2();
virtual void _ReservedBNetAddressFBCCruft3(); // WARNING: This method, as it stands, breaks R5 compatibility *STM*.
virtual void _ReservedBNetAddressFBCCruft4(); inline NLAddress* BNetAddress::GetImpl( void ) const
virtual void _ReservedBNetAddressFBCCruft5(); {
virtual void _ReservedBNetAddressFBCCruft6(); return NULL; // Cheeky, yes; but no Nettle stuff is allowed...
}
int32 __ReservedBNetAddressFBCCruftData[9];
}; #endif // <-- #ifndef NETADDRESS_H
/*=------------------------------------------------------------------- End -=*/
inline NLAddress *BNetAddress::GetImpl() const
{
return NULL; // No Nettle backward compatibility
}
#endif // _NETADDRESS_H