Added methods used to fill a binary IP address buffer from stringified address.
git-svn-id: http://voip.null.ro/svn/yate@5657 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
bb49512cd1
commit
135f3c1a6c
|
@ -477,6 +477,24 @@ bool SocketAddr::stringify(String& s, struct sockaddr* addr)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Copy a host address to a buffer
|
||||
int SocketAddr::copyAddr(uint8_t* buf, struct sockaddr* addr)
|
||||
{
|
||||
if (!(buf && addr))
|
||||
return Unknown;
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
::memcpy(buf,&((struct sockaddr_in*)addr)->sin_addr,4);
|
||||
return IPv4;
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
::memcpy(buf,&((struct sockaddr_in6*)addr)->sin6_addr,16);
|
||||
return IPv6;
|
||||
#endif
|
||||
}
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
// Append an address to a buffer
|
||||
String& SocketAddr::appendAddr(String& buf, const String& addr, int family)
|
||||
{
|
||||
|
|
23
yateclass.h
23
yateclass.h
|
@ -5677,6 +5677,29 @@ public:
|
|||
*/
|
||||
static bool stringify(String& buf, struct sockaddr* addr);
|
||||
|
||||
/**
|
||||
* Put a host address to a buffer
|
||||
* @param buf Destination buffer. It must be large enough to keep the address
|
||||
* (4 bytes for IPv4, 16 bytes for IPv6)
|
||||
* @param host The host address
|
||||
* @param family Address family, set it to Unknown to detect
|
||||
* @return Address family, Unknown on failure
|
||||
*/
|
||||
static inline int unStringify(uint8_t* buf, const String& host,
|
||||
int family = Unknown) {
|
||||
SocketAddr sa(family);
|
||||
return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a host address to a buffer
|
||||
* @param buf Destination buffer. It must be large enough to keep the address
|
||||
* (4 bytes for IPv4, 16 bytes for IPv6)
|
||||
* @param addr The host address
|
||||
* @return Address family, Unknown on failure
|
||||
*/
|
||||
static int copyAddr(uint8_t* buf, struct sockaddr* addr);
|
||||
|
||||
/**
|
||||
* Retrieve the scope id value of an IPv6 address
|
||||
* @param addr The address
|
||||
|
|
Loading…
Reference in New Issue