[or-cvs] Add functions to parse addr[:port] consistently

Nick Mathewson nickm at seul.org
Tue Oct 12 15:48:33 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv26325/src/or

Modified Files:
	test.c 
Log Message:
Add functions to parse addr[:port] consistently

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- test.c	7 Oct 2004 21:37:06 -0000	1.121
+++ test.c	12 Oct 2004 15:48:30 -0000	1.122
@@ -500,6 +500,9 @@
   char buf[1024];
   time_t t_res;
   int i;
+  uint32_t u32;
+  uint16_t u16;
+  char *cp;
 
   start.tv_sec = 5;
   start.tv_usec = 5000;
@@ -633,6 +636,34 @@
                                  NEVER_TERMINATE));
   test_streq(buf, "abc##def##ghi");
 
+  /* Test parse_addr_port */
+  cp = NULL; u32 = 3; u16 = 3;
+  test_assert(!parse_addr_port("1.2.3.4", &cp, &u32, &u16));
+  test_streq(cp, "1.2.3.4");
+  test_eq(u32, 0x01020304u);
+  test_eq(u16, 0);
+  tor_free(cp);
+  test_assert(!parse_addr_port("4.3.2.1:99", &cp, &u32, &u16));
+  test_streq(cp, "4.3.2.1");
+  test_eq(u32, 0x04030201u);
+  test_eq(u16, 99);
+  tor_free(cp);
+  test_assert(!parse_addr_port("nonexistent.address:4040", &cp, NULL, &u16));
+  test_streq(cp, "nonexistent.address");
+  test_eq(u16, 4040);
+  tor_free(cp);
+  test_assert(!parse_addr_port("localhost:9999", &cp, &u32, &u16));
+  test_streq(cp, "localhost");
+  test_eq(u32, 0x7f000001u);
+  test_eq(u16, 9999);
+  tor_free(cp);
+  u32 = 3;
+  test_assert(!parse_addr_port("localhost", NULL, &u32, &u16));
+  test_eq(cp, NULL);
+  test_eq(u32, 0x7f000001u);
+  test_eq(u16, 0);
+  tor_free(cp);
+
   /* XXXX test older functions. */
   smartlist_free(sl);
 }



More information about the tor-commits mailing list