*
* This file is part of Trivial IP Encryption (TrIPE).
*
- * TrIPE is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * TrIPE is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your
+ * option) any later version.
*
- * TrIPE is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * TrIPE is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
*
* You should have received a copy of the GNU General Public License
- * along with TrIPE; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
*/
/*----- Header files ------------------------------------------------------*/
* Returns: The hash of the address.
*/
-uint32 hash(const addr *a)
+static uint32 hash(const addr *a)
{
+ size_t i;
+ uint32 h;
+
switch (a->sa.sa_family) {
case AF_INET:
- return (U32((AF_INET * 0x4eaac1b7ul) +
- (a->sin.sin_addr.s_addr * 0xa5dbc837) +
- (a->sin.sin_port * 0x3b049e83)));
+ return (U32(0x4eaac1b7ul*AF_INET +
+ 0xa5dbc837ul*a->sin.sin_addr.s_addr +
+ 0x3b049e83ul*a->sin.sin_port));
+ case AF_INET6:
+ for (i = 0, h = 0; i < 16; i++)
+ h = 0x6bd26a67ul*h + a->sin6.sin6_addr.s6_addr[i];
+ return (U32(0x4eaac1b7ul*AF_INET6 +
+ 0xa5dbc837ul*h +
+ 0x1d94eab4ul*a->sin6.sin6_scope_id +
+ 0x3b049e83ul*a->sin6.sin6_port));
default:
abort();
}
* Returns: Nonzero if the addresses are equal.
*/
-int addreq(const addr *a, const addr *b)
+static int addreq(const addr *a, const addr *b)
{
if (a->sa.sa_family != b->sa.sa_family)
return (0);
case AF_INET:
return (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr &&
a->sin.sin_port == b->sin.sin_port);
+ case AF_INET6:
+ return (!memcmp(a->sin6.sin6_addr.s6_addr,
+ b->sin6.sin6_addr.s6_addr, 16) &&
+ a->sin6.sin6_port == b->sin6.sin6_port);
default:
abort();
}