xref: /haiku/headers/os/net/NetAddress.h (revision 49a22456ddda2a7cfc5c19d9ccc131125b8b690c)
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,
31 			const char* service);
32 
33 		BNetAddress& operator=(const BNetAddress&);
34 
35 		status_t InitCheck() const;
36 
37 		status_t SetTo(const char* hostname, const char* protocol,
38 			const char* service);
39 		status_t SetTo(const char* hostname = NULL, unsigned short port = 0);
40 		status_t SetTo(const struct sockaddr_in& addr);
41 		status_t SetTo(in_addr addr, int port = 0);
42 		status_t SetTo(uint32 addr = INADDR_ANY, int port = 0);
43 
44 		status_t GetAddr(char* hostname = NULL,
45 			unsigned short* port = NULL) const;
46 		status_t GetAddr(struct sockaddr_in& addr) const;
47 		status_t GetAddr(in_addr& addr, unsigned short* port = NULL) const;
48 
49 		// TODO: drop this compatibility cruft method after R1
50 		status_t InitCheck();
51 
52 	private:
53 		virtual void _ReservedBNetAddressFBCCruft1();
54 		virtual void _ReservedBNetAddressFBCCruft2();
55 		virtual void _ReservedBNetAddressFBCCruft3();
56 		virtual void _ReservedBNetAddressFBCCruft4();
57 		virtual void _ReservedBNetAddressFBCCruft5();
58 		virtual void _ReservedBNetAddressFBCCruft6();
59 
60 		status_t fInit;
61 		int16	fFamily;
62 		int16	fPort;
63 		int32	fAddress;
64 		int32	fPrivateData[7];
65 };
66 
67 #endif	// H_NETADDRESS
68