/* 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; }