apps/examples/udp: Enable testing with the broadcast address.
This commit is contained in:
parent
ea95f710db
commit
444922ea93
@ -101,6 +101,13 @@ config EXAMPLES_UDP_IPv6
|
||||
|
||||
endchoice # IP Domain
|
||||
|
||||
config EXAMPLES_UDP_BROADCAST
|
||||
bool "Broadcast outgoing messages"
|
||||
default n
|
||||
depends on NET_BROADCAST
|
||||
---help---
|
||||
Send and receive all UDP packets using the broadcast address.
|
||||
|
||||
if EXAMPLES_UDP_IPv4
|
||||
|
||||
comment "IPv4 addresses"
|
||||
|
@ -142,6 +142,10 @@ void udp_client(void)
|
||||
int sockfd;
|
||||
int nbytes;
|
||||
int offset;
|
||||
#ifdef CONFIG_EXAMPLES_UDP_BROADCAST
|
||||
int optval;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* Create a new UDP socket */
|
||||
|
||||
@ -152,6 +156,16 @@ void udp_client(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDP_BROADCAST
|
||||
optval = 1;
|
||||
ret = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(int));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set SO_BROADCAST\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then send and receive 256 messages */
|
||||
|
||||
for (offset = 0; offset < 256; offset++)
|
||||
|
@ -101,6 +101,9 @@ void udp_server(void)
|
||||
int nbytes;
|
||||
int optval;
|
||||
int offset;
|
||||
#ifdef CONFIG_EXAMPLES_UDP_BROADCAST
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* Create a new UDP socket */
|
||||
|
||||
@ -120,6 +123,16 @@ void udp_server(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDP_BROADCAST
|
||||
optval = 1;
|
||||
ret = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(int));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set SO_BROADCAST\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Bind the socket to a local address */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||
|
Loading…
Reference in New Issue
Block a user