summaryrefslogtreecommitdiff
path: root/support/dktools/test-peer.c
blob: fbf9317fee520f5dd5d93683a0a12717f67fb89d (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: test-peer.ctr
*/

/*
Copyright (C) 2015-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**	@file test-peer.c The test-peer module.
*/


#line 10 "test-peer.ctr"

#include "dk4conf.h"
#include "dk4app.h"
#include "dk4sock.h"
#include "dk4socka.h"
#include "dk4vers.h"
#include "dk4fput.h"





#line 21 "test-peer.ctr"


static
void
dk4socket_c8_debug_allowed_peer(dk4_allowed_peer_t *peerptr)
{
#if DK4_HAVE_STRUCT_SOCKADDR_IN6 && defined(AF_INET6)
  unsigned char		*ucptr;
  size_t		 i;
  size_t		 pass;
#endif
  unsigned long ul1, ul2;

  if (NULL != stdout) {
    switch (peerptr->af) {
      case AF_INET : {
        ul1 = (peerptr->data).ipv4.ad.s_addr;
	ul2 = (peerptr->data).ipv4.ma.s_addr;
	ul1 = dk4socket_ntohl(ul1);
	ul2 = dk4socket_ntohl(ul2);
        fprintf(
	  stdout,
	  "Address/Mask: %lu.%lu.%lu.%lu/%lu.%lu.%lu.%lu\n",
	  ((ul1 >> 24) & 0x000000FFUL),
	  ((ul1 >> 16) & 0x000000FFUL),
	  ((ul1 >>  8) & 0x000000FFUL),
	  ((ul1      ) & 0x000000FFUL),
	  ((ul2 >> 24) & 0x000000FFUL),
	  ((ul2 >> 16) & 0x000000FFUL),
	  ((ul2 >>  8) & 0x000000FFUL),
	  ((ul2      ) & 0x000000FFUL)
	);
      } break;
#if DK4_HAVE_STRUCT_SOCKADDR_IN6 && defined(AF_INET6)
      case AF_INET6 : {
        fputs("Address/Mask: ", stdout);
	for (pass = 0; pass < 2; pass++) {
	  if (0 != pass) {
	    fputc('/', stdout);
	    ucptr = &((peerptr->data).ipv6.ma.s6_addr[0]);
	  } else {
	    ucptr = &((peerptr->data).ipv6.ad.s6_addr[0]);
	  }
	  for (i = 0; i < 16; i++) {
	    if ((0 != i) && (0 == (i % 2))) {
	      fputc(':', stdout);
	    }
	    fprintf(stdout, "%02x", *(ucptr++));
	  }
	}
	fputc('\n', stdout);
      } break;
#endif
    }
  }
}


/**     Main function.
        @param  argc    Number of command line arguments.
        @param  argv    Command line arguments array.
        @return 0 on success, all other values indicate errors.
*/
#if DK4_CHAR_SIZE > 1
int wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
  dk4_allowed_peer_t	apeer;
  dk4_er_t		er;
  size_t		i;
  int			res;
  

#line 95 "test-peer.ctr"
  

#line 96 "test-peer.ctr"
  if (DK4_SOCKET_RESULT_SUCCESS == dk4socket_up(NULL)) {	

#line 97 "test-peer.ctr"
    for (i = 1; i < argc; i++) {
      dk4error_init(&er);
      res = dk4socket_get_allowed_peer(&apeer, argv[i], &er);
      if (DK4_SOCKET_RESULT_SUCCESS == res) {
        printf("SUCCESS: %s\n", argv[i]);
        dk4socket_c8_debug_allowed_peer(&apeer);
      } else {
        printf("FAILED: %s\n", argv[i]);
      }
    }
    dk4socket_down(NULL);
  } else {				

#line 109 "test-peer.ctr"
  }
  

#line 111 "test-peer.ctr"
  

#line 112 "test-peer.ctr"
  exit(0); return 0;
}