3
* Copyright (C) 2000 Henry Spencer.
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Library General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or (at your
8
* option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
10
* This library is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
* License for more details.
15
* RCSID $Id: anyaddr.c,v 1.7.6.1 2004/03/21 05:23:31 mcr Exp $
20
/* these are mostly fallbacks for the no-IPv6-support-in-library case */
21
#ifndef IN6ADDR_ANY_INIT
22
#define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
24
#ifndef IN6ADDR_LOOPBACK_INIT
25
#define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
28
static struct in6_addr v6any = IN6ADDR_ANY_INIT;
29
static struct in6_addr v6loop = IN6ADDR_LOOPBACK_INIT;
32
- anyaddr - initialize to the any-address value
34
err_t /* NULL for success, else string literal */
36
int af; /* address family */
39
uint32_t v4any = htonl(INADDR_ANY);
43
return initaddr((unsigned char *)&v4any, sizeof(v4any), af, dst);
46
return initaddr((unsigned char *)&v6any, sizeof(v6any), af, dst);
49
return "unknown address family in anyaddr/unspecaddr";
55
- unspecaddr - initialize to the unspecified-address value
57
err_t /* NULL for success, else string literal */
59
int af; /* address family */
62
return anyaddr(af, dst);
66
- loopbackaddr - initialize to the loopback-address value
68
err_t /* NULL for success, else string literal */
70
int af; /* address family */
73
uint32_t v4loop = htonl(INADDR_LOOPBACK);
77
return initaddr((unsigned char *)&v4loop, sizeof(v4loop), af, dst);
80
return initaddr((unsigned char *)&v6loop, sizeof(v6loop), af, dst);
83
return "unknown address family in loopbackaddr";
89
- isanyaddr - test for the any-address value
93
const ip_address *src;
95
uint32_t v4any = htonl(INADDR_ANY);
98
switch (src->u.v4.sin_family) {
100
cmp = memcmp(&src->u.v4.sin_addr.s_addr, &v4any, sizeof(v4any));
103
cmp = memcmp(&src->u.v6.sin6_addr, &v6any, sizeof(v6any));
110
return (cmp == 0) ? 1 : 0;
114
- isunspecaddr - test for the unspecified-address value
118
const ip_address *src;
120
return isanyaddr(src);
124
- isloopbackaddr - test for the loopback-address value
128
const ip_address *src;
130
uint32_t v4loop = htonl(INADDR_LOOPBACK);
133
switch (src->u.v4.sin_family) {
135
cmp = memcmp(&src->u.v4.sin_addr.s_addr, &v4loop, sizeof(v4loop));
138
cmp = memcmp(&src->u.v6.sin6_addr, &v6loop, sizeof(v6loop));
145
return (cmp == 0) ? 1 : 0;