Back to index

glibc  2.9
tst-ether_aton.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <netinet/ether.h>
00004 
00005 int
00006 main (int argc, char *argv[])
00007 {
00008   struct ether_addr *valp, val;
00009   int result, r;
00010   char hostname[32], buf[64], *p;
00011 
00012   valp = ether_aton ("12:34:56:78:9a:bc");
00013 
00014   printf ("ether_aton (\"12:34:56:78:9a:bc\") = %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n",
00015          valp->ether_addr_octet[0],
00016          valp->ether_addr_octet[1],
00017          valp->ether_addr_octet[2],
00018          valp->ether_addr_octet[3],
00019          valp->ether_addr_octet[4],
00020          valp->ether_addr_octet[5]);
00021 
00022   result = (valp->ether_addr_octet[0] != 0x12
00023            || valp->ether_addr_octet[1] != 0x34
00024            || valp->ether_addr_octet[2] != 0x56
00025            || valp->ether_addr_octet[3] != 0x78
00026            || valp->ether_addr_octet[4] != 0x9a
00027            || valp->ether_addr_octet[5] != 0xbc);
00028 
00029   if ((r = ether_line ("0:c0:f0:46:5f:97 host.ether.com \t# comment",
00030                      &val, hostname)) == 0)
00031     {
00032       ether_ntoa_r (&val, buf);
00033       p = strchr (buf, '\0');
00034       *p++ = ' ';
00035       strcpy (p, hostname);
00036 
00037       printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = \"%s\"\n",
00038              buf);
00039 
00040       result |= strcmp ("0:c0:f0:46:5f:97 host.ether.com", buf) != 0;
00041     }
00042   else
00043     {
00044       printf ("ether_line (\"0:c0:f0:46:5f:97 host.ether.com\") = %d\n", r);
00045       result |= 1;
00046     }
00047 
00048   r = ether_line ("0:c0:2:d0 foo.bar   ", &val, hostname);
00049   printf ("ether_line (\"0:c0:2:d0 foo.bar   \") = %d\n", r);
00050   result |= r != -1;
00051 
00052   r = ether_line ("0:c0:2:d0:1a:2a  ", &val, hostname);
00053   printf ("ether_line (\"0:c0:2:d0:1a:2a  \") = %d\n", r);
00054   result |= r != -1;
00055 
00056   return result;
00057 }