Permalink
Browse files

Add cast operator from IPAddress to sockaddr.

  • Loading branch information...
1 parent 85fdb25 commit 41087814b3365e838a7d2be1559d08345af1c293 @pprindeville committed Dec 21, 2012
Showing with 15 additions and 0 deletions.
  1. +3 −0 Net/include/Poco/Net/IPAddress.h
  2. +12 −0 Net/src/IPAddress.cpp
@@ -324,6 +324,9 @@ class Net_API IPAddress
IPAddress operator ^ (const IPAddress& addr) const;
IPAddress operator ~ () const;
+ const sockaddr operator () () const;
+ /// cast to sockaddr
+
poco_socklen_t length() const;
/// Returns the length in bytes of the internal socket address structure.
View
@@ -1167,6 +1167,18 @@ IPAddress IPAddress::operator ~ () const
}
+const sockaddr IPAddress::operator () () const
+{
+ sockaddr sock;
+
+ sock.sa_family = af();
+ poco_set_sa_len(&sock, (sock.sa_family == AF_INET) ? sizeof(sockaddr_in) : sizeof(sockaddr_in6));
+ memcpy(&sock.sa_data, addr(), length());
+
+ return sock;
+}
+
+
poco_socklen_t IPAddress::length() const
{
return _pImpl->length();

0 comments on commit 4108781

Please sign in to comment.