Skip to content

Instantly share code, notes, and snippets.

@hach-que
Created February 13, 2018 03:31
Show Gist options
  • Save hach-que/ef1ec3247cf3be1d6d1cdc55f58cf752 to your computer and use it in GitHub Desktop.
Save hach-que/ef1ec3247cf3be1d6d1cdc55f58cf752 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include "libzt.h"
#include <inttypes.h>
#if defined(_WIN32)
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <Ws2def.h>
#include <stdint.h>
#include <windows.h>
#endif
int main()
{
uint64_t nwid = 0xa09acf0233eabcde;
zts_startjoin("place", nwid);
int result, socket_fd;
fd_set readset;
socket_fd = zts_socket(AF_INET6, SOCK_DGRAM, 0);
sockaddr_in6 servicezt6;
servicezt6.sin6_family = AF_INET6;
servicezt6.sin6_addr = IN6ADDR_ANY_INIT;
servicezt6.sin6_port = htons(9595);
int err = zts_bind(socket_fd, (struct sockaddr*)&servicezt6, sizeof(sockaddr_in6));
err = zts_listen(socket_fd, 1);
while (true)
{
FD_ZERO(&readset);
FD_SET(socket_fd, &readset);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 100;
result = zts_select(socket_fd + 1, &readset, NULL, NULL, &timeout);
DEBUG_INFO("result=%d", result);
if (result > 0)
{
char buffer[2048];
struct sockaddr_storage src_addr;
socklen_t src_addr_len = sizeof(src_addr);
ssize_t count = zts_recvfrom(socket_fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&src_addr, &src_addr_len);
DEBUG_INFO("buf=%s", &buf);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment