summary refs log tree commit diff
path: root/inet/tst-ether_aton.c
blob: eba350ed3a7481f0b66cbdfa74be36874c607652 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <string.h>
#include <netinet/ether.h>

static int
do_test (void)
{
  struct ether_addr *valp, val;
  int result, r;
  char hostname[32], buf[64], *p;

  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",
	  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;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"