Merge branch 'ieee802154'

This commit is contained in:
Gregory Nutt 2017-06-20 15:11:54 -06:00
commit 31352e570c
5 changed files with 76 additions and 8 deletions

View File

@ -511,4 +511,13 @@ config EXAMPLES_UDP_SERVERIPv6ADDR_8
This is the last of the 8-values.
endif # EXAMPLES_UDP_IPv6
config EXAMPLES_SERVER_PORTNO
int "Server port number"
default 5471
config EXAMPLES_CLIENT_PORTNO
int "Client port number"
default 5472
endif # EXAMPLES_UDP

View File

@ -83,7 +83,13 @@
# define PF_INETX PF_INET
#endif
#define PORTNO 5471
#ifndef CONFIG_EXAMPLES_SERVER_PORTNO
# define CONFIG_EXAMPLES_SERVER_PORTNO 5471
#endif
#ifndef CONFIG_EXAMPLES_CLIENT_PORTNO
# define CONFIG_EXAMPLES_CLIENT_PORTNO 5472
#endif
#define ASCIISIZE (0x7f - 0x20)
#define SENDSIZE (ASCIISIZE+1)

View File

@ -57,6 +57,59 @@
* Private Functions
****************************************************************************/
static int create_socket(void)
{
socklen_t addrlen;
int sockfd;
#ifdef CONFIG_EXAMPLES_UDP_IPv4
struct sockaddr_in addr;
/* Create a new IPv4 UDP socket */
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
printf("client ERROR: client socket failure %d\n", errno);
return -1;
}
/* Bind the UDP socket to a IPv4 port */
addr.sin_family = AF_INET;
addr.sin_port = HTONS(CONFIG_EXAMPLES_CLIENT_PORTNO);
addr.sin_addr.s_addr = HTONL(INADDR_ANY);
addrlen = sizeof(struct sockaddr_in);
#else
struct sockaddr_in6 addr;
/* Create a new IPv6 UDP socket */
sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
if (sockfd < 0)
{
printf("client ERROR: client socket failure %d\n", errno);
return -1;
}
/* Bind the UDP socket to a IPv6 port */
addr.sin6_family = AF_INET6;
addr.sin6_port = HTONS(CONFIG_EXAMPLES_CLIENT_PORTNO);
memset(addr.sin6_addr.s6_addr, 0, sizeof(struct in6_addr));
addrlen = sizeof(struct sockaddr_in6);
#endif
if (bind(sockfd, (FAR struct sockaddr *)&addr, addrlen) < 0)
{
printf("client ERROR: Bind failure: %d\n", errno);
return -1;
}
return sockfd;
}
static inline void fill_buffer(unsigned char *buf, int offset)
{
int ch;
@ -92,10 +145,10 @@ void send_client(void)
/* Create a new UDP socket */
sockfd = socket(PF_INETX, SOCK_DGRAM, 0);
sockfd = create_socket();
if (sockfd < 0)
{
printf("client socket failure %d\n", errno);
printf("client ERROR: create_socket failed %d\n");
exit(1);
}
@ -111,12 +164,12 @@ void send_client(void)
#ifdef CONFIG_EXAMPLES_UDP_IPv6
server.sin6_family = AF_INET6;
server.sin6_port = HTONS(PORTNO);
server.sin6_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
memcpy(server.sin6_addr.s6_addr16, g_server_ipv6, 8 * sizeof(uint16_t));
addrlen = sizeof(struct sockaddr_in6);
#else
server.sin_family = AF_INET;
server.sin_port = HTONS(PORTNO);
server.sin_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
server.sin_addr.s_addr = (in_addr_t)g_server_ipv4;
addrlen = sizeof(struct sockaddr_in);
#endif

View File

@ -50,7 +50,7 @@
****************************************************************************/
#ifdef CONFIG_EXAMPLES_UDP_IPv6
uint16_t g_server_ipv6[8] =
uint16_t g_server_ipv6[8] =
{
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_1),
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_2),

View File

@ -124,13 +124,13 @@ void recv_server(void)
#ifdef CONFIG_EXAMPLES_UDP_IPv6
server.sin6_family = AF_INET6;
server.sin6_port = HTONS(PORTNO);
server.sin6_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
memset(&server.sin6_addr, 0, sizeof(struct in6_addr));
addrlen = sizeof(struct sockaddr_in6);
#else
server.sin_family = AF_INET;
server.sin_port = HTONS(PORTNO);
server.sin_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
server.sin_addr.s_addr = HTONL(INADDR_ANY);
addrlen = sizeof(struct sockaddr_in);