Skip to content

Commit

Permalink
Add ip address checker (#796)
Browse files Browse the repository at this point in the history
Add test and logging for invalid IP address
  • Loading branch information
MinyazevR authored Oct 21, 2024
1 parent 29e01ae commit 8639e29
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion trikNetwork/src/mailboxServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void MailboxServer::setHullNumber(int hullNumber)

void MailboxServer::connectTo(const QString &ip, int port)
{
QHostAddress address;
if (!address.setAddress(ip)) {
QLOG_INFO() << "Connect to ip " << ip << "and port" << port << "with not valid ip";
return;
; }
mAuxiliaryInformationLock.lockForRead();
auto server = mServerIp;
auto serverPort = mServerPort;
Expand All @@ -111,7 +116,12 @@ void MailboxServer::connectTo(const QString &ip, int port)
if (server.toString() != ip || serverPort != port) {
{
QWriteLocker l(&mAuxiliaryInformationLock);
mServerIp = QHostInfo::fromName(ip).addresses().first();
auto addresses = QHostInfo::fromName(ip).addresses();
if (addresses.isEmpty()) {
QLOG_INFO() << "Not found addresses for ip " << ip;
return;
}
mServerIp = addresses.first();
mServerPort = port;
}
saveSettings();
Expand Down

0 comments on commit 8639e29

Please sign in to comment.