Merge branch 'libradsec-new-client' into libradsec
[radsecproxy.git] / lib / tests / udp.c
index 6c43a2f..47ea595 100644 (file)
@@ -40,14 +40,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
-poll (struct polldata *data)
+udp_poll (struct polldata *data)
 {
   int r;
   long timeout;
   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);
@@ -68,7 +81,7 @@ poll (struct polldata *data)
 }
 
 struct polldata *
-server (const char *bindto, struct timeval *timeout, data_cb cb)
+udp_server (const char *bindto, struct timeval *timeout, data_cb cb)
 {
   struct addrinfo *res;
   int s = -1;
@@ -106,3 +119,19 @@ 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;
+}