Log incoming IP address when accepting a connection
[trust_router.git] / common / tr_comm.c
index 3b177bb..f8f91df 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, JANET(UK)
+ * Copyright (c) 2012-2018, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
 
 #include <tr_rp.h>
 #include <tr_idp.h>
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <tr_comm.h>
 #include <tr_debug.h>
 
@@ -372,10 +372,10 @@ static TR_COMM *tr_comm_sweep_func(TR_COMM *head)
     return NULL;
 
   /* will not remove the head here, that has already been done */
-  for (comm=head; comm->next!=NULL; comm=comm->next) {
+  for (comm=head; (comm!=NULL) && (comm->next!=NULL); comm=comm->next) {
     if (comm->next->refcount==0) {
       old_next=comm->next;
-      tr_comm_remove(head, comm->next); /* changes comm->next */
+      tr_comm_remove(head, comm->next); /* changes comm->next, may make it null */
       tr_comm_free(old_next);
     }
   }
@@ -1480,7 +1480,8 @@ cleanup:
 void tr_comm_table_print(FILE *f, TR_COMM_TABLE *ctab)
 {
   char *s=tr_comm_table_to_str(NULL, ctab);
-  if (s!=NULL)
-    fprintf(f, "%s", s);
-  talloc_free(s);
+  if (s!=NULL) {
+    tr_debug("%s", s);
+    talloc_free(s);
+  }
 }
\ No newline at end of file