esac
# Special case
case "$OS" in
+ darwin*)
+ # Can't install /libexec
+ : ${PREFIX:=/usr/local}
+ ;;
dragonfly*)
# This means /usr HAS to be mounted not via dhcpcd
: ${LIBEXECDIR:=${PREFIX:-/usr}/libexec}
ALLOW_USR_LIBS=true
fi
case "$OS" in
-linux*|solaris*|sunos*|kfreebsd*|dragonfly*|freebsd*) ;;
+darwin*|linux*|solaris*|sunos*|kfreebsd*|dragonfly*|freebsd*) ;;
*)
# There might be more than one ...
for LDELFN in /libexec/ld-elf.so.[0-9]*; do
if [ -z "$PRIVSEP_USER" ]; then
printf "Detecting a suitable user for dhcpcd ... "
for x in _dhcpcd _dhcp dhcpcd; do
- home=$(getent passwd $x 2>/dev/null | cut -d: -f6)
- if [ -d "$home" ]; then
+ if id "$x" >/dev/null 2>&1; then
PRIVSEP_USER="$x"
break
fi
if $XCC _test.c -o _test >/dev/null 2>&3; then
[ -x _test ] && _CC=true
fi
-rm -f _test.c _test
+rm -rf _test.* _test
if ! $_CC; then
echo $XCC
echo "$CC does not create executables" >&2
else
echo "no"
fi
- rm -f _capsicum.c _capsicum
+ rm -rf _capsicum.* _capsicum
printf "Testing for pledge ... "
cat <<EOF >_pledge.c
else
echo "no"
fi
- rm -f _pledge.c _pledge
+ rm -rf _pledge.* _pledge
fi
# This block needs to be after the compiler test due to embedded quotes.
echo "no"
echo "DHCPCD_SRCS+= if-linux-wext.c" >>$CONFIG_MK
fi
- rm -f _nl80211.c _nl80211
+ rm -rf _nl80211.* _nl80211
printf "Testing for IN6_ADDR_GEN_MODE_NONE ... "
cat <<EOF >_IN6_ADDR_GEN_MODE_NONE.c
else
echo "no"
fi
- rm -f _IN6_ADDR_GEN_MODE_NONE.c _IN6_ADDR_GEN_MODE_NONE
+ rm -rf _IN6_ADDR_GEN_MODE_NONE.* _IN6_ADDR_GEN_MODE_NONE
else
printf "Testing for ifam_pid ... "
cat <<EOF >_ifam_pid.c
else
echo "no"
fi
- rm -f _ifam_pid.c _ifam_pid
+ rm -rf _ifam_pid.* _ifam_pid
printf "Testing for ifam_addrflags ... "
cat <<EOF >_ifam_addrflags.c
else
echo "no"
fi
- rm -f _ifam_addrflags.c _ifam_addrflags
+ rm -rf _ifam_addrflags.* _ifam_addrflags
fi
abort=false
echo "libc support for getifaddrs is required - aborting" >&2
abort=true
fi
-rm -f _getifaddrs.c _getifaddrs
+rm -rf _getifaddrs.* _getifaddrs
$abort && exit 1
printf "Testing for ifaddrs.ifa_addrflags ... "
else
echo "no"
fi
-rm -f _getifaddrs_addrflags.c _getifaddrs_addrflags
+rm -rf _getifaddrs_addrflags.* _getifaddrs_addrflags
printf "Testing for clock_gettime ... "
cat <<EOF >_clock_gettime.c
echo "libc support for clock_getttime is required - aborting" >&2
abort=true
fi
-rm -f _clock_gettime.c _clock_gettime
+rm -rf _clock_gettime.* _clock_gettime
$abort && exit 1
if [ -z "$CLOSEFROM" ]; then
fi
echo "$CLOSEFROM"
fi
-rm -f _closefrom.c _closefrom
+rm -rf _closefrom.* _closefrom
if [ "$CLOSEFROM" = no ]; then
echo "COMPAT_SRCS+= compat/closefrom.c" >>$CONFIG_MK
echo "#include \"compat/closefrom.h\"" >>$CONFIG_H
if [ "$IOCTL_REQ" != "unsigned long" ]; then
echo "#define IOCTL_REQUEST_TYPE $IOCTL_REQ" >>$CONFIG_H
fi
-rm -f _ioctl.c _ioctl
+rm -rf _ioctl.* _ioctl
printf "Testing for inet_ntoa ... "
cat <<EOF >_inet_ntoa.c
echo "libc support for inet_ntoa is required - aborting" >&2
abort=true
fi
-rm -f _inet_ntoa.c _inet_ntoa
+rm -rf _inet_ntoa.* _inet_ntoa
$abort && exit 1
if [ -z "$ARC4RANDOM" ]; then
ARC4RANDOM=no
fi
echo "$ARC4RANDOM"
- rm -f _arc4random.c _arc4random
+ rm -rf _arc4random.* _arc4random
fi
if [ "$ARC4RANDOM" = no ]; then
echo "COMPAT_SRCS+= compat/arc4random.c" >>$CONFIG_MK
ARC4RANDOM_UNIFORM=no
fi
echo "$ARC4RANDOM_UNIFORM"
- rm -f _arc4random_uniform.c _arc4random_uniform
+ rm -rf _arc4random_uniform.* _arc4random_uniform
fi
if [ "$ARC4RANDOM_UNIFORM" = no ]; then
echo "COMPAT_SRCS+= compat/arc4random_uniform.c" >>$CONFIG_MK
MEMSET_EXPLICIT=no
fi
echo "$MEMSET_EXPLICIT"
- rm -f _memset_explicit.c _memset_explicit
+ rm -rf _memset_explicit.* _memset_explicit
fi
if [ "$MEMSET_EXPLICIT" = yes ]; then
echo "#define HAVE_MEMSET_EXPLICIT" >>$CONFIG_H
EXPLICIT_BZERO=no
fi
echo "$EXPLICIT_BZERO"
- rm -f _explicit_bzero.c _explicit_bzero
+ rm -rf _explicit_bzero.* _explicit_bzero
fi
if [ "$EXPLICIT_BZERO" = yes ]; then
echo "#define HAVE_EXPLICIT_BZERO" >>$CONFIG_H
MEMSET_S=no
fi
echo "$MEMSET_S"
- rm -f _memset_s.c _memset_s
+ rm -rf _memset_s.* _memset_s
fi
if [ "$MEMSET_S" = yes ]; then
echo "#define __STDC_WANT_LIB_EXT1__ 1" >>$CONFIG_H
OPEN_MEMSTREAM=no
fi
echo "$OPEN_MEMSTREAM"
- rm -f _open_memstream.c _open_memstream
+ rm -rf _open_memstream.* _open_memstream
fi
if [ "$OPEN_MEMSTREAM" = yes ]; then
echo "#define HAVE_OPEN_MEMSTREAM" >>$CONFIG_H
PIDFILE_LOCK=no
fi
echo "$PIDFILE_LOCK"
- rm -f _pidfile.c _pidfile
+ rm -rf _pidfile.* _pidfile
fi
if [ "$PIDFILE_LOCK" = no ]; then
echo "COMPAT_SRCS+= compat/pidfile.c" >>$CONFIG_MK
SETPROCTITLE=no
fi
echo "$SETPROCTITLE"
- rm -f _setproctitle.c _setproctitle
+ rm -rf _setproctitle.* _setproctitle
fi
if [ "$SETPROCTITLE" = no ]; then
case "$OS" in
- solaris*|sunos*)
+ darwin*|solaris*|sunos*)
echo "$OS has no support for setting process title"
echo "#define setproctitle(...)" >>$CONFIG_H
;;
echo "COMPAT_SRCS+= compat/setproctitle.c" >>$CONFIG_MK
echo "#include \"compat/setproctitle.h\"" \
>>$CONFIG_H
+ SETPROCTITLE=yes
;;
esac
fi
+if [ "$SETPROCTITLE" = yes ]; then
+ echo "#define HAVE_SETPROCTITLE" >>$CONFIG_H
+fi
if [ -z "$STRLCPY" ]; then
printf "Testing for strlcpy ... "
STRLCPY=no
fi
echo "$STRLCPY"
- rm -f _strlcpy.c _strlcpy
+ rm -rf _strlcpy.* _strlcpy
fi
if [ "$STRLCPY" = no ]; then
echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK
STRTOI=no
fi
echo "$STRTOI"
- rm -f _strtoi.c _strtoi
+ rm -rf _strtoi.* _strtoi
fi
if [ "$STRTOI" = no ]; then
echo "COMPAT_SRCS+= compat/strtoi.c compat/strtou.c" >>$CONFIG_MK
CONSTTIME_MEMEQUAL=no
fi
echo "$CONSTTIME_MEMEQUAL"
- rm -f _consttime_memequal.c _consttime_memequal
+ rm -rf _consttime_memequal.* _consttime_memequal
fi
if [ "$CONSTTIME_MEMEQUAL" = no ] && [ -z "$TIMINGSAFE_BCMP" ]; then
printf "Testing for timingsafe_bcmp ... "
TIMINGSAFE_BCMP=no
fi
echo "$TIMINGSAFE_BCMP"
- rm -f _timingsafe_bcmp.c _timingsafe_bcmp
+ rm -rf _timingsafe_bcmp.* _timingsafe_bcmp
fi
if [ "$CONSTTIME_MEMEQUAL" = no ]; then
DPRINTF=no
fi
echo "$DPRINTF"
- rm -f _dprintf.c _dprintf
+ rm -rf _dprintf.* _dprintf
fi
if [ "$DPRINTF" = no ]; then
echo "COMPAT_SRCS+= compat/dprintf.c" >>$CONFIG_MK
RBTREE=no
fi
echo "$RBTREE"
- rm -f _rbtree.c _rbtree
+ rm -rf _rbtree.* _rbtree
fi
if [ "$RBTREE" = no ]; then
echo "VENDOR_SRCS+= vendor/rbtree.c" >>$CONFIG_MK
REALLOCARRAY=no
fi
echo "$REALLOCARRAY"
- rm -f _reallocarray.c _reallocarray
+ rm -rf _reallocarray.* _reallocarray
fi
if [ "$REALLOCARRAY" = no ]; then
echo "COMPAT_SRCS+= compat/reallocarray.c" >>$CONFIG_MK
BE64ENC=no
fi
echo "$BE64ENC"
- rm -f _be64enc.c _be64enc
+ rm -rf _be64enc.* _be64enc
fi
if [ "$BE64ENC" = no ]; then
echo "#include \"compat/endian.h\"" >>$CONFIG_H
FLS64=no
fi
echo "$FLS64"
- rm -f _fls64.c _fls64
+ rm -rf _fls64.* _fls64
fi
if [ "$FLS64" = yes ]; then
echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H
MD5=no
fi
echo "$MD5"
- rm -f _md5.c _md5
+ rm -rf _md5.* _md5
fi
if [ -z "$SHA2_H" ]; then
SHA2=no
fi
echo "$SHA2"
- rm -f _sha256.c _sha256
+ rm -rf _sha256.* _sha256
if [ "$SHA2" = no ]; then
# Did OpenBSD really change this? grrrr
printf "Testing for SHA256Init ... "
SHA2=no
fi
echo "$SHA2"
- rm -f _sha256.c _sha256
+ rm -rf _sha256.* _sha256
fi
fi
fi
fi
echo "$HMAC"
- rm -f _hmac.c _hmac
+ rm -rf _hmac.* _hmac
fi
if [ "$OPENSSL" = yes ] ||
OPENSSL=no
fi
echo "$OPENSSL"
- rm -f _openssl.c _openssl
+ rm -rf _openssl.* _openssl
fi
if [ "$OPENSSL" = yes ]; then
SHA2_LIB=
SHA2_RENAMED=
echo "$SHA2"
- rm -f _openssl_sha.c _openssl_sha
+ rm -rf _openssl_sha.* _openssl_sha
fi
if [ "$LIBPCAP" = yes ]; then
echo "no"
abort=true
fi
- rm -f _libpcap.c libpcap
+ rm -rf _libpcap.* libpcap
$abort && exit 1
fi
echo "CFLAGS+= $LIBPCAP_CFLAGS" >>$CONFIG_MK
else
echo "no"
fi
- rm -f _libpcap_imm.c libpcap_imm
+ rm -rf _libpcap_imm.* libpcap_imm
printf "Testing for pcap_setwritefilter() ... "
cat <<EOF >_libpcap_write.c
else
echo "no"
fi
- rm -f _libpcap_write.c libpcap_write
+ rm -rf _libpcap_write.* libpcap_write
printf "Testing for pcap_lockfilter() ... "
cat <<EOF >_libpcap_lock.c
else
echo "no"
fi
- rm -f _libpcap_lock.c libpcap_lock
+ rm -rf _libpcap_lock.* libpcap_lock
fi
# Workaround for DragonFlyBSD import
echo "LIBUDEV_CPPFLAGS+= -DLIBUDEV_NOFILTER" >>$CONFIG_MK
echo "no"
fi
- rm -f _udev.c _udev
+ rm -rf _udev.* _udev
printf "Checking udev_device_get_is_initialized ... "
cat <<EOF >_udev.c
echo "LIBUDEV_CPPFLAGS+= -DLIBUDEV_NOINIT" >>$CONFIG_MK
echo "no"
fi
- rm -f _udev.c _udev
+ rm -rf _udev.* _udev
elif [ "$DEV" != no ] && [ "$UDEV" != no ] && [ -n "$UDEV" ]; then
echo "udev has been explicitly requested ... aborting" >&2
exit 1
echo "no"
echo "libc for dlopen is required - aborting"
fi
- rm -f _dlopen.c _dlopen
+ rm -rf _dlopen.* _dlopen
$abort && exit 1
fi
#include <arpa/inet.h>
#include "config.h"
+#include "src/dhcpcd.h"
#ifdef __NetBSD__
#include <net/if_vlanvar.h> /* Needs netinet/if_ether.h */
#elif defined(__DragonFly__)
#include <net/vlan/if_vlan_var.h>
+#elif defined(__APPLE__)
+/* Apple doesn't ship this in include/net ... */
+struct vlanreq {
+ char vlr_parent[IFNAMSIZ];
+ u_short vlr_tag;
+};
#else
#include <net/if_vlan_var.h>
#endif
#ifdef __DragonFly__
#include <netproto/802_11/ieee80211_ioctl.h>
-#else
+#elif !defined(__APPLE__)
#include <net80211/ieee80211.h>
#include <net80211/ieee80211_ioctl.h>
#endif
#include "sa.h"
#ifndef RT_ROUNDUP
+#ifdef __APPLE__
+#define RT_ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
+#else
#define RT_ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#endif
#define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
#endif
-
/* Ignore these interface names which look like ethernet but are virtual or
* just won't work without explicit configuration. */
static const char *const ifnames_ignore[] = { "bridge",
"fwe", /* Firewire */
"fwip", /* Firewire */
"tap", "vether", "xvif", /* XEN DOM0 -> guest interface */
+#ifdef __APPLE__
+ "ap", "awdl", "llw",
+#endif
NULL };
struct rtm {
ps_rights_limit_fd_sockopt(ctx->link_fd);
#endif
-#if defined(SIOCALIFADDR) && defined(IFLR_ACTIVE) /*NetBSD */
+#if (defined(SIOCALIFADDR) && defined(IFLR_ACTIVE))
priv->pf_link_fd = xsocket(PF_LINK, SOCK_DGRAM, 0);
if (priv->pf_link_fd == -1)
logerr("%s: socket(PF_LINK)", __func__);
int
if_carrier(struct interface *ifp, const void *ifadata)
{
+#ifdef LINK_STATE_UP
const struct if_data *ifi = ifadata;
/*
* support SIOCGIFMEDIA.
*/
assert(ifadata != NULL);
-
if (ifi->ifi_link_state >= LINK_STATE_UP)
return LINK_UP;
if (ifi->ifi_link_state == LINK_STATE_UNKNOWN) {
return LINK_UNKNOWN;
}
return LINK_DOWN;
+#elif defined(SIOCGIFXMEDIA)
+ struct dhcpcd_ctx *ctx = ifp->ctx;
+ struct ifmediareq ifmr = { .ifm_active = 0 };
+
+ UNUSED(ifadata);
+ strlcpy(ifmr.ifm_name, ifp->name, sizeof(ifmr.ifm_name));
+ if (ioctl(ctx->pf_inet_fd, SIOCGIFXMEDIA, &ifmr) == -1)
+ return LINK_UNKNOWN;
+ if (!(ifmr.ifm_status & IFM_AVALID))
+ return LINK_UNKNOWN;
+ return ifmr.ifm_status & IFM_ACTIVE ? LINK_UP : LINK_DOWN;
+#else
+#warning OS does not report interface link state
+ UNUSED(ifp);
+ UNUSED(ifadata);
+ return LINK_UNKNOWN;
+#endif
}
bool
}
}
#else
+#warning OS does not report interface SSID
+ UNUSED(ctx);
+ UNUSED(ifname);
+ UNUSED(ssid);
errno = ENOSYS;
#endif
return -1;
if (ifmr.ifm_status & IFM_AVALID &&
IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211) {
- if (if_getssid1(ctx, ifname, NULL) == -1)
+ if (if_getssid1(ctx, ifname, NULL) == -1 && errno != ENOSYS)
return 1;
}
return 0;
unsigned short
if_vlanid(const struct interface *ifp)
{
-#ifdef SIOCGETVLAN
+#if defined(SIOCGETVLAN)
struct vlanreq vlr = { .vlr_tag = 0 };
if (if_indirect_ioctl(ifp->ctx, ifp->name, SIOCGETVLAN, &vlr,
}
static int
-if_sysctl(struct dhcpcd_ctx *ctx, const int *name, u_int namelen, void *oldp,
+if_sysctl(struct dhcpcd_ctx *ctx, int *name, u_int namelen, void *oldp,
size_t *oldlenp, void *newp, size_t newlen)
{
#if defined(PRIVSEP) && defined(HAVE_CAPSICUM)
}
#endif
+#ifdef IFAN_ARRIVAL
static int
if_announce(struct dhcpcd_ctx *ctx, const struct if_announcemsghdr *ifan)
{
return 0;
}
+#endif
static int
if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm)