updated api tests
This commit is contained in:
46
tests/api_test/udpserver6.c
Executable file
46
tests/api_test/udpserver6.c
Executable file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXBUF 65536
|
||||
|
||||
int main()
|
||||
{
|
||||
int sock;
|
||||
int status;
|
||||
struct sockaddr_in6 sin6;
|
||||
int sin6len;
|
||||
char buffer[MAXBUF];
|
||||
|
||||
sock = socket(PF_INET6, SOCK_DGRAM,0);
|
||||
|
||||
sin6len = sizeof(struct sockaddr_in6);
|
||||
|
||||
memset(&sin6, 0, sin6len);
|
||||
|
||||
/* just use the first address returned in the structure */
|
||||
|
||||
sin6.sin6_port = htons(0);
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_addr = in6addr_any;
|
||||
|
||||
status = bind(sock, (struct sockaddr *)&sin6, sin6len);
|
||||
if(-1 == status)
|
||||
perror("bind"), exit(1);
|
||||
|
||||
status = getsockname(sock, (struct sockaddr *)&sin6, &sin6len);
|
||||
|
||||
printf("%d\n", ntohs(sin6.sin6_port));
|
||||
|
||||
status = recvfrom(sock, buffer, MAXBUF, 0,
|
||||
(struct sockaddr *)&sin6, &sin6len);
|
||||
printf("buffer : %s\n", buffer);
|
||||
|
||||
shutdown(sock, 2);
|
||||
close(sock);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user