15e9cd1aeSAssar Westerlund /*
2*ae771770SStanislav Sedov * Copyright (c) 2000 - 2002 Kungliga Tekniska Högskolan
35e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden).
45e9cd1aeSAssar Westerlund * All rights reserved.
55e9cd1aeSAssar Westerlund *
65e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without
75e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions
85e9cd1aeSAssar Westerlund * are met:
95e9cd1aeSAssar Westerlund *
105e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright
115e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer.
125e9cd1aeSAssar Westerlund *
135e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright
145e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the
155e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution.
165e9cd1aeSAssar Westerlund *
175e9cd1aeSAssar Westerlund * 3. Neither the name of KTH nor the names of its contributors may be
185e9cd1aeSAssar Westerlund * used to endorse or promote products derived from this software without
195e9cd1aeSAssar Westerlund * specific prior written permission.
205e9cd1aeSAssar Westerlund *
215e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
225e9cd1aeSAssar Westerlund * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
245e9cd1aeSAssar Westerlund * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
255e9cd1aeSAssar Westerlund * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
265e9cd1aeSAssar Westerlund * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
275e9cd1aeSAssar Westerlund * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
285e9cd1aeSAssar Westerlund * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
295e9cd1aeSAssar Westerlund * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
305e9cd1aeSAssar Westerlund * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
315e9cd1aeSAssar Westerlund * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
325e9cd1aeSAssar Westerlund
335e9cd1aeSAssar Westerlund #include "krb5_locl.h"
345e9cd1aeSAssar Westerlund #include <err.h>
358373020dSJacques Vidrine #include <getarg.h>
365e9cd1aeSAssar Westerlund
375e9cd1aeSAssar Westerlund /* print all addresses that we find */
385e9cd1aeSAssar Westerlund
395e9cd1aeSAssar Westerlund static void
print_addresses(krb5_context context,const krb5_addresses * addrs)405e9cd1aeSAssar Westerlund print_addresses (krb5_context context, const krb5_addresses *addrs)
415e9cd1aeSAssar Westerlund {
425e9cd1aeSAssar Westerlund int i;
435e9cd1aeSAssar Westerlund char buf[256];
445e9cd1aeSAssar Westerlund size_t len;
455e9cd1aeSAssar Westerlund
465e9cd1aeSAssar Westerlund for (i = 0; i < addrs->len; ++i) {
475e9cd1aeSAssar Westerlund krb5_print_address (&addrs->val[i], buf, sizeof(buf), &len);
485e9cd1aeSAssar Westerlund printf ("%s\n", buf);
495e9cd1aeSAssar Westerlund }
505e9cd1aeSAssar Westerlund }
515e9cd1aeSAssar Westerlund
528373020dSJacques Vidrine static int version_flag = 0;
538373020dSJacques Vidrine static int help_flag = 0;
548373020dSJacques Vidrine
558373020dSJacques Vidrine static struct getargs args[] = {
568373020dSJacques Vidrine {"version", 0, arg_flag, &version_flag,
578373020dSJacques Vidrine "print version", NULL },
588373020dSJacques Vidrine {"help", 0, arg_flag, &help_flag,
598373020dSJacques Vidrine NULL, NULL }
608373020dSJacques Vidrine };
618373020dSJacques Vidrine
628373020dSJacques Vidrine static void
usage(int ret)638373020dSJacques Vidrine usage (int ret)
648373020dSJacques Vidrine {
658373020dSJacques Vidrine arg_printusage (args,
668373020dSJacques Vidrine sizeof(args)/sizeof(*args),
678373020dSJacques Vidrine NULL,
688373020dSJacques Vidrine "");
698373020dSJacques Vidrine exit (ret);
708373020dSJacques Vidrine }
718373020dSJacques Vidrine
725e9cd1aeSAssar Westerlund int
main(int argc,char ** argv)735e9cd1aeSAssar Westerlund main(int argc, char **argv)
745e9cd1aeSAssar Westerlund {
755e9cd1aeSAssar Westerlund krb5_context context;
765e9cd1aeSAssar Westerlund krb5_error_code ret;
775e9cd1aeSAssar Westerlund krb5_addresses addrs;
78c19800e8SDoug Rabson int optidx = 0;
798373020dSJacques Vidrine
808373020dSJacques Vidrine setprogname (argv[0]);
818373020dSJacques Vidrine
82c19800e8SDoug Rabson if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
838373020dSJacques Vidrine usage(1);
848373020dSJacques Vidrine
858373020dSJacques Vidrine if (help_flag)
868373020dSJacques Vidrine usage (0);
878373020dSJacques Vidrine
888373020dSJacques Vidrine if(version_flag){
898373020dSJacques Vidrine print_version(NULL);
908373020dSJacques Vidrine exit(0);
918373020dSJacques Vidrine }
928373020dSJacques Vidrine
935e9cd1aeSAssar Westerlund ret = krb5_init_context(&context);
945e9cd1aeSAssar Westerlund if (ret)
955e9cd1aeSAssar Westerlund errx (1, "krb5_init_context failed: %d", ret);
965e9cd1aeSAssar Westerlund
975e9cd1aeSAssar Westerlund ret = krb5_get_all_client_addrs (context, &addrs);
985e9cd1aeSAssar Westerlund if (ret)
995e9cd1aeSAssar Westerlund krb5_err (context, 1, ret, "krb5_get_all_client_addrs");
1005e9cd1aeSAssar Westerlund printf ("client addresses\n");
1015e9cd1aeSAssar Westerlund print_addresses (context, &addrs);
1025e9cd1aeSAssar Westerlund krb5_free_addresses (context, &addrs);
1035e9cd1aeSAssar Westerlund
1045e9cd1aeSAssar Westerlund ret = krb5_get_all_server_addrs (context, &addrs);
1055e9cd1aeSAssar Westerlund if (ret)
1065e9cd1aeSAssar Westerlund krb5_err (context, 1, ret, "krb5_get_all_server_addrs");
1075e9cd1aeSAssar Westerlund printf ("server addresses\n");
1085e9cd1aeSAssar Westerlund print_addresses (context, &addrs);
1095e9cd1aeSAssar Westerlund krb5_free_addresses (context, &addrs);
1105e9cd1aeSAssar Westerlund return 0;
1115e9cd1aeSAssar Westerlund }
112