* Cleanup, no functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38362 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
00a2914f9c
commit
4cd42050fa
@ -1,11 +1,10 @@
|
||||
/*
|
||||
* Copyright 2007-2008, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2007-2010, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos, hugosantos@gmail.com
|
||||
*/
|
||||
|
||||
#ifndef NET_ADDRESS_UTILITIES_H
|
||||
#define NET_ADDRESS_UTILITIES_H
|
||||
|
||||
@ -18,16 +17,28 @@
|
||||
|
||||
class SocketAddress {
|
||||
public:
|
||||
SocketAddress(net_address_module_info *module, sockaddr *address)
|
||||
: fModule(module), fAddress(address) {}
|
||||
SocketAddress(net_address_module_info* module, sockaddr* address)
|
||||
:
|
||||
fModule(module),
|
||||
fAddress(address)
|
||||
{
|
||||
}
|
||||
|
||||
SocketAddress(net_address_module_info *module, sockaddr_storage *address)
|
||||
: fModule(module), fAddress((sockaddr *)address) {}
|
||||
SocketAddress(net_address_module_info* module, sockaddr_storage* address)
|
||||
:
|
||||
fModule(module),
|
||||
fAddress((sockaddr*)address)
|
||||
{
|
||||
}
|
||||
|
||||
SocketAddress(const SocketAddress &address)
|
||||
: fModule(address.fModule), fAddress(address.fAddress) {}
|
||||
SocketAddress(const SocketAddress& address)
|
||||
:
|
||||
fModule(address.fModule),
|
||||
fAddress(address.fAddress)
|
||||
{
|
||||
}
|
||||
|
||||
void SetAddressTo(sockaddr *address)
|
||||
void SetAddressTo(sockaddr* address)
|
||||
{
|
||||
fAddress = address;
|
||||
}
|
||||
@ -37,30 +48,30 @@ public:
|
||||
return fModule->is_empty_address(fAddress, checkPort);
|
||||
}
|
||||
|
||||
uint32 HashPair(const sockaddr *second) const
|
||||
uint32 HashPair(const sockaddr* second) const
|
||||
{
|
||||
return fModule->hash_address_pair(fAddress, second);
|
||||
}
|
||||
|
||||
bool EqualTo(const sockaddr *address, bool checkPort = false) const
|
||||
bool EqualTo(const sockaddr* address, bool checkPort = false) const
|
||||
{
|
||||
if (checkPort)
|
||||
return fModule->equal_addresses_and_ports(fAddress, address);
|
||||
else
|
||||
return fModule->equal_addresses(fAddress, address);
|
||||
|
||||
return fModule->equal_addresses(fAddress, address);
|
||||
}
|
||||
|
||||
bool EqualTo(const SocketAddress &second, bool checkPort = false) const
|
||||
bool EqualTo(const SocketAddress& second, bool checkPort = false) const
|
||||
{
|
||||
return EqualTo(second.fAddress, checkPort);
|
||||
}
|
||||
|
||||
bool EqualPorts(const sockaddr *second) const
|
||||
bool EqualPorts(const sockaddr* second) const
|
||||
{
|
||||
return fModule->equal_ports(fAddress, second);
|
||||
}
|
||||
|
||||
bool MatchMasked(const sockaddr *address, const sockaddr *mask) const
|
||||
bool MatchMasked(const sockaddr* address, const sockaddr* mask) const
|
||||
{
|
||||
return fModule->equal_masked_addresses(fAddress, address, mask);
|
||||
}
|
||||
@ -70,24 +81,24 @@ public:
|
||||
return fModule->get_port(fAddress);
|
||||
}
|
||||
|
||||
status_t SetTo(const sockaddr *from)
|
||||
status_t SetTo(const sockaddr* from)
|
||||
{
|
||||
return fModule->set_to(fAddress, from);
|
||||
}
|
||||
|
||||
status_t SetTo(const sockaddr_storage *from)
|
||||
status_t SetTo(const sockaddr_storage* from)
|
||||
{
|
||||
return SetTo((sockaddr *)from);
|
||||
return SetTo((sockaddr*)from);
|
||||
}
|
||||
|
||||
status_t CopyTo(sockaddr *to) const
|
||||
status_t CopyTo(sockaddr* to) const
|
||||
{
|
||||
return fModule->set_to(to, fAddress);
|
||||
}
|
||||
|
||||
status_t CopyTo(sockaddr_storage *to) const
|
||||
status_t CopyTo(sockaddr_storage* to) const
|
||||
{
|
||||
return CopyTo((sockaddr *)to);
|
||||
return CopyTo((sockaddr*)to);
|
||||
}
|
||||
|
||||
status_t SetPort(uint16 port)
|
||||
@ -100,7 +111,7 @@ public:
|
||||
return fModule->set_to_empty_address(fAddress);
|
||||
}
|
||||
|
||||
status_t UpdateTo(const sockaddr *from)
|
||||
status_t UpdateTo(const sockaddr* from)
|
||||
{
|
||||
return fModule->update_to(fAddress, from);
|
||||
}
|
||||
@ -110,39 +121,57 @@ public:
|
||||
return AddressString(fModule, fAddress, printPort);
|
||||
}
|
||||
|
||||
const char *AsString(char *buffer, size_t bufferSize,
|
||||
bool printPort = false) const {
|
||||
const char* AsString(char* buffer, size_t bufferSize,
|
||||
bool printPort = false) const
|
||||
{
|
||||
fModule->print_address_buffer(fAddress, buffer, bufferSize, printPort);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const sockaddr *operator *() const { return fAddress; }
|
||||
sockaddr *operator *() { return fAddress; }
|
||||
const sockaddr* operator*() const { return fAddress; }
|
||||
sockaddr* operator*() { return fAddress; }
|
||||
|
||||
net_address_module_info *Module() const { return fModule; }
|
||||
net_address_module_info* Module() const { return fModule; }
|
||||
|
||||
private:
|
||||
net_address_module_info *fModule;
|
||||
sockaddr *fAddress;
|
||||
net_address_module_info* fModule;
|
||||
sockaddr* fAddress;
|
||||
};
|
||||
|
||||
|
||||
class ConstSocketAddress {
|
||||
public:
|
||||
ConstSocketAddress(net_address_module_info *module,
|
||||
const sockaddr *address)
|
||||
: fModule(module), fAddress(address) {}
|
||||
ConstSocketAddress(net_address_module_info* module,
|
||||
const sockaddr* address)
|
||||
:
|
||||
fModule(module),
|
||||
fAddress(address)
|
||||
{
|
||||
}
|
||||
|
||||
ConstSocketAddress(net_address_module_info *module,
|
||||
const sockaddr_storage *address)
|
||||
: fModule(module), fAddress((sockaddr *)address) {}
|
||||
ConstSocketAddress(net_address_module_info* module,
|
||||
const sockaddr_storage* address)
|
||||
:
|
||||
fModule(module),
|
||||
fAddress((sockaddr*)address)
|
||||
{
|
||||
}
|
||||
|
||||
ConstSocketAddress(const ConstSocketAddress &address)
|
||||
: fModule(address.fModule), fAddress(address.fAddress) {}
|
||||
ConstSocketAddress(const ConstSocketAddress& address)
|
||||
:
|
||||
fModule(address.fModule),
|
||||
fAddress(address.fAddress)
|
||||
{
|
||||
}
|
||||
|
||||
ConstSocketAddress(const SocketAddress &address)
|
||||
: fModule(address.Module()), fAddress(*address) {}
|
||||
ConstSocketAddress(const SocketAddress& address)
|
||||
:
|
||||
fModule(address.Module()),
|
||||
fAddress(*address)
|
||||
{
|
||||
}
|
||||
|
||||
void SetAddressTo(const sockaddr *address)
|
||||
void SetAddressTo(const sockaddr* address)
|
||||
{
|
||||
fAddress = address;
|
||||
}
|
||||
@ -152,12 +181,12 @@ public:
|
||||
return fModule->is_empty_address(fAddress, checkPort);
|
||||
}
|
||||
|
||||
uint32 HashPair(const sockaddr *second) const
|
||||
uint32 HashPair(const sockaddr* second) const
|
||||
{
|
||||
return fModule->hash_address_pair(fAddress, second);
|
||||
}
|
||||
|
||||
bool EqualTo(const sockaddr *address, bool checkPort = false) const
|
||||
bool EqualTo(const sockaddr* address, bool checkPort = false) const
|
||||
{
|
||||
if (checkPort)
|
||||
return fModule->equal_addresses_and_ports(fAddress, address);
|
||||
@ -165,12 +194,12 @@ public:
|
||||
return fModule->equal_addresses(fAddress, address);
|
||||
}
|
||||
|
||||
bool EqualPorts(const sockaddr *second) const
|
||||
bool EqualPorts(const sockaddr* second) const
|
||||
{
|
||||
return fModule->equal_ports(fAddress, second);
|
||||
}
|
||||
|
||||
bool MatchMasked(const sockaddr *address, const sockaddr *mask) const
|
||||
bool MatchMasked(const sockaddr* address, const sockaddr* mask) const
|
||||
{
|
||||
return fModule->equal_masked_addresses(fAddress, address, mask);
|
||||
}
|
||||
@ -180,14 +209,14 @@ public:
|
||||
return fModule->get_port(fAddress);
|
||||
}
|
||||
|
||||
status_t CopyTo(sockaddr *to) const
|
||||
status_t CopyTo(sockaddr* to) const
|
||||
{
|
||||
return fModule->set_to(to, fAddress);
|
||||
}
|
||||
|
||||
status_t CopyTo(sockaddr_storage *to) const
|
||||
status_t CopyTo(sockaddr_storage* to) const
|
||||
{
|
||||
return CopyTo((sockaddr *)to);
|
||||
return CopyTo((sockaddr*)to);
|
||||
}
|
||||
|
||||
AddressString AsString(bool printPort = false) const
|
||||
@ -195,28 +224,32 @@ public:
|
||||
return AddressString(fModule, fAddress, printPort);
|
||||
}
|
||||
|
||||
const char *AsString(char *buffer, size_t bufferSize,
|
||||
const char* AsString(char* buffer, size_t bufferSize,
|
||||
bool printPort = false) const
|
||||
{
|
||||
fModule->print_address_buffer(fAddress, buffer, bufferSize, printPort);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const sockaddr *operator *() const { return fAddress; }
|
||||
const sockaddr* operator*() const { return fAddress; }
|
||||
|
||||
private:
|
||||
net_address_module_info *fModule;
|
||||
const sockaddr *fAddress;
|
||||
net_address_module_info* fModule;
|
||||
const sockaddr* fAddress;
|
||||
};
|
||||
|
||||
|
||||
class SocketAddressStorage : public SocketAddress {
|
||||
public:
|
||||
SocketAddressStorage(net_address_module_info *module)
|
||||
: SocketAddress(module, &fAddressStorage)
|
||||
{}
|
||||
SocketAddressStorage(net_address_module_info* module)
|
||||
:
|
||||
SocketAddress(module, &fAddressStorage)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
sockaddr_storage fAddressStorage;
|
||||
};
|
||||
|
||||
|
||||
#endif // NET_ADDRESS_UTILITIES_H
|
||||
|
Loading…
Reference in New Issue
Block a user