1 #pragma ident "%Z%%M% %I% %E% SMI" 2 /* 3 * lib/krb5/krb/addr_comp.c 4 * 5 * Copyright 1990 by the Massachusetts Institute of Technology. 6 * All Rights Reserved. 7 * 8 * Export of this software from the United States of America may 9 * require a specific license from the United States Government. 10 * It is the responsibility of any person or organization contemplating 11 * export to obtain such a license before exporting. 12 * 13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 14 * distribute this software and its documentation for any purpose and 15 * without fee is hereby granted, provided that the above copyright 16 * notice appear in all copies and that both that copyright notice and 17 * this permission notice appear in supporting documentation, and that 18 * the name of M.I.T. not be used in advertising or publicity pertaining 19 * to distribution of the software without specific, written prior 20 * permission. Furthermore if you modify this software you must label 21 * your software as modified software and not distribute it in such a 22 * fashion that it might be confused with the original M.I.T. software. 23 * M.I.T. makes no representations about the suitability of 24 * this software for any purpose. It is provided "as is" without express 25 * or implied warranty. 26 * 27 * 28 * krb5_address_compare() 29 */ 30 31 #include <k5-int.h> 32 33 #ifdef KRB5_DEBUG 34 #include <sys/types.h> 35 #include <sys/socket.h> 36 #include <netinet/in.h> 37 #include <arpa/inet.h> 38 #endif 39 40 /* 41 * If the two addresses are the same, return TRUE, else return FALSE 42 */ 43 /*ARGSUSED*/ 44 krb5_boolean KRB5_CALLCONV 45 krb5_address_compare(krb5_context context, krb5_const krb5_address *addr1, 46 krb5_const krb5_address *addr2) 47 { 48 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() start"); 49 50 #ifdef KRB5_DEBUG 51 { 52 char buf[256]; 53 sa_family_t addr_fam; 54 55 switch (addr1->addrtype) { 56 case ADDRTYPE_INET: 57 addr_fam = AF_INET; 58 break; 59 case ADDRTYPE_INET6: 60 addr_fam = AF_INET6; 61 break; 62 } 63 inet_ntop(addr_fam, addr1->contents, buf, sizeof(buf)); 64 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1=%s", buf); 65 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 type=%d", 66 addr1->addrtype); 67 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 length=%d", 68 addr1->length); 69 70 switch (addr2->addrtype) { 71 case ADDRTYPE_INET: 72 addr_fam = AF_INET; 73 break; 74 case ADDRTYPE_INET6: 75 addr_fam = AF_INET6; 76 break; 77 } 78 inet_ntop(addr_fam, addr2->contents, buf, sizeof(buf)); 79 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2=%s", buf); 80 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 type=%d", 81 addr2->addrtype); 82 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 length=%d", 83 addr2->length); 84 } 85 #endif /* KRB5_DEBUG */ 86 87 if (addr1->addrtype != addr2->addrtype){ 88 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 89 " (addrtype mismatch)"); 90 return(FALSE); 91 } 92 93 if (addr1->length != addr2->length){ 94 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 95 " (length mismatch)"); 96 return(FALSE); 97 } 98 if (memcmp((char *)addr1->contents, (char *)addr2->contents, 99 addr1->length)){ 100 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 101 " (contents mismatch)"); 102 return FALSE; 103 } 104 else { 105 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end TRUE"); 106 return TRUE; 107 } 108 } 109