1 /* 2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef H_NETADDRESS 6 #define H_NETADDRESS 7 8 9 #include <BeBuild.h> 10 #include <SupportDefs.h> 11 #include <Archivable.h> 12 13 #include <netinet/in.h> 14 #include <sys/socket.h> 15 16 17 class BNetAddress : public BArchivable { 18 public: 19 BNetAddress(BMessage* archive); 20 virtual ~BNetAddress(); 21 22 virtual status_t Archive(BMessage* into, bool deep = true) const; 23 static BArchivable* Instantiate(BMessage* archive); 24 25 BNetAddress(const char* hostname = 0, unsigned short port = 0); 26 BNetAddress(const struct sockaddr_in& addr); 27 BNetAddress(in_addr addr, int port = 0); 28 BNetAddress(uint32 addr, int port = 0); 29 BNetAddress(const BNetAddress& other); 30 BNetAddress(const char* hostname, const char* protocol, const char* service); 31 32 BNetAddress& operator=(const BNetAddress&); 33 34 status_t InitCheck(); 35 36 status_t SetTo(const char* hostname, const char* protocol, const char* service); 37 status_t SetTo(const char* hostname = NULL, unsigned short port = 0); 38 status_t SetTo(const struct sockaddr_in& addr); 39 status_t SetTo(in_addr addr, int port = 0); 40 status_t SetTo(uint32 addr = INADDR_ANY, int port = 0); 41 42 status_t GetAddr(char* hostname = NULL, unsigned short* port = NULL) const; 43 status_t GetAddr(struct sockaddr_in& addr) const; 44 status_t GetAddr(in_addr& addr, unsigned short* port = NULL) const; 45 46 private: 47 virtual void _ReservedBNetAddressFBCCruft1(); 48 virtual void _ReservedBNetAddressFBCCruft2(); 49 virtual void _ReservedBNetAddressFBCCruft3(); 50 virtual void _ReservedBNetAddressFBCCruft4(); 51 virtual void _ReservedBNetAddressFBCCruft5(); 52 virtual void _ReservedBNetAddressFBCCruft6(); 53 54 status_t fInit; 55 int32 fFamily; 56 int32 fPort; 57 int32 fAddress; 58 int32 fPrivateData[6]; 59 }; 60 61 #endif // H_NETADDRESS 62