Commit b7d01f3f authored by Dafydd Harries's avatar Dafydd Harries

stun client: time out request after 5 seconds

darcs-hash:20070107151007-c9803-ec392192f425d6b554d81f58a81cc0164fd0f83d.gz
parent 34fa2db9
#include <errno.h>
#include <netdb.h> #include <netdb.h>
#include <string.h> #include <string.h>
#include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <glib.h> #include <glib.h>
...@@ -28,10 +30,13 @@ main (int argc, char **argv) ...@@ -28,10 +30,13 @@ main (int argc, char **argv)
{ {
struct hostent he; struct hostent he;
struct sockaddr_in sin; struct sockaddr_in sin;
struct timeval tv;
fd_set fds;
guint sock; guint sock;
gchar *packed; gchar *packed;
guint length; guint length;
gchar buffer[256]; gchar buffer[256];
gint ret;
StunMessage *msg; StunMessage *msg;
StunAttribute **attr; StunAttribute **attr;
...@@ -68,6 +73,24 @@ main (int argc, char **argv) ...@@ -68,6 +73,24 @@ main (int argc, char **argv)
g_free (packed); g_free (packed);
stun_message_free (msg); stun_message_free (msg);
FD_ZERO (&fds);
FD_SET (sock, &fds);
tv.tv_sec = 5;
tv.tv_usec = 0;
ret = select (sock + 1, &fds, NULL, NULL, &tv);
if (ret < 0)
{
g_print ("error: %s", g_strerror (errno));
return 1;
}
else if (ret == 0)
{
g_print ("timeout\n");
return 1;
}
length = recv (sock, buffer, 256, 0); length = recv (sock, buffer, 256, 0);
msg = stun_message_unpack (length, buffer); msg = stun_message_unpack (length, buffer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment