Use CUnit for tests.
[libradsec.git] / lib / tests / udp.c
index 184325e..2c580da 100644 (file)
@@ -1,3 +1,6 @@
+/* Copyright 2011,2013, NORDUnet A/S. All rights reserved. */
+/* See LICENSE for licensing information. */
+
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -10,6 +13,7 @@
 #include <netdb.h>
 #include <sys/select.h>
 #include <sys/time.h>
+#include "radius/client.h"
 #include "udp.h"
 
 static struct addrinfo *
@@ -40,14 +44,27 @@ _resolve (const char *str)
   return rp;
 }
 
+void
+udp_free_polldata (struct polldata *data)
+{
+  if (data)
+    {
+      if (data->timeout)
+       free (data->timeout);
+      free (data);
+    }
+}
+
+/* @return if select() returns error or timeout, return select()
+   else return value from invoked callback function */
 ssize_t
 udp_poll (struct polldata *data)
 {
   int r;
-  long timeout;
+  long timeout = 0;
   fd_set rfds;
   ssize_t len;
-  uint8_t buf[4096];
+  uint8_t buf[RS_MAX_PACKET_LEN];
 
   FD_ZERO (&rfds);
   FD_SET (data->s, &rfds);
@@ -106,3 +123,19 @@ udp_server (const char *bindto, struct timeval *timeout, data_cb cb)
 
   return NULL;
 }
+
+ssize_t
+hd (const uint8_t *buf, ssize_t len)
+{
+  int i;
+
+  printf ("# len: %ld\n", len);
+  for (i = 0; i < len; i++)
+    {
+      printf ("%02x%s", buf[i], (i+1) % 8 ? " " : "   ");
+      if ((i + 1) % 16 == 0)
+       printf ("\n");
+    }
+  printf ("\n");
+  return len;
+}