172445Sassar/* 2102644Snectar * Copyright (c) 2000 - 2002 Kungliga Tekniska H�gskolan 372445Sassar * (Royal Institute of Technology, Stockholm, Sweden). 472445Sassar * All rights reserved. 572445Sassar * 672445Sassar * Redistribution and use in source and binary forms, with or without 772445Sassar * modification, are permitted provided that the following conditions 872445Sassar * are met: 972445Sassar * 1072445Sassar * 1. Redistributions of source code must retain the above copyright 1172445Sassar * notice, this list of conditions and the following disclaimer. 1272445Sassar * 1372445Sassar * 2. Redistributions in binary form must reproduce the above copyright 1472445Sassar * notice, this list of conditions and the following disclaimer in the 1572445Sassar * documentation and/or other materials provided with the distribution. 1672445Sassar * 1772445Sassar * 3. Neither the name of KTH nor the names of its contributors may be 1872445Sassar * used to endorse or promote products derived from this software without 1972445Sassar * specific prior written permission. 2072445Sassar * 2172445Sassar * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 2272445Sassar * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2372445Sassar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2472445Sassar * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 2572445Sassar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2672445Sassar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2772445Sassar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2872445Sassar * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2972445Sassar * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3072445Sassar * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3172445Sassar * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 3272445Sassar 3372445Sassar#include "krb5_locl.h" 3472445Sassar#include <err.h> 35102644Snectar#include <getarg.h> 3672445Sassar 37178825SdfrRCSID("$Id: test_get_addrs.c 15474 2005-06-17 04:48:02Z lha $"); 3872445Sassar 3972445Sassar/* print all addresses that we find */ 4072445Sassar 4172445Sassarstatic void 4272445Sassarprint_addresses (krb5_context context, const krb5_addresses *addrs) 4372445Sassar{ 4472445Sassar int i; 4572445Sassar char buf[256]; 4672445Sassar size_t len; 4772445Sassar 4872445Sassar for (i = 0; i < addrs->len; ++i) { 4972445Sassar krb5_print_address (&addrs->val[i], buf, sizeof(buf), &len); 5072445Sassar printf ("%s\n", buf); 5172445Sassar } 5272445Sassar} 5372445Sassar 54102644Snectarstatic int version_flag = 0; 55102644Snectarstatic int help_flag = 0; 56102644Snectar 57102644Snectarstatic struct getargs args[] = { 58102644Snectar {"version", 0, arg_flag, &version_flag, 59102644Snectar "print version", NULL }, 60102644Snectar {"help", 0, arg_flag, &help_flag, 61102644Snectar NULL, NULL } 62102644Snectar}; 63102644Snectar 64102644Snectarstatic void 65102644Snectarusage (int ret) 66102644Snectar{ 67102644Snectar arg_printusage (args, 68102644Snectar sizeof(args)/sizeof(*args), 69102644Snectar NULL, 70102644Snectar ""); 71102644Snectar exit (ret); 72102644Snectar} 73102644Snectar 7472445Sassarint 7572445Sassarmain(int argc, char **argv) 7672445Sassar{ 7772445Sassar krb5_context context; 7872445Sassar krb5_error_code ret; 7972445Sassar krb5_addresses addrs; 80178825Sdfr int optidx = 0; 8172445Sassar 82102644Snectar setprogname (argv[0]); 83102644Snectar 84178825Sdfr if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx)) 85102644Snectar usage(1); 86102644Snectar 87102644Snectar if (help_flag) 88102644Snectar usage (0); 89102644Snectar 90102644Snectar if(version_flag){ 91102644Snectar print_version(NULL); 92102644Snectar exit(0); 93102644Snectar } 94102644Snectar 95178825Sdfr argc -= optidx; 96178825Sdfr argv += optidx; 97102644Snectar 9872445Sassar ret = krb5_init_context(&context); 9972445Sassar if (ret) 10072445Sassar errx (1, "krb5_init_context failed: %d", ret); 10172445Sassar 10272445Sassar ret = krb5_get_all_client_addrs (context, &addrs); 10372445Sassar if (ret) 10472445Sassar krb5_err (context, 1, ret, "krb5_get_all_client_addrs"); 10572445Sassar printf ("client addresses\n"); 10672445Sassar print_addresses (context, &addrs); 10772445Sassar krb5_free_addresses (context, &addrs); 10872445Sassar 10972445Sassar ret = krb5_get_all_server_addrs (context, &addrs); 11072445Sassar if (ret) 11172445Sassar krb5_err (context, 1, ret, "krb5_get_all_server_addrs"); 11272445Sassar printf ("server addresses\n"); 11372445Sassar print_addresses (context, &addrs); 11472445Sassar krb5_free_addresses (context, &addrs); 11572445Sassar return 0; 11672445Sassar} 117