00001 #include <Utility.h>
00002 #include "UdpTestSocket.h"
00003
00004
00005 UdpTestSocket::UdpTestSocket(ISocketHandler& h)
00006 :UdpSocket(h)
00007 {
00008 }
00009
00010
00011 void UdpTestSocket::OnRawData(const char *p,size_t l,struct sockaddr *sa_from,socklen_t sa_len)
00012 {
00013 if (sa_len == sizeof(struct sockaddr_in))
00014 {
00015 struct sockaddr_in sa;
00016 memcpy(&sa,sa_from,sa_len);
00017 ipaddr_t a;
00018 memcpy(&a,&sa.sin_addr,4);
00019 std::string ip;
00020 Utility::l2ip(a,ip);
00021 printf("Received %d bytes from: %s:%d\n", l,ip.c_str(),ntohs(sa.sin_port));
00022 printf("%s\n",static_cast<std::string>(p).substr(0,l).c_str());
00023 }
00024 #ifdef ENABLE_IPV6
00025 #ifdef IPPROTO_IPV6
00026 else
00027 if (sa_len == sizeof(struct sockaddr_in6))
00028 {
00029 struct sockaddr_in6 sa;
00030 memcpy(&sa,sa_from,sa_len);
00031 std::string ip;
00032 Utility::l2ip(sa.sin6_addr,ip);
00033 printf("(IPv6) Received %d bytes from: %s:%d\n", l,ip.c_str(),ntohs(sa.sin6_port));
00034 printf("%s\n",static_cast<std::string>(p).substr(0,l).c_str());
00035 }
00036 #endif
00037 #endif
00038 }