#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
-#ifdef WIN32
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
#ifndef WIN32
#include <unistd.h>
#endif
unsigned char reply_buf[1024];
fd_set rfds;
struct timeval to = { STUN_TIMEOUT, 0 };
- struct sockaddr_in src;
-#ifdef WIN32
- int srclen;
-#else
- socklen_t srclen;
-#endif
int res = stun_send(sock, server, req);
if(res < 0)
res = select(sock + 1, &rfds, NULL, NULL, &to);
if (res <= 0) /* timeout or error */
return -11;
- memset(&src, 0, sizeof(src));
- srclen = sizeof(src);
- /* XXX pass -1 in the size, because stun_handle_packet might
- * write past the end of the buffer.
- */
+ struct sockaddr_in src = {};
+ socklen_t srclen = sizeof(src);
+
+ // XXX pass -1 in the size, because stun_handle_packet might
+ // write past the end of the buffer.
res = recvfrom(sock, (char *)reply_buf, sizeof(reply_buf) - 1,
0, (struct sockaddr *)&src, &srclen);
if (res <= 0)
return -12;
- memset(mapped, 0, sizeof(struct sockaddr_in));
return stun_handle_packet(sock, &src, reply_buf, res, stun_get_mapped, mapped);
} // StunRequest2
if (hostinfo == NULL)
return -1;
- struct sockaddr_in server, client;
- memset(&server, 0, sizeof(server));
- memset(&client, 0, sizeof(client));
- server.sin_family = client.sin_family = AF_INET;
-
- server.sin_addr = *(struct in_addr*) hostinfo->h_addr;
- server.sin_port = htons(port);
-
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET)
return -2;
+ struct sockaddr_in server = {}, client = {};
+
+ server.sin_family = client.sin_family = AF_INET;
+ server.sin_addr = *(struct in_addr*) hostinfo->h_addr;
+ server.sin_port = htons(port);
client.sin_addr.s_addr = htonl(INADDR_ANY);
int rc = -3;