xref: /freebsd/crypto/heimdal/lib/krb5/test_get_addrs.c (revision 5e9cd1ae3e10592ed70e7575551cba1bbab04d84)
15e9cd1aeSAssar Westerlund /*
25e9cd1aeSAssar Westerlund  * Copyright (c) 2000 - 2001 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>
355e9cd1aeSAssar Westerlund 
365e9cd1aeSAssar Westerlund RCSID("$Id: test_get_addrs.c,v 1.3 2001/01/25 12:45:15 assar Exp $");
375e9cd1aeSAssar Westerlund 
385e9cd1aeSAssar Westerlund /* print all addresses that we find */
395e9cd1aeSAssar Westerlund 
405e9cd1aeSAssar Westerlund static void
415e9cd1aeSAssar Westerlund print_addresses (krb5_context context, const krb5_addresses *addrs)
425e9cd1aeSAssar Westerlund {
435e9cd1aeSAssar Westerlund     int i;
445e9cd1aeSAssar Westerlund     char buf[256];
455e9cd1aeSAssar Westerlund     size_t len;
465e9cd1aeSAssar Westerlund 
475e9cd1aeSAssar Westerlund     for (i = 0; i < addrs->len; ++i) {
485e9cd1aeSAssar Westerlund 	krb5_print_address (&addrs->val[i], buf, sizeof(buf), &len);
495e9cd1aeSAssar Westerlund 	printf ("%s\n", buf);
505e9cd1aeSAssar Westerlund     }
515e9cd1aeSAssar Westerlund }
525e9cd1aeSAssar Westerlund 
535e9cd1aeSAssar Westerlund int
545e9cd1aeSAssar Westerlund main(int argc, char **argv)
555e9cd1aeSAssar Westerlund {
565e9cd1aeSAssar Westerlund     krb5_context context;
575e9cd1aeSAssar Westerlund     krb5_error_code ret;
585e9cd1aeSAssar Westerlund     krb5_addresses addrs;
595e9cd1aeSAssar Westerlund 
605e9cd1aeSAssar Westerlund     ret = krb5_init_context(&context);
615e9cd1aeSAssar Westerlund     if (ret)
625e9cd1aeSAssar Westerlund 	errx (1, "krb5_init_context failed: %d", ret);
635e9cd1aeSAssar Westerlund 
645e9cd1aeSAssar Westerlund     ret = krb5_get_all_client_addrs (context, &addrs);
655e9cd1aeSAssar Westerlund     if (ret)
665e9cd1aeSAssar Westerlund 	krb5_err (context, 1, ret, "krb5_get_all_client_addrs");
675e9cd1aeSAssar Westerlund     printf ("client addresses\n");
685e9cd1aeSAssar Westerlund     print_addresses (context, &addrs);
695e9cd1aeSAssar Westerlund     krb5_free_addresses (context, &addrs);
705e9cd1aeSAssar Westerlund 
715e9cd1aeSAssar Westerlund     ret = krb5_get_all_server_addrs (context, &addrs);
725e9cd1aeSAssar Westerlund     if (ret)
735e9cd1aeSAssar Westerlund 	krb5_err (context, 1, ret, "krb5_get_all_server_addrs");
745e9cd1aeSAssar Westerlund     printf ("server addresses\n");
755e9cd1aeSAssar Westerlund     print_addresses (context, &addrs);
765e9cd1aeSAssar Westerlund     krb5_free_addresses (context, &addrs);
775e9cd1aeSAssar Westerlund     return 0;
785e9cd1aeSAssar Westerlund }
79