* @brief Set UDP local port */
| 161 | * @brief Set UDP local port |
| 162 | */ |
| 163 | API::CommandResponse API::Handlers::NetworkHandler::setUdpLocalPort(const QString& id, |
| 164 | const QJsonObject& params) |
| 165 | { |
| 166 | if (!params.contains(QStringLiteral("port"))) { |
| 167 | return CommandResponse::makeError( |
| 168 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: port")); |
| 169 | } |
| 170 | |
| 171 | const int port = params.value(QStringLiteral("port")).toInt(); |
| 172 | if (port < 0 || port > 65535) { |
| 173 | return CommandResponse::makeError( |
| 174 | id, ErrorCode::InvalidParam, QStringLiteral("Port must be between 0 and 65535")); |
| 175 | } |
| 176 | |
| 177 | IO::ConnectionManager::instance().network()->setUdpLocalPort(static_cast<quint16>(port)); |
| 178 | |
| 179 | QJsonObject result; |
| 180 | result[QStringLiteral("udpLocalPort")] = port; |
| 181 | return CommandResponse::makeSuccess(id, result); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @brief Set UDP remote port |