  			{
  			/* (Re-)Start logging to a new file */
  			time_t now;
-@@ -1144,11 +1161,15 @@
+@@ -1144,6 +1161,10 @@
  
  			generate(tx_asn, cur_tg, lasttime);
  			}

 		}
 
 	/* Finished, tear down connection.				*/
 
-	if ((*(prot.prot->teardown))(tx_asn) == -1)
+	if (tx_asn >= 0 && (*(prot.prot->teardown))(tx_asn) == -1)
 		{
 
 		/* log the teardown error. */
@@ -1156,6 +1177,7 @@
 		perror("do_actions: protocol teardown");
 		exit(-1);
 		}
+	active_tx_asn = -1;
 
 	return;
 	}
@@ -1341,6 +1363,12 @@
 
 		if (arrival != 0)
 			(*(prot.prot->sleep_till))(&nextpkt_tv);

 		lasttime = nextpkt_tv;
 
 		/* Did we exceed the limit on the number of packets to send? */
@@ -1382,6 +1412,10 @@
 						   pktlen,
 						   &(cur_tg->stop_before),
 						   &pktid);
