| 177 | } |
| 178 | |
| 179 | long GetRemoteAddress(const std::string &remote, AmsNetId &netId) |
| 180 | { |
| 181 | Frame f{ 128 }; |
| 182 | |
| 183 | const uint32_t tagCount = 0; |
| 184 | f.prepend(htole(tagCount)); |
| 185 | |
| 186 | const auto myAddr = AmsAddr{ {}, 0 }; |
| 187 | f.prepend(&myAddr, sizeof(myAddr)); |
| 188 | |
| 189 | const auto status = SendRecv(remote, f, UdpServiceId::SERVERINFO); |
| 190 | if (status) { |
| 191 | return status; |
| 192 | } |
| 193 | |
| 194 | // We expect at least the AmsAddr |
| 195 | if (sizeof(netId) > f.capacity()) { |
| 196 | LOG_ERROR(__FUNCTION__ |
| 197 | << "(): frame too short to be AMS response '0x" |
| 198 | << std::hex << f.capacity() << "'\n"); |
| 199 | return ADSERR_DEVICE_INVALIDSIZE; |
| 200 | } |
| 201 | memcpy(&netId, f.data(), sizeof(netId)); |
| 202 | return 0; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |