added port window and port range options
[anytun.git] / Sockets / UdpSocket.cpp
blob75bebf2b9101d99c389ff70c32e9e994ed466f6f
1 /** \file UdpSocket.cpp
2 ** \date 2004-02-13
3 ** \author grymse@alhem.net
4 **/
5 /*
6 Copyright (C) 2004-2007 Anders Hedstrom
8 This library is made available under the terms of the GNU GPL.
10 If you would like to use this library in a closed-source application,
11 a separate license agreement is available. For information about
12 the closed-source license agreement for the C++ sockets library,
13 please visit http://www.alhem.net/Sockets/license.html and/or
14 email license@alhem.net.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef _WIN32
31 #ifdef _MSC_VER
32 #pragma warning(disable:4786)
33 #endif
34 #include <stdlib.h>
35 #else
36 #include <errno.h>
37 #endif
39 #include "ISocketHandler.h"
40 #include "UdpSocket.h"
41 #include "Utility.h"
42 #include "Ipv4Address.h"
43 #include "Ipv6Address.h"
44 #ifdef ENABLE_EXCEPTIONS
45 #include "Exception.h"
46 #endif
47 // include this to see strange sights
48 //#include <linux/in6.h>
51 #ifdef SOCKETS_NAMESPACE
52 namespace SOCKETS_NAMESPACE {
53 #endif
56 UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : Socket(h)
57 , m_ibuf(new char[ibufsz])
58 , m_ibufsz(ibufsz)
59 , m_bind_ok(false)
60 , m_port(0)
61 , m_last_size_written(-1)
62 , m_retries(retries)
63 , m_b_read_ts(false)
65 #ifdef ENABLE_IPV6
66 #ifdef IPPROTO_IPV6
67 SetIpv6(ipv6);
68 #endif
69 #endif
73 UdpSocket::~UdpSocket()
75 Close();
76 delete[] m_ibuf;
80 int UdpSocket::Bind(port_t &port, int range)
82 #ifdef ENABLE_IPV6
83 #ifdef IPPROTO_IPV6
84 if (IsIpv6())
86 Ipv6Address ad(port);
87 return Bind(ad, range);
89 #endif
90 #endif
91 Ipv4Address ad(port);
92 return Bind(ad, range);
96 int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
98 #ifdef ENABLE_IPV6
99 #ifdef IPPROTO_IPV6
100 if (IsIpv6())
102 Ipv6Address ad(intf, port);
103 if (ad.IsValid())
105 return Bind(ad, range);
107 SetCloseAndDelete();
108 return -1;
110 #endif
111 #endif
112 Ipv4Address ad(intf, port);
113 if (ad.IsValid())
115 return Bind(ad, range);
117 SetCloseAndDelete();
118 return -1;
122 int UdpSocket::Bind(ipaddr_t a, port_t &port, int range)
124 Ipv4Address ad(a, port);
125 return Bind(ad, range);
129 #ifdef ENABLE_IPV6
130 #ifdef IPPROTO_IPV6
131 int UdpSocket::Bind(in6_addr a, port_t &port, int range)
133 Ipv6Address ad(a, port);
134 return Bind(ad, range);
136 #endif
137 #endif
140 int UdpSocket::Bind(SocketAddress& ad, int range)
142 if (GetSocket() == INVALID_SOCKET)
144 Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
146 if (GetSocket() != INVALID_SOCKET)
148 SetNonblocking(true);
149 int n = bind(GetSocket(), ad, ad);
150 int tries = range;
151 while (n == -1 && tries--)
153 ad.SetPort(ad.GetPort() + 1);
154 n = bind(GetSocket(), ad, ad);
156 if (n == -1)
158 Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
159 SetCloseAndDelete();
160 #ifdef ENABLE_EXCEPTIONS
161 throw Exception("bind() failed for UdpSocket, port:range: " + Utility::l2string(ad.GetPort()) + ":" + Utility::l2string(range));
162 #endif
163 return -1;
165 m_bind_ok = true;
166 m_port = ad.GetPort();
167 return 0;
169 return -1;
173 /** if you wish to use Send, first Open a connection */
174 bool UdpSocket::Open(ipaddr_t l, port_t port)
176 Ipv4Address ad(l, port);
177 return Open(ad);
181 bool UdpSocket::Open(const std::string& host, port_t port)
183 #ifdef ENABLE_IPV6
184 #ifdef IPPROTO_IPV6
185 if (IsIpv6())
187 Ipv6Address ad(host, port);
188 if (ad.IsValid())
190 return Open(ad);
192 return false;
194 #endif
195 #endif
196 Ipv4Address ad(host, port);
197 if (ad.IsValid())
199 return Open(ad);
201 return false;
205 #ifdef ENABLE_IPV6
206 #ifdef IPPROTO_IPV6
207 bool UdpSocket::Open(struct in6_addr& a, port_t port)
209 Ipv6Address ad(a, port);
210 return Open(ad);
212 #endif
213 #endif
216 bool UdpSocket::Open(SocketAddress& ad)
218 if (GetSocket() == INVALID_SOCKET)
220 Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
222 if (GetSocket() != INVALID_SOCKET)
224 SetNonblocking(true);
225 if (connect(GetSocket(), ad, ad) == -1)
227 Handler().LogError(this, "connect", Errno, StrError(Errno), LOG_LEVEL_FATAL);
228 SetCloseAndDelete();
229 return false;
231 SetConnected();
232 return true;
234 return false;
238 void UdpSocket::CreateConnection()
240 #ifdef ENABLE_IPV6
241 #ifdef IPPROTO_IPV6
242 if (IsIpv6())
244 if (GetSocket() == INVALID_SOCKET)
246 SOCKET s = CreateSocket(AF_INET6, SOCK_DGRAM, "udp");
247 if (s == INVALID_SOCKET)
249 return;
251 SetNonblocking(true, s);
252 Attach(s);
254 return;
256 #endif
257 #endif
258 if (GetSocket() == INVALID_SOCKET)
260 SOCKET s = CreateSocket(AF_INET, SOCK_DGRAM, "udp");
261 if (s == INVALID_SOCKET)
263 return;
265 SetNonblocking(true, s);
266 Attach(s);
271 /** send to specified address */
272 void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int len, int flags)
274 #ifdef ENABLE_IPV6
275 #ifdef IPPROTO_IPV6
276 if (IsIpv6())
278 Ipv6Address ad(h, p);
279 if (ad.IsValid())
281 SendToBuf(ad, data, len, flags);
283 return;
285 #endif
286 #endif
287 Ipv4Address ad(h, p);
288 if (ad.IsValid())
290 SendToBuf(ad, data, len, flags);
295 /** send to specified address */
296 void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int flags)
298 Ipv4Address ad(a, p);
299 SendToBuf(ad, data, len, flags);
303 #ifdef ENABLE_IPV6
304 #ifdef IPPROTO_IPV6
305 void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int flags)
307 Ipv6Address ad(a, p);
308 SendToBuf(ad, data, len, flags);
310 #endif
311 #endif
314 void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flags)
316 if (GetSocket() == INVALID_SOCKET)
318 Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
320 if (GetSocket() != INVALID_SOCKET)
322 SetNonblocking(true);
323 if ((m_last_size_written = sendto(GetSocket(), data, len, flags, ad, ad)) == -1)
325 Handler().LogError(this, "sendto", Errno, StrError(Errno), LOG_LEVEL_ERROR);
331 void UdpSocket::SendTo(const std::string& a, port_t p, const std::string& str, int flags)
333 SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
337 void UdpSocket::SendTo(ipaddr_t a, port_t p, const std::string& str, int flags)
339 SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
343 #ifdef ENABLE_IPV6
344 #ifdef IPPROTO_IPV6
345 void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags)
347 SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
349 #endif
350 #endif
353 void UdpSocket::SendTo(SocketAddress& ad, const std::string& str, int flags)
355 SendToBuf(ad, str.c_str(), (int)str.size(), flags);
359 /** send to connected address */
360 void UdpSocket::SendBuf(const char *data, size_t len, int flags)
362 if (!IsConnected())
364 Handler().LogError(this, "SendBuf", 0, "not connected", LOG_LEVEL_ERROR);
365 return;
367 if ((m_last_size_written = send(GetSocket(), data, (int)len, flags)) == -1)
369 Handler().LogError(this, "send", Errno, StrError(Errno), LOG_LEVEL_ERROR);
374 void UdpSocket::Send(const std::string& str, int flags)
376 SendBuf(str.c_str(), (int)str.size(), flags);
380 #ifndef _WIN32
381 int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts)
383 struct msghdr msg;
384 struct iovec vec[1];
385 union {
386 struct cmsghdr cm;
387 char data[CMSG_SPACE(sizeof(struct timeval))];
388 } cmsg_un;
389 struct cmsghdr *cmsg;
390 struct timeval *tv;
392 vec[0].iov_base = ioBuf;
393 vec[0].iov_len = inBufSize;
395 memset(&msg, 0, sizeof(msg));
396 memset(from, 0, fromlen);
397 memset(ioBuf, 0, inBufSize);
398 memset(&cmsg_un, 0, sizeof(cmsg_un));
400 msg.msg_name = (caddr_t)from;
401 msg.msg_namelen = fromlen;
402 msg.msg_iov = vec;
403 msg.msg_iovlen = 1;
404 msg.msg_control = cmsg_un.data;
405 msg.msg_controllen = sizeof(cmsg_un.data);
406 msg.msg_flags = 0;
408 // Original version - for reference only
409 //int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
411 int n = recvmsg(GetSocket(), &msg, MSG_DONTWAIT);
413 // now ioBuf will contain the data, as if we used recvfrom
415 // Now get the time
416 if(n != -1 && msg.msg_controllen >= sizeof(struct cmsghdr) && !(msg.msg_flags & MSG_CTRUNC))
418 tv = 0;
419 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg))
421 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP)
423 tv = (struct timeval *)CMSG_DATA(cmsg);
426 if (tv)
428 memcpy(ts, tv, sizeof(struct timeval));
431 // The address is in network order, but that's OK right now
432 return n;
434 #endif
437 void UdpSocket::OnRead()
439 #ifdef ENABLE_IPV6
440 #ifdef IPPROTO_IPV6
441 if (IsIpv6())
443 struct sockaddr_in6 sa;
444 socklen_t sa_len = sizeof(sa);
445 if (m_b_read_ts)
447 struct timeval ts;
448 Utility::GetTime(&ts);
449 #ifdef _WIN32
450 int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
451 #else
452 int n = ReadTS(m_ibuf, m_ibufsz, (struct sockaddr *)&sa, sa_len, &ts);
453 #endif
454 if (n > 0)
456 this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len, &ts);
458 else
459 if (n == -1)
461 #ifdef _WIN32
462 if (Errno != WSAEWOULDBLOCK)
463 #else
464 if (Errno != EWOULDBLOCK)
465 #endif
466 Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR);
468 return;
470 int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
471 int q = m_retries; // receive max 10 at one cycle
472 while (n > 0)
474 if (sa_len != sizeof(sa))
476 Handler().LogError(this, "recvfrom", 0, "unexpected address struct size", LOG_LEVEL_WARNING);
478 this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len);
479 if (!q--)
480 break;
482 n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
484 if (n == -1)
486 #ifdef _WIN32
487 if (Errno != WSAEWOULDBLOCK)
488 #else
489 if (Errno != EWOULDBLOCK)
490 #endif
491 Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR);
493 return;
495 #endif
496 #endif
497 struct sockaddr_in sa;
498 socklen_t sa_len = sizeof(sa);
499 if (m_b_read_ts)
501 struct timeval ts;
502 Utility::GetTime(&ts);
503 #ifdef _WIN32
504 int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
505 #else
506 int n = ReadTS(m_ibuf, m_ibufsz, (struct sockaddr *)&sa, sa_len, &ts);
507 #endif
508 if (n > 0)
510 this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len, &ts);
512 else
513 if (n == -1)
515 #ifdef _WIN32
516 if (Errno != WSAEWOULDBLOCK)
517 #else
518 if (Errno != EWOULDBLOCK)
519 #endif
520 Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR);
522 return;
524 int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
525 int q = m_retries;
526 while (n > 0)
528 if (sa_len != sizeof(sa))
530 Handler().LogError(this, "recvfrom", 0, "unexpected address struct size", LOG_LEVEL_WARNING);
532 this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len);
533 if (!q--)
534 break;
536 n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
538 if (n == -1)
540 #ifdef _WIN32
541 if (Errno != WSAEWOULDBLOCK)
542 #else
543 if (Errno != EWOULDBLOCK)
544 #endif
545 Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR);
550 void UdpSocket::SetBroadcast(bool b)
552 int one = 1;
553 int zero = 0;
555 if (GetSocket() == INVALID_SOCKET)
557 CreateConnection();
559 if (b)
561 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof(one)) == -1)
563 Handler().LogError(this, "SetBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING);
566 else
568 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *) &zero, sizeof(zero)) == -1)
570 Handler().LogError(this, "SetBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING);
576 bool UdpSocket::IsBroadcast()
578 int is_broadcast = 0;
579 socklen_t size;
581 if (GetSocket() == INVALID_SOCKET)
583 CreateConnection();
585 if (getsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&is_broadcast, &size) == -1)
587 Handler().LogError(this, "IsBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING);
589 return is_broadcast != 0;
593 void UdpSocket::SetMulticastTTL(int ttl)
595 if (GetSocket() == INVALID_SOCKET)
597 CreateConnection();
599 if (setsockopt(GetSocket(), SOL_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(int)) == -1)
601 Handler().LogError(this, "SetMulticastTTL", Errno, StrError(Errno), LOG_LEVEL_WARNING);
606 int UdpSocket::GetMulticastTTL()
608 int ttl = 0;
609 socklen_t size = sizeof(int);
611 if (GetSocket() == INVALID_SOCKET)
613 CreateConnection();
615 if (getsockopt(GetSocket(), SOL_IP, IP_MULTICAST_TTL, (char *)&ttl, &size) == -1)
617 Handler().LogError(this, "GetMulticastTTL", Errno, StrError(Errno), LOG_LEVEL_WARNING);
619 return ttl;
623 void UdpSocket::SetMulticastLoop(bool x)
625 if (GetSocket() == INVALID_SOCKET)
627 CreateConnection();
629 #ifdef ENABLE_IPV6
630 #ifdef IPPROTO_IPV6
631 if (IsIpv6())
633 int val = x ? 1 : 0;
634 if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&val, sizeof(int)) == -1)
636 Handler().LogError(this, "SetMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING);
638 return;
640 #endif
641 #endif
642 int val = x ? 1 : 0;
643 if (setsockopt(GetSocket(), SOL_IP, IP_MULTICAST_LOOP, (char *)&val, sizeof(int)) == -1)
645 Handler().LogError(this, "SetMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING);
650 bool UdpSocket::IsMulticastLoop()
652 if (GetSocket() == INVALID_SOCKET)
654 CreateConnection();
656 #ifdef ENABLE_IPV6
657 #ifdef IPPROTO_IPV6
658 if (IsIpv6())
660 int is_loop = 0;
661 socklen_t size = sizeof(int);
662 if (getsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&is_loop, &size) == -1)
664 Handler().LogError(this, "IsMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING);
666 return is_loop ? true : false;
668 #endif
669 #endif
670 int is_loop = 0;
671 socklen_t size = sizeof(int);
672 if (getsockopt(GetSocket(), SOL_IP, IP_MULTICAST_LOOP, (char *)&is_loop, &size) == -1)
674 Handler().LogError(this, "IsMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING);
676 return is_loop ? true : false;
680 void UdpSocket::AddMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
682 if (GetSocket() == INVALID_SOCKET)
684 CreateConnection();
686 #ifdef ENABLE_IPV6
687 #ifdef IPPROTO_IPV6
688 if (IsIpv6())
690 struct ipv6_mreq x;
691 struct in6_addr addr;
692 if (Utility::u2ip( group, addr ))
694 x.ipv6mr_multiaddr = addr;
695 x.ipv6mr_interface = if_index;
696 if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&x, sizeof(struct ipv6_mreq)) == -1)
698 Handler().LogError(this, "AddMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING);
701 return;
703 #endif
704 #endif
705 struct ip_mreq x; // ip_mreqn
706 ipaddr_t addr;
707 if (Utility::u2ip( group, addr ))
709 memcpy(&x.imr_multiaddr.s_addr, &addr, sizeof(addr));
710 Utility::u2ip( local_if, addr);
711 memcpy(&x.imr_interface.s_addr, &addr, sizeof(addr));
712 // x.imr_ifindex = if_index;
713 if (setsockopt(GetSocket(), SOL_IP, IP_ADD_MEMBERSHIP, (char *)&x, sizeof(struct ip_mreq)) == -1)
715 Handler().LogError(this, "AddMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING);
721 void UdpSocket::DropMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
723 if (GetSocket() == INVALID_SOCKET)
725 CreateConnection();
727 #ifdef ENABLE_IPV6
728 #ifdef IPPROTO_IPV6
729 if (IsIpv6())
731 struct ipv6_mreq x;
732 struct in6_addr addr;
733 if (Utility::u2ip( group, addr ))
735 x.ipv6mr_multiaddr = addr;
736 x.ipv6mr_interface = if_index;
737 if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ipv6_mreq)) == -1)
739 Handler().LogError(this, "DropMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING);
742 return;
744 #endif
745 #endif
746 struct ip_mreq x; // ip_mreqn
747 ipaddr_t addr;
748 if (Utility::u2ip( group, addr ))
750 memcpy(&x.imr_multiaddr.s_addr, &addr, sizeof(addr));
751 Utility::u2ip( local_if, addr);
752 memcpy(&x.imr_interface.s_addr, &addr, sizeof(addr));
753 // x.imr_ifindex = if_index;
754 if (setsockopt(GetSocket(), SOL_IP, IP_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ip_mreq)) == -1)
756 Handler().LogError(this, "DropMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING);
762 #ifdef ENABLE_IPV6
763 #ifdef IPPROTO_IPV6
764 void UdpSocket::SetMulticastHops(int hops)
766 if (GetSocket() == INVALID_SOCKET)
768 CreateConnection();
770 if (!IsIpv6())
772 Handler().LogError(this, "SetMulticastHops", 0, "Ipv6 only", LOG_LEVEL_ERROR);
773 return;
775 if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops, sizeof(int)) == -1)
777 Handler().LogError(this, "SetMulticastHops", Errno, StrError(Errno), LOG_LEVEL_WARNING);
782 int UdpSocket::GetMulticastHops()
784 if (GetSocket() == INVALID_SOCKET)
786 CreateConnection();
788 if (!IsIpv6())
790 Handler().LogError(this, "SetMulticastHops", 0, "Ipv6 only", LOG_LEVEL_ERROR);
791 return -1;
793 int hops = 0;
794 socklen_t size = sizeof(int);
795 if (getsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops, &size) == -1)
797 Handler().LogError(this, "GetMulticastHops", Errno, StrError(Errno), LOG_LEVEL_WARNING);
799 return hops;
801 #endif // IPPROTO_IPV6
802 #endif
805 bool UdpSocket::IsBound()
807 return m_bind_ok;
811 void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len)
816 void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len, struct timeval *ts)
821 port_t UdpSocket::GetPort()
823 return m_port;
827 int UdpSocket::GetLastSizeWritten()
829 return m_last_size_written;
833 void UdpSocket::SetTimestamp(bool x)
835 m_b_read_ts = x;
839 #ifdef SOCKETS_NAMESPACE
841 #endif