2005-02-23 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* ospfd.h: Add new field struct stream *ibuf to struct ospf.
	* ospfd.c: (ospf_new) Check return code from ospf_sock_init.
	  Allocate ibuf using stream_new(OSPF_MAX_PACKET_SIZE+1).
	  (ospf_finish) Call stream_free(ospf->ibuf.
	* ospf_packet.c: (ospf_read) Call stream_reset(ospf->ibuf) and then
	  pass it to ospf_recv_packet for use in receiving the packet
	  (instead of allocating a new stream for each packet received).
	  Eliminate all calls to stream_free(ibuf).
	  (ospf_recv_packet) The struct stream *ibuf is now passed in as
	  an argument.  No need to use recvfrom to peek at the packet
	  header (to see how big it is), just use ospf->ibuf which is
	  always large enough (this eliminates a system call to recvfrom).
	  Therefore, no need to allocate a stream just for this packet,
	  and no need to free it when done.
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 931ae49..a77fb4b 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -204,9 +204,19 @@
 					   new, new->lsa_refresh_interval);
   new->lsa_refresher_started = time (NULL);
 
-  new->fd = ospf_sock_init ();
-  if (new->fd >= 0)
-    new->t_read = thread_add_read (master, ospf_read, new, new->fd);
+  if ((new->fd = ospf_sock_init()) < 0)
+    {
+      zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
+	       "a socket");
+      exit(1);
+    }
+  if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE+1)) == NULL)
+    {
+      zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
+	       OSPF_MAX_PACKET_SIZE+1);
+      exit(1);
+    }
+  new->t_read = thread_add_read (master, ospf_read, new, new->fd);
   new->oi_write_q = list_new ();
   
   return new;
@@ -360,6 +370,7 @@
   OSPF_TIMER_OFF (ospf->t_write);
 
   close (ospf->fd);
+  stream_free(ospf->ibuf);
    
 #ifdef HAVE_OPAQUE_LSA
   LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa)