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 45 krb5_address_compare(context, addr1, addr2) 46 krb5_context context; 47 krb5_const krb5_address *addr1; 48 krb5_const krb5_address *addr2; 49 { 50 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() start"); 51 52 #ifdef KRB5_DEBUG 53 { 54 char buf[256]; 55 sa_family_t addr_fam; 56 57 switch (addr1->addrtype) { 58 case ADDRTYPE_INET: 59 addr_fam = AF_INET; 60 break; 61 case ADDRTYPE_INET6: 62 addr_fam = AF_INET6; 63 break; 64 } 65 inet_ntop(addr_fam, addr1->contents, buf, sizeof(buf)); 66 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1=%s", buf); 67 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 type=%d", 68 addr1->addrtype); 69 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 length=%d", 70 addr1->length); 71 72 switch (addr2->addrtype) { 73 case ADDRTYPE_INET: 74 addr_fam = AF_INET; 75 break; 76 case ADDRTYPE_INET6: 77 addr_fam = AF_INET6; 78 break; 79 } 80 inet_ntop(addr_fam, addr2->contents, buf, sizeof(buf)); 81 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2=%s", buf); 82 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 type=%d", 83 addr2->addrtype); 84 KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 length=%d", 85 addr2->length); 86 } 87 #endif /* KRB5_DEBUG */ 88 89 if (addr1->addrtype != addr2->addrtype){ 90 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 91 " (addrtype mismatch)"); 92 return(FALSE); 93 } 94 95 if (addr1->length != addr2->length){ 96 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 97 " (length mismatch)"); 98 return(FALSE); 99 } 100 if (memcmp((char *)addr1->contents, (char *)addr2->contents, 101 addr1->length)){ 102 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE" 103 " (contents mismatch)"); 104 return FALSE; 105 } 106 else { 107 KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end TRUE"); 108 return TRUE; 109 } 110 } 111