| 1056 | } |
| 1057 | |
| 1058 | Net::Error Net::sendto(const NetAddress *address, const U8 *buffer, S32 bufferSize) |
| 1059 | { |
| 1060 | if(Journal::IsPlaying()) |
| 1061 | return NoError; |
| 1062 | |
| 1063 | SOCKET socketFd; |
| 1064 | |
| 1065 | if(address->type == NetAddress::IPAddress || address->type == NetAddress::IPBroadcastAddress) |
| 1066 | { |
| 1067 | socketFd = PlatformNetState::smReservedSocketList.resolve(PlatformNetState::udpSocket); |
| 1068 | if (socketFd != InvalidSocketHandle) |
| 1069 | { |
| 1070 | sockaddr_in ipAddr; |
| 1071 | NetAddressToIPSocket(address, &ipAddr); |
| 1072 | |
| 1073 | if (::sendto(socketFd, (const char*)buffer, bufferSize, 0, |
| 1074 | (sockaddr *)&ipAddr, sizeof(sockaddr_in)) == SOCKET_ERROR) |
| 1075 | return PlatformNetState::getLastError(); |
| 1076 | else |
| 1077 | return NoError; |
| 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | return NotASocket; |
| 1082 | } |
| 1083 | } |
| 1084 | else if (address->type == NetAddress::IPV6Address || address->type == NetAddress::IPV6MulticastAddress) |
| 1085 | { |
| 1086 | socketFd = PlatformNetState::smReservedSocketList.resolve(address->type == NetAddress::IPV6MulticastAddress ? PlatformNetState::multicast6Socket : PlatformNetState::udp6Socket); |
| 1087 | |
| 1088 | if (socketFd != InvalidSocketHandle) |
| 1089 | { |
| 1090 | sockaddr_in6 ipAddr; |
| 1091 | NetAddressToIPSocket6(address, &ipAddr); |
| 1092 | if (::sendto(socketFd, (const char*)buffer, bufferSize, 0, |
| 1093 | (struct sockaddr *) &ipAddr, sizeof(sockaddr_in6)) == SOCKET_ERROR) |
| 1094 | return PlatformNetState::getLastError(); |
| 1095 | else |
| 1096 | return NoError; |
| 1097 | } |
| 1098 | else |
| 1099 | { |
| 1100 | return NotASocket; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | return WrongProtocolType; |
| 1105 | } |
| 1106 | |
| 1107 | void Net::process() |
| 1108 | { |
nothing calls this directly
no test coverage detected