xref: /haiku/src/add-ons/kernel/file_systems/netfs/headers/shared/NetAddress.h (revision ca8ed5ea660fb6275799a3b7f138b201c41a667b)
1 // NetAddress.h
2 
3 #ifndef NET_FS_NET_ADDRESS_H
4 #define NET_FS_NET_ADDRESS_H
5 
6 #ifdef HAIKU_TARGET_PLATFORM_BEOS
7 #	include <socket.h>
8 #else
9 #	include <netinet/in.h>
10 #	include <sys/socket.h>
11 #endif
12 
13 namespace BPrivate {
14 class HashString;
15 };
16 using BPrivate::HashString;
17 
18 // NetAddress
19 class NetAddress {
20 public:
21 								NetAddress();
22 								NetAddress(const sockaddr_in& address);
23 								NetAddress(const NetAddress& address);
24 
25 			void				SetIP(int32 address);
26 			int32				GetIP() const;
27 
28 			void				SetPort(uint16 port);
29 			uint16				GetPort() const;
30 
31 			void				SetAddress(const sockaddr_in& address);
32 			const sockaddr_in&	GetAddress() const;
33 
34 			bool				IsLocal() const;
35 
36 			status_t			GetString(HashString* string,
37 									bool includePort = true) const;
38 
39 			uint32				GetHashCode() const;
40 
41 			NetAddress&			operator=(const NetAddress& address);
42 			bool				operator==(const NetAddress& address) const;
43 			bool				operator!=(const NetAddress& address) const;
44 
45 private:
46 			sockaddr_in			fAddress;
47 };
48 
49 // NetAddressResolver
50 class NetAddressResolver {
51 public:
52 								NetAddressResolver();
53 								~NetAddressResolver();
54 
55 			status_t			InitCheck() const;
56 
57 			status_t			GetHostAddress(const char* hostName,
58 									NetAddress* address);
59 
60 private:
61 			class Resolver;
62 
63 	static	void				_Lock();
64 	static	void				_Unlock();
65 
66 			Resolver*			fResolver;
67 
68 	static	Resolver* volatile	sResolver;
69 	static	int32				sLockCounter;
70 };
71 
72 #endif	// NET_FS_NET_ADDRESS_H
73