Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
b689d5b7
Commit
b689d5b7
authored
May 06, 2015
by
dogmaphobic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skipping DNS lookup if not needed.
parent
3520241e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
24 deletions
+39
-24
UDPLink.cc
src/comm/UDPLink.cc
+39
-24
No files found.
src/comm/UDPLink.cc
View file @
b689d5b7
...
...
@@ -39,6 +39,36 @@ This file is part of the QGROUNDCONTROL project
#include "QGC.h"
#include <QHostInfo>
static
bool
is_ip
(
const
QString
&
address
)
{
int
a
,
b
,
c
,
d
;
if
(
sscanf
(
address
.
toStdString
().
c_str
(),
"%d.%d.%d.%d"
,
&
a
,
&
b
,
&
c
,
&
d
)
!=
4
)
return
false
;
return
true
;
}
static
QString
get_ip_address
(
const
QString
&
address
)
{
if
(
is_ip
(
address
))
return
address
;
// Need to look it up
QHostInfo
info
=
QHostInfo
::
fromName
(
address
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
QList
<
QHostAddress
>
hostAddresses
=
info
.
addresses
();
QHostAddress
address
;
for
(
int
i
=
0
;
i
<
hostAddresses
.
size
();
i
++
)
{
// Exclude all IPv6 addresses
if
(
!
hostAddresses
.
at
(
i
).
toString
().
contains
(
":"
))
{
return
hostAddresses
.
at
(
i
).
toString
();
}
}
}
return
QString
(
""
);
}
UDPLink
::
UDPLink
(
UDPConfiguration
*
config
)
:
_socket
(
NULL
)
,
_connectState
(
false
)
...
...
@@ -294,28 +324,12 @@ void UDPConfiguration::copyFrom(LinkConfiguration *source)
*/
void
UDPConfiguration
::
addHost
(
const
QString
&
host
)
{
// Handle x.x.x.x:p
if
(
host
.
contains
(
":"
))
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
.
split
(
":"
).
first
());
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
// Add host
QList
<
QHostAddress
>
hostAddresses
=
info
.
addresses
();
QHostAddress
address
;
for
(
int
i
=
0
;
i
<
hostAddresses
.
size
();
i
++
)
{
// Exclude all IPv6 addresses
if
(
!
hostAddresses
.
at
(
i
).
toString
().
contains
(
":"
))
{
address
=
hostAddresses
.
at
(
i
);
}
}
_confMutex
.
lock
();
_hosts
[
address
.
toString
()]
=
host
.
split
(
":"
).
last
().
toInt
();
_confMutex
.
unlock
();
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
address
.
toString
()
<<
":"
<<
host
.
split
(
":"
).
last
();
}
addHost
(
host
.
split
(
":"
).
first
(),
host
.
split
(
":"
).
last
().
toInt
());
}
// If no port, use default
else
{
addHost
(
host
,
(
int
)
_localPort
);
...
...
@@ -330,11 +344,12 @@ void UDPConfiguration::addHost(const QString& host, int port)
_hosts
[
host
]
=
port
;
}
}
else
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
_hosts
[
info
.
addresses
().
first
().
toString
()]
=
port
;
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
info
.
addresses
().
first
().
toString
()
<<
":"
<<
port
;
QString
ipAdd
=
get_ip_address
(
host
);
if
(
ipAdd
.
isEmpty
())
{
qWarning
()
<<
"UDP:"
<<
"Could not resolve"
<<
host
;
}
else
{
_hosts
[
ipAdd
]
=
port
;
qDebug
()
<<
"UDP:"
<<
"Adding Host:"
<<
ipAdd
<<
":"
<<
port
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment