From patchwork Wed Sep 23 12:04:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 521672 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) by ozlabs.org (Postfix) with ESMTP id E3BDA140187 for ; Wed, 23 Sep 2015 22:05:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=hDmIBvT5; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 9139617C4C9; Wed, 23 Sep 2015 08:05:36 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OXhJRVKbwT8d; Wed, 23 Sep 2015 08:05:36 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 74C3217C4CB; Wed, 23 Sep 2015 08:04:47 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 827D517C4B6 for ; Wed, 23 Sep 2015 08:04:45 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aut-FWOO8kXn for ; Wed, 23 Sep 2015 08:04:40 -0400 (EDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com [209.85.215.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 8238E17C4B8 for ; Wed, 23 Sep 2015 08:04:35 -0400 (EDT) Received: by lacao8 with SMTP id ao8so24308912lac.3 for ; Wed, 23 Sep 2015 05:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wRh/sJt9TOroYQYhYuElZk/efIjozHaUxYejhE3G7P0=; b=hDmIBvT5xM9sQkTLe4amaqlNRoQO8Lve63l/dyFm9pBICI1umI/zJSt4OIywmGsAcq iMm/0AD34G+wMRnlUdybnyc5vKyMQyCyL3E+FxU/LyMODmetVmoS6hA/0aIg52k5DW0t iQTCZC5J64fm3vrnCMFknEO1tNfIY9yh3TvPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wRh/sJt9TOroYQYhYuElZk/efIjozHaUxYejhE3G7P0=; b=I9X3FZTHH392HN2eLzr9cFsStpWr176BdQGhn11Rd5CvP1izHH3S74RJXt/MHbBaZm U4/h8obb/XICJSLigZlNzKbT1F1pbP+ZPK+d+dNoxfONrVPxVR6MW0yTl8dtTy5/9mYf dUrjlN2zIkcs0wxOTAFwt1vkgVkb6n+Khoi5MNCJpzhcaxS2RjY+bsqnEgjChNGKyibR T+/EOrNRMWaGQ6IN3aD3+HUENnYNc9bNUzuIfSxKy1iV7DtfEGcO8QWvZj9oD2HJ7cJj H2FxFcI8xzM4D6feWZRKR05i4HQHdn9JoZp455NKxMVULLt3+k8wrcZzKcQZSDu5eTgW ysfg== X-Gm-Message-State: ALoCoQlnxk8RkXnNMD485QlCfYlyT9NvufC6A6SSNZx1WsdsDdI80gbMeiuReM7D74a8bCnmBqn661qpav/B/KYhq8BgixvvFY2lmca7DaBQ0UQvF3ZxzHL4HcC2g89lX0hGwERTqqZcP3iDjOBNeDcCdUkxYhL9dd9Mym8ZNWd3XF5GxF5dAuHpWHpUC4mgU4dNxuIOPkQM X-Received: by 10.152.180.171 with SMTP id dp11mr11221138lac.39.1443009873778; Wed, 23 Sep 2015 05:04:33 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id j8sm721294lah.46.2015.09.23.05.04.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Sep 2015 05:04:32 -0700 (PDT) From: Janusz Dziedzic To: hostap@lists.shmoo.com Subject: [PATCH 3/9] wpa_supplicant: add helper function sockaddr_compare Date: Wed, 23 Sep 2015 14:04:13 +0200 Message-Id: <1443009859-15327-4-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443009859-15327-1-git-send-email-janusz.dziedzic@tieto.com> References: <1443009859-15327-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com Cc: j@w1.fi X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com Kill not needed #ifdefs and use helper sockaddr_compare function. Signed-off-by: Janusz Dziedzic --- wpa_supplicant/ctrl_iface_udp.c | 52 +++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c index 26fb3aa..e219ff4 100644 --- a/wpa_supplicant/ctrl_iface_udp.c +++ b/wpa_supplicant/ctrl_iface_udp.c @@ -53,6 +53,39 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv, int level, const char *buf, size_t len); +static int sockaddr_compare(struct sockaddr *a, struct sockaddr *b) +{ + struct sockaddr_in *in_a, *in_b; + struct sockaddr_in6 *in6_a, *in6_b; + + if (a->sa_family != b->sa_family) + return 1; + + switch (a->sa_family) { + case AF_INET: + in_a = (struct sockaddr_in *) a; + in_b = (struct sockaddr_in *) b; + + if (in_a->sin_port != in_b->sin_port) + return 1; + if (in_a->sin_addr.s_addr != in_b->sin_addr.s_addr) + return 1; + break; + case AF_INET6: + in6_a = (struct sockaddr_in6 *) a; + in6_b = (struct sockaddr_in6 *) b; + + if (in6_a->sin6_port != in6_b->sin6_port) + return 1; + if (os_memcmp(&in6_a->sin6_addr, &in6_b->sin6_addr, sizeof(in6_a->sin6_addr))) + return 1; + break; + default: + return 1; + } + + return 0; +} static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv, #ifdef CONFIG_CTRL_IFACE_UDP_IPV6 @@ -100,15 +133,7 @@ static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv, dst = priv->ctrl_dst; while (dst) { -#ifdef CONFIG_CTRL_IFACE_UDP_IPV6 - if (from->sin6_port == dst->addr.sin6_port && - !os_memcmp(&from->sin6_addr, &dst->addr.sin6_addr, - sizeof(from->sin6_addr))) { -#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */ - if (from->sin_addr.s_addr == dst->addr.sin_addr.s_addr && - from->sin_port == dst->addr.sin_port) { -#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */ - + if (!sockaddr_compare((struct sockaddr *) from, (struct sockaddr *) &dst->addr)) { getnameinfo((struct sockaddr *) from, fromlen, host, sizeof(host), service, sizeof(service), @@ -148,14 +173,7 @@ static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv, dst = priv->ctrl_dst; while (dst) { -#if CONFIG_CTRL_IFACE_UDP_IPV6 - if (from->sin6_port == dst->addr.sin6_port && - !os_memcmp(&from->sin6_addr, &dst->addr.sin6_addr, - sizeof(from->sin6_addr))) { -#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */ - if (from->sin_addr.s_addr == dst->addr.sin_addr.s_addr && - from->sin_port == dst->addr.sin_port) { -#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */ + if (!sockaddr_compare((struct sockaddr *) from, (struct sockaddr *) &dst->addr)) { getnameinfo((struct sockaddr *) from, fromlen, host, sizeof(host), service, sizeof(service),