]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(main): Add ether_line tests.
authorUlrich Drepper <drepper@redhat.com>
Fri, 24 May 2002 08:29:30 +0000 (08:29 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 24 May 2002 08:29:30 +0000 (08:29 +0000)
inet/tst-ether_aton.c

index 24718f48ded22b91f9b14ab399f2bfcd3aa454e0..94ceec80ff0a1efdd49b21f7ed1ee0594ece3ec9 100644 (file)
@@ -1,29 +1,57 @@
 #include <stdio.h>
+#include <string.h>
 #include <netinet/ether.h>
 
 int
 main (int argc, char *argv[])
 {
-  struct ether_addr *val;
-  int result;
+  struct ether_addr *valp, val;
+  int result, r;
+  char hostname[32], buf[64], *p;
 
-  val = ether_aton ("12:34:56:78:9a:bc");
+  valp = ether_aton ("12:34:56:78:9a:bc");
 
   printf ("ether_aton (\"12:34:56:78:9a:bc\") = %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n",
-         val->ether_addr_octet[0],
-         val->ether_addr_octet[1],
-         val->ether_addr_octet[2],
-         val->ether_addr_octet[3],
-         val->ether_addr_octet[4],
-         val->ether_addr_octet[5]);
-
-
-  result = (val->ether_addr_octet[0] != 0x12
-           || val->ether_addr_octet[1] != 0x34
-           || val->ether_addr_octet[2] != 0x56
-           || val->ether_addr_octet[3] != 0x78
-           || val->ether_addr_octet[4] != 0x9a
-           || val->ether_addr_octet[5] != 0xbc);
+         valp->ether_addr_octet[0],
+         valp->ether_addr_octet[1],
+         valp->ether_addr_octet[2],
+         valp->ether_addr_octet[3],
+         valp->ether_addr_octet[4],
+         valp->ether_addr_octet[5]);
+
+  result = (valp->ether_addr_octet[0] != 0x12
+           || valp->ether_addr_octet[1] != 0x34
+           || valp->ether_addr_octet[2] != 0x56
+           || valp->ether_addr_octet[3] != 0x78
+           || valp->ether_addr_octet[4] != 0x9a
+           || valp->ether_addr_octet[5] != 0xbc);
+
+  if ((r = ether_line ("0:c0:f0:46:5f:97 host.ether.com \t# comment",
+                      &val, hostname)) == 0)
+    {
+      ether_ntoa_r (&val, buf);
+      p = strchr (buf, '\0');
+      *p++ = ' ';
+      strcpy (p, hostname);
+
+      printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = \"%s\"\n",
+             buf);
+
+      result |= strcmp ("0:c0:f0:46:5f:97 host.ether.com", buf) != 0;
+    }
+  else
+    {
+      printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = %d\n", r);
+      result |= 1;
+    }
+
+  r = ether_line ("0:c0:2:d0 foo.bar   ", &val, hostname);
+  printf ("ether_line (\"0:c0:2:d0 foo.bar   \") = %d\n", r);
+  result |= r != -1;
+
+  r = ether_line ("0:c0:2:d0:1a:2a  ", &val, hostname);
+  printf ("ether_line (\"0:c0:2:d0:1a:2a  \") = %d\n", r);
+  result |= r != -1;
 
   return result;
 }