--- netpipe-3.7.1.orig/src/tcp.c
+++ netpipe-3.7.1/src/tcp.c
@@ -28,6 +28,79 @@
    p->rcv = 1;
 }
 
+void establish(ArgStruct *p)
+{
+  int one = 1;
+  socklen_t clen;
+  struct protoent *proto;
+
+  clen = (socklen_t) sizeof(p->prot.sin2);
+
+  if( p->tr ){
+
+    while( connect(p->commfd, (struct sockaddr *) &(p->prot.sin1),
+                   sizeof(p->prot.sin1)) < 0 ) {
+
+      /* If we are doing a reset and we get a connection refused from
+       * the connect() call, assume that the other node has not yet
+       * gotten to its corresponding accept() call and keep trying until
+       * we have success.
+       */
+      if(!doing_reset || errno != ECONNREFUSED) {
+        printf("Client: Cannot Connect! errno=%d\n",errno);
+        exit(-10);
+      } 
+        
+    }
+
+  } else if( p->rcv ) {
+
+    /* SERVER */
+    listen(p->servicefd, 5);
+    p->commfd = accept(p->servicefd, (struct sockaddr *) &(p->prot.sin2), &clen);
+
+    if(p->commfd < 0){
+      printf("Server: Accept Failed! errno=%d\n",errno);
+      exit(-12);
+    }
+
+    /*
+      Attempt to set TCP_NODELAY. TCP_NODELAY may or may not be propagated
+      to accepted sockets.
+     */
+    if(!(proto = getprotobyname("tcp"))){
+      printf("unknown protocol!\n");
+      exit(555);
+    }
+
+    if(setsockopt(p->commfd, proto->p_proto, TCP_NODELAY,
+                  &one, sizeof(one)) < 0)
+    {
+      printf("setsockopt: TCP_NODELAY failed! errno=%d\n", errno);
+      exit(556);
+    }
+
+    /* If requested, set the send and receive buffer sizes */
+    if(p->prot.sndbufsz > 0)
+    {
+/*      printf("Send and Receive Buffers on accepted socket set to %d bytes\n",*/
+/*           p->prot.sndbufsz);*/
+      if(setsockopt(p->commfd, SOL_SOCKET, SO_SNDBUF, &(p->prot.sndbufsz), 
+                                       sizeof(p->prot.sndbufsz)) < 0)
+      {
+        printf("setsockopt: SO_SNDBUF failed! errno=%d\n", errno);
+        exit(556);
+      }
+      if(setsockopt(p->commfd, SOL_SOCKET, SO_RCVBUF, &(p->prot.rcvbufsz), 
+                                       sizeof(p->prot.rcvbufsz)) < 0)
+      {
+        printf("setsockopt: SO_RCVBUF failed! errno=%d\n", errno);
+        exit(556);
+      }
+    }
+  }
+}
+
 void Setup(ArgStruct *p)
 {
 
@@ -164,10 +237,16 @@
 {
     char s[] = "SyncMe", response[] = "      ";
 
-    if (write(p->commfd, s, strlen(s)) < 0 ||           /* Write to nbor */
-        readFully(p->commfd, response, strlen(s)) < 0)  /* Read from nbor */
+    /* Write to nbor */
+    if (write(p->commfd, s, strlen(s)) < 0) 
+      {
+	perror("NetPIPE: error writing syncronization string");
+	exit(3);
+      }
+    /* Read from nbor */
+    if (readFully(p->commfd, response, strlen(s)) < 0)
       {
-        perror("NetPIPE: error writing or reading synchronization string");
+        perror("NetPIPE: error reading synchronization string");
         exit(3);
       }
     if (strncmp(s, response, strlen(s)))
@@ -314,84 +393,6 @@
   *rpt = lrpt;
 }
 
-void establish(ArgStruct *p)
-{
-  int one = 1;
-  socklen_t clen;
-  struct protoent *proto;
-
-  clen = (socklen_t) sizeof(p->prot.sin2);
-
-  if( p->tr ){
-
-    while( connect(p->commfd, (struct sockaddr *) &(p->prot.sin1),
-                   sizeof(p->prot.sin1)) < 0 ) {
-
-      /* If we are doing a reset and we get a connection refused from
-       * the connect() call, assume that the other node has not yet
-       * gotten to its corresponding accept() call and keep trying until
-       * we have success.
-       */
-      if(!doing_reset || errno != ECONNREFUSED) {
-        printf("Client: Cannot Connect! errno=%d\n",errno);
-        exit(-10);
-      } 
-        
-    }
-
-  } else if( p->rcv ) {
-
-    /* SERVER */
-    listen(p->servicefd, 5);
-    p->commfd = accept(p->servicefd, (struct sockaddr *) &(p->prot.sin2), &clen);
-
-    if(p->commfd < 0){
-      printf("Server: Accept Failed! errno=%d\n",errno);
-      exit(-12);
-    }
-
-    /*
-      Attempt to set TCP_NODELAY. TCP_NODELAY may or may not be propagated
-      to accepted sockets.
-     */
-    if(!(proto = getprotobyname("tcp"))){
-      printf("unknown protocol!\n");
-      exit(555);
-    }
-
-    if(setsockopt(p->commfd, proto->p_proto, TCP_NODELAY,
-                  &one, sizeof(one)) < 0)
-    {
-      printf("setsockopt: TCP_NODELAY failed! errno=%d\n", errno);
-      exit(556);
-    }
-    
-    if (setsockopt(p->commfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))) {
-      printf("NetPIPE: server: unable to setsockopt -- errno %d\n", errno);
-      exit(557);
-    }
-
-    /* If requested, set the send and receive buffer sizes */
-    if(p->prot.sndbufsz > 0)
-    {
-/*      printf("Send and Receive Buffers on accepted socket set to %d bytes\n",*/
-/*           p->prot.sndbufsz);*/
-      if(setsockopt(p->commfd, SOL_SOCKET, SO_SNDBUF, &(p->prot.sndbufsz), 
-                                       sizeof(p->prot.sndbufsz)) < 0)
-      {
-        printf("setsockopt: SO_SNDBUF failed! errno=%d\n", errno);
-        exit(556);
-      }
-      if(setsockopt(p->commfd, SOL_SOCKET, SO_RCVBUF, &(p->prot.rcvbufsz), 
-                                       sizeof(p->prot.rcvbufsz)) < 0)
-      {
-        printf("setsockopt: SO_RCVBUF failed! errno=%d\n", errno);
-        exit(556);
-      }
-    }
-  }
-}
-
 void CleanUp(ArgStruct *p)
 {
    char *quit="QUIT";
--- netpipe-3.7.1.orig/src/netpipe.h
+++ netpipe-3.7.1/src/netpipe.h
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <sys/time.h>       /* struct timeval */
 #include <sys/resource.h>   /* getrusage() */
 #include <stdlib.h>         /* malloc(3) */
@@ -384,6 +385,10 @@
 
 void ResetRecvPtr(ArgStruct* p);
 
+void AfterAlignmentInit(ArgStruct* p);
+
+/* void InitBufferData(ArgStruct *p, int nbytes); */
+
 void PrintUsage();
 
 int getopt( int argc, char * const argv[], const char *optstring);
--- netpipe-3.7.1.orig/src/netpipe.c
+++ netpipe-3.7.1/src/netpipe.c
@@ -142,7 +142,7 @@
                       printf("Performance measured without cache effects\n\n"); fflush(stdout);
                       break;
 
-            case 'o': strcpy(s,optarg);
+            case 'o': memset(s,0,sizeof(s));strncpy(s,optarg,sizeof(s)-1);
                       printf("Sending output to %s\n", s); fflush(stdout);
                       break;
 
