Back to index

courier  0.68.2
rfc1035sameip.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 #include      "config.h"
00006 #include      "rfc1035.h"
00007 #include      <sys/types.h>
00008 #include      <sys/socket.h>
00009 #include      <arpa/inet.h>
00010 #include      <errno.h>
00011 #include      <string.h>
00012 
00013 
00014 /*
00015 **     We have two socket addresses.  Did they come from the same IP
00016 **     address?
00017 */
00018 
00019 #if RFC1035_IPV6
00020 
00021 int rfc1035_same_ip(const void *a, int al, const void *b, int bl)
00022 {
00023 char   bufa[INET6_ADDRSTRLEN];
00024 char   bufb[INET6_ADDRSTRLEN];
00025 struct in6_addr in6a;
00026 struct in6_addr in6b;
00027 const char *as, *bs;
00028 
00029        if (rfc1035_sockaddrip(a, al, &in6a) ||
00030               rfc1035_sockaddrip(b, bl, &in6b) ||
00031               (as=inet_ntop(AF_INET6, &in6a, bufa, sizeof(bufa))) == 0 ||
00032               (bs=inet_ntop(AF_INET6, &in6b, bufb, sizeof(bufb))) == 0 ||
00033               strcmp(as, bs))
00034               return (0);
00035        return (1);
00036 }
00037 
00038 #else
00039 
00040 int rfc1035_same_ip(const void *a, int al, const void *b, int bl)
00041 {
00042        if ( ((const struct sockaddr_in *)a)->sin_family != AF_INET ||
00043               ((const struct sockaddr_in *)b)->sin_family != AF_INET ||
00044               al < sizeof(struct sockaddr_in) ||
00045               bl < sizeof(struct sockaddr_in))
00046        {
00047               return (0);
00048        }
00049 
00050        return ( ((const struct sockaddr_in *)a)->sin_addr.s_addr ==
00051               ((const struct sockaddr_in *)b)->sin_addr.s_addr);
00052 }
00053 
00054 #endif
00055