-: 0:Source:hostaddr.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/krb5/os/hostaddr.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/krb5/os/hostaddr.so.gcda -: 0:Runs:1602 -: 0:Programs:1 -: 1:/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -: 2:/* lib/krb5/os/hostaddr.c - Return list of krb5 addresses for a hostname */ -: 3:/* -: 4: * Copyright 1990,1991,2008 by the Massachusetts Institute of Technology. -: 5: * All Rights Reserved. -: 6: * -: 7: * Export of this software from the United States of America may -: 8: * require a specific license from the United States Government. -: 9: * It is the responsibility of any person or organization contemplating -: 10: * export to obtain such a license before exporting. -: 11: * -: 12: * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and -: 13: * distribute this software and its documentation for any purpose and -: 14: * without fee is hereby granted, provided that the above copyright -: 15: * notice appear in all copies and that both that copyright notice and -: 16: * this permission notice appear in supporting documentation, and that -: 17: * the name of M.I.T. not be used in advertising or publicity pertaining -: 18: * to distribution of the software without specific, written prior -: 19: * permission. Furthermore if you modify this software you must label -: 20: * your software as modified software and not distribute it in such a -: 21: * fashion that it might be confused with the original M.I.T. software. -: 22: * M.I.T. makes no representations about the suitability of -: 23: * this software for any purpose. It is provided "as is" without express -: 24: * or implied warranty. -: 25: */ -: 26: -: 27:#include "k5-int.h" -: 28: -: 29:#include "fake-addrinfo.h" -: 30: -: 31:krb5_error_code #####: 32:krb5_os_hostaddr(krb5_context context, const char *name, -: 33: krb5_address ***ret_addrs) -: 34:{ -: 35: krb5_error_code retval; -: 36: krb5_address **addrs; -: 37: int i, j, r; -: 38: struct addrinfo hints, *ai, *aip; -: 39: #####: 40: if (!name) #####: 41: return KRB5_ERR_BAD_HOSTNAME; -: 42: #####: 43: memset (&hints, 0, sizeof (hints)); #####: 44: hints.ai_flags = AI_NUMERICHOST | AI_ADDRCONFIG; -: 45: /* We don't care what kind at this point, really, but without -: 46: this, we can get back multiple sockaddrs per address, for -: 47: SOCK_DGRAM, SOCK_STREAM, and SOCK_RAW. I haven't checked if -: 48: that's what the spec indicates. */ #####: 49: hints.ai_socktype = SOCK_DGRAM; -: 50: #####: 51: r = getaddrinfo (name, 0, &hints, &ai); #####: 52: if (r && AI_NUMERICHOST != 0) { #####: 53: hints.ai_flags &= ~AI_NUMERICHOST; #####: 54: r = getaddrinfo (name, 0, &hints, &ai); -: 55: } #####: 56: if (r) #####: 57: return KRB5_ERR_BAD_HOSTNAME; -: 58: #####: 59: for (i = 0, aip = ai; aip; aip = aip->ai_next) { #####: 60: switch (aip->ai_addr->sa_family) { -: 61: case AF_INET: -: 62:#ifdef KRB5_USE_INET6 -: 63: case AF_INET6: -: 64:#endif #####: 65: i++; -: 66: default: -: 67: /* Ignore addresses of unknown families. */ -: 68: ; -: 69: } -: 70: } -: 71: #####: 72: addrs = malloc ((i+1) * sizeof(*addrs)); #####: 73: if (!addrs) #####: 74: return ENOMEM; -: 75: #####: 76: for (j = 0; j < i + 1; j++) #####: 77: addrs[j] = 0; -: 78: #####: 79: for (i = 0, aip = ai; aip; aip = aip->ai_next) { -: 80: void *ptr; -: 81: size_t addrlen; -: 82: int atype; -: 83: #####: 84: switch (aip->ai_addr->sa_family) { -: 85: case AF_INET: #####: 86: addrlen = sizeof (struct in_addr); #####: 87: ptr = &((struct sockaddr_in *)aip->ai_addr)->sin_addr; #####: 88: atype = ADDRTYPE_INET; #####: 89: break; -: 90:#ifdef KRB5_USE_INET6 -: 91: case AF_INET6: #####: 92: addrlen = sizeof (struct in6_addr); #####: 93: ptr = &((struct sockaddr_in6 *)aip->ai_addr)->sin6_addr; #####: 94: atype = ADDRTYPE_INET6; #####: 95: break; -: 96:#endif -: 97: default: #####: 98: continue; -: 99: } #####: 100: addrs[i] = (krb5_address *) malloc(sizeof(krb5_address)); #####: 101: if (!addrs[i]) { #####: 102: retval = ENOMEM; #####: 103: goto errout; -: 104: } #####: 105: addrs[i]->magic = KV5M_ADDRESS; #####: 106: addrs[i]->addrtype = atype; #####: 107: addrs[i]->length = addrlen; #####: 108: addrs[i]->contents = malloc(addrs[i]->length); #####: 109: if (!addrs[i]->contents) { #####: 110: retval = ENOMEM; #####: 111: goto errout; -: 112: } #####: 113: memcpy (addrs[i]->contents, ptr, addrs[i]->length); #####: 114: i++; -: 115: } -: 116: #####: 117: *ret_addrs = addrs; #####: 118: if (ai) #####: 119: freeaddrinfo(ai); #####: 120: return 0; -: 121: -: 122:errout: #####: 123: if (addrs) { #####: 124: for (i = 0; addrs[i]; i++) { #####: 125: free (addrs[i]->contents); #####: 126: free (addrs[i]); -: 127: } #####: 128: krb5_free_addresses(context, addrs); -: 129: } #####: 130: if (ai) #####: 131: freeaddrinfo(ai); #####: 132: return retval; -: 133: -: 134:}