Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
56585082
Commit
56585082
authored
9 years ago
by
Julian Oes
Committed by
Lorenz Meier
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
mavlink: look up broadcast address, don't guess it
parent
a7e9bc8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/mavlink/mavlink_main.cpp
+15
-19
15 additions, 19 deletions
src/modules/mavlink/mavlink_main.cpp
with
15 additions
and
19 deletions
src/modules/mavlink/mavlink_main.cpp
+
15
−
19
View file @
56585082
...
...
@@ -1016,6 +1016,16 @@ Mavlink::init_udp()
continue
;
}
struct
ifreq
bc_ifreq
;
memset
(
&
bc_ifreq
,
0
,
sizeof
(
bc_ifreq
));
strncpy
(
bc_ifreq
.
ifr_name
,
ifreqs
[
i
].
ifr_name
,
IF_NAMESIZE
);
ret
=
ioctl
(
_socket_fd
,
SIOCGIFBRDADDR
,
&
bc_ifreq
);
if
(
ret
!=
0
)
{
PX4_WARN
(
"getting broadcast address failed"
);
return
;
}
struct
in_addr
&
sin_addr
=
((
struct
sockaddr_in
*
)
&
ifreqs
[
i
].
ifr_addr
)
->
sin_addr
;
// Accept network interfaces to local network only. This means it's an IP starting with:
...
...
@@ -1023,33 +1033,19 @@ Mavlink::init_udp()
// Also see https://tools.ietf.org/html/rfc1918#section-3
uint8_t
first_byte
=
sin_addr
.
s_addr
&
0xFF
;
int32_t
subnet_mask
=
0x0
;
if
(
first_byte
==
192
)
{
// /24
subnet_mask
=
0xFFFFFF
;
}
else
if
(
first_byte
!=
172
)
{
// /16
subnet_mask
=
0xFFFF
;
}
else
if
(
first_byte
!=
10
)
{
// /8
subnet_mask
=
0xFF
;
}
else
{
// Ignore anything else.
if
(
first_byte
!=
192
&&
first_byte
!=
172
&&
first_byte
!=
10
)
{
continue
;
}
if
(
!
network_interface_found
)
{
PX4_INFO
(
"using network interface %s, IP: %s"
,
ifreqs
[
i
].
ifr_name
,
inet_ntoa
(
sin_addr
));
_bcast_addr
.
sin_family
=
AF_INET
;
struct
in_addr
&
bc_addr
=
((
struct
sockaddr_in
*
)
&
bc_ifreq
.
ifr_broadaddr
)
->
sin_addr
;
PX4_INFO
(
"with broadcast IP: %s"
,
inet_ntoa
(
bc_addr
));
// Assemble the broadcast address. This should be done using the default gateway IP
// instead of the IP. However, for most cases, this should work.
_bcast_addr
.
sin_addr
.
s_addr
=
(
~
subnet_mask
)
|
sin_addr
.
s_addr
;
PX4_INFO
(
"broadcast address should be: %s"
,
inet_ntoa
(
_bcast_addr
.
sin_addr
));
_bcast_addr
.
sin_family
=
AF_INET
;
_bcast_addr
.
sin_addr
=
bc_addr
;
network_interface_found
=
true
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment