Brief Introduction to so_broadcast options of sockets

Source: Internet
Author: User

When the setsockopt () function is used to set the socket options, an option in the so_broadcast line is displayed,


Its level is sol_socket, which allows the process to send broadcast messages

Note that the broadcast is only supported on the "network that supports broadcast message" (such as Ethernet, Token Ring) datainsocket.

Why do programs need to set this option before sending broadcast messages?

This is to prevent some programs from being designed to send broadcast messages because of incorrect input.

For example, a UDP program accepts a destination IP address as a command line parameter, but the user writes this address as a broadcast address.

At this time, the role of this option is shown. Instead, let the UDP program verify whether the user entered a broadcast address.

It is better to let the kernel detect it. If it is a broadcast address, but the so_broadcast option is not set,

An eacces error is returned.

The ip_output.c file in the 4.4bsd-lite version code is as follows:

If (in_broadcast (DST-> sin_addr, IFP )){
...
...
If (flags & ip_allowbroadcast) = 0)
Error = eaccess;
Goto bad;
}
...
...
}

Bad:
M_freem (M0 );
Goto done;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.