Commits

Alexandru Moșoi committed 1124b08

One more test from the book.

Comments (0)

Files changed (2)

test/frail-connect-listen-14.c

         F_reset();
         assert(ret == 0);
 
-        F_add(FO_NONE, F_and(F_has_ack(), F_has_fin()));
+        F_add(FO_NONE, F_and(F_has_ack_nr(301), F_has_fin()));
         ret = tcp_close();
         F_reset();
         assert(ret == 0);
 
-        F_add(FO_NONE, F_has_ack_nr(301 + strlen(message)));
-        F_add(FO_NONE, F_never());
+        F_add(FO_NONE, F_has_ack_nr(302));
         ret = tcp_read(buf, sizeof(buf));
-        F_reset();
-        assert(ret == strlen(message));
-        assert(memcmp(buf, message, strlen(message)) == 0);
+        assert(ret == -1);
 
-        ret = tcp_read(buf, sizeof(buf));
-        assert(ret == 0);
 
         return 0;
 }
 int server(ipaddr_t client_ip, ipaddr_t server_ip)
 {
         int ret;
+        char buf[128];
 
         tcp_socket();
         sleep(1);
         F_reset();
         assert(ret == 0);
 
-        ret = tcp_write(message, strlen(message));
-        assert(ret == strlen(message));
-
+        F_add(FO_NONE, F_and(F_has_ack_nr(802), F_has_fin()));
         ret = tcp_close();
         assert(ret == 0);
 
+        ret = tcp_read(buf, sizeof(buf));
+        assert(ret == -1);
+
         return 0;
 }

test/frail-connect-listen-15.c

+/**
+ * Exercise 1.4
+ * http://www.cs.vu.nl/~cn/exercise2.pdf
+ *
+ * tcp_listen() receives a FIN.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include "tcp_debug.h"
+
+char message[] = "frail framework is genious. my spelling is worse";
+
+void setup(void)
+{
+}
+
+int client(ipaddr_t client_ip, ipaddr_t server_ip)
+{
+        int ret;
+        char buf[128];
+
+        tcp_socket();
+        sleep(1);
+
+        tcp_connect_seq_nr = 800;
+        F_add(FO_NONE, F_has_syn());
+        F_add(FO_DROP, F_has_ack());
+        F_add(FO_NONE, F_never());
+        ret = tcp_connect(server_ip, 1234);
+        F_reset();
+        assert(ret == 0);
+
+        F_add(FO_NONE, F_and(F_has_ack(), F_has_fin()));
+        ret = tcp_close();
+        F_reset();
+        assert(ret == 0);
+
+        F_add(FO_NONE, F_has_ack_nr(301 + strlen(message)));
+        F_add(FO_NONE, F_never());
+        ret = tcp_read(buf, sizeof(buf));
+        F_reset();
+        assert(ret == strlen(message));
+        assert(memcmp(buf, message, strlen(message)) == 0);
+
+        ret = tcp_read(buf, sizeof(buf));
+        assert(ret == 0);
+
+        return 0;
+}
+
+int server(ipaddr_t client_ip, ipaddr_t server_ip)
+{
+        int ret;
+
+        tcp_socket();
+        sleep(1);
+
+        tcp_listen_seq_nr = 300;
+        F_add(FO_NONE, F_and(F_has_syn_ack(), F_has_ack_nr(801)));
+        F_add(FO_NONE, F_has_ack_nr(802));
+        F_add(FO_NONE, F_never());
+        ret = tcp_listen(1234, &client_ip);
+        F_reset();
+        assert(ret == 0);
+
+        ret = tcp_write(message, strlen(message));
+        assert(ret == strlen(message));
+
+        ret = tcp_close();
+        assert(ret == 0);
+
+        return 0;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.