Ejemplo n.º 1
0
bool KInetSocketAddress::areEqualInet(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly)
{
    if(s1.family() != s2.family())
        return false;
    if((s1.size() < sizeof(sockaddr_in)) || (s2.size() < sizeof(sockaddr_in)))
        return false;

    struct sockaddr_in *sin1 = (sockaddr_in *)s1.address();
    struct sockaddr_in *sin2 = (sockaddr_in *)s2.address();

    if(coreOnly)
        return (memcmp(&sin1->sin_addr, &sin2->sin_addr, sizeof(struct in_addr)) == 0);
    else
        return (sin1->sin_port == sin2->sin_port) && (memcmp(&sin1->sin_addr, &sin2->sin_addr, sizeof(struct in_addr)) == 0);
}
Ejemplo n.º 2
0
bool KUnixSocketAddress::areEqualUnix(const KSocketAddress &s1, const KSocketAddress &s2, bool /* coreOnly */)
{
    if(s1.family() != s2.family())
        return false;

    if((s1.size() < MIN_SOCKADDR_LEN) || (s2.size() < MIN_SOCKADDR_LEN))
        return false;

    struct sockaddr_un *sun1 = (sockaddr_un *)s1.address();
    struct sockaddr_un *sun2 = (sockaddr_un *)s2.address();

    if(s1.size() == MIN_SOCKADDR_LEN && s2.size() == MIN_SOCKADDR_LEN)
        return true; // unnamed Unix sockets

    return (strcmp(sun1->sun_path, sun2->sun_path) == 0);
}
Ejemplo n.º 3
0
bool KInetSocketAddress::areEqualInet6(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly)
{
#ifdef AF_INET6
    if(s1.family() != s2.family())
        return false;

    if((s1.size() < sizeof(sockaddr_in6)) || (s2.size() < sizeof(sockaddr_in6)))
        return false;

    struct sockaddr_in6 *sin1 = (sockaddr_in6 *)s1.address();
    struct sockaddr_in6 *sin2 = (sockaddr_in6 *)s2.address();

    if(coreOnly)
        return (memcmp(&sin1->sin6_addr, &sin2->sin6_addr, sizeof(struct in6_addr)) == 0);
    else
        return (sin1->sin6_port == sin2->sin6_port) && (sin1->sin6_flowinfo == sin2->sin6_flowinfo) &&
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
               (sin1->sin6_scope_id == sin2->sin6_scope_id) &&
#endif
               (memcmp(&sin1->sin6_addr, &sin2->sin6_addr, sizeof(struct in6_addr)) == 0);
#else
    return false;
#endif
}