]> git.cameronkatri.com Git - apple_cmds.git/commitdiff
network_cmds: Fix compilation for lower targets
authorCameron Katri <me@cameronkatri.com>
Sun, 23 May 2021 15:50:26 +0000 (11:50 -0400)
committerCameron Katri <me@cameronkatri.com>
Sun, 23 May 2021 15:50:26 +0000 (11:50 -0400)
network_cmds/Makefile
network_cmds/ifconfig.tproj/if6lowpan.c
network_cmds/ifconfig.tproj/ifbridge.c
network_cmds/ifconfig.tproj/ifconfig.c
network_cmds/ifconfig.tproj/ifmedia.c
network_cmds/ifconfig.tproj/nexus.c
network_cmds/ndp.tproj/ndp.c

index 4d21c8ef7fa786a747139377582eb5fde7bf4cf5..296ddb466e543a0eb853a1824b7cc7a2f8502b84 100644 (file)
@@ -10,7 +10,6 @@ SUBDIR=       arp.tproj \
        mptcp_client \
        mtest.tproj \
        ndp.tproj \
-       netstat.tproj \
        ping.tproj \
        ping6.tproj \
        pktapctl \
@@ -23,4 +22,13 @@ SUBDIR=      arp.tproj \
        traceroute.tproj \
        traceroute6.tproj
 
+.if !defined(MK_NETSTAT)
+MK_NETSTAT=no
+.endif
+
+# netstat doesnt build on iOS 12, if building for higher set MK_NETSTAT to yes
+.if ${MK_NETSTAT} == "yes"
+SUBDIR+=       netstat.tproj
+.endif
+
 .include <bsd.subdir.mk>
index f0f4b2e5723dbcbdaea7458da7c15ce0ba67347e..ee638965326b352ae63e4ebab7190859177475bc 100644 (file)
@@ -58,6 +58,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -176,3 +177,4 @@ sixlowpan_ctor(void)
        callback_register(sixlowpan_clone_cb, NULL);
 #undef N
 }
+#endif
index 951c56bd4661c3a448bb0cef385aa56a1be8981a..19ce8fffd6203ab7472660d0deb5f6053573b577 100644 (file)
@@ -300,6 +300,7 @@ bridge_addresses(int s, const char *prefix)
 }
 
 #define MAX_IPv6_STR_LEN       INET6_ADDRSTRLEN
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 static void
 bridge_mac_nat(int s, const char *prefix)
 {
@@ -348,6 +349,7 @@ bridge_mac_nat(int s, const char *prefix)
        }
        free(buf);
 }
+#endif
 
 static void
 bridge_status(int s)
@@ -399,7 +401,9 @@ bridge_status(int s)
        if (!all || verbose > 1) {
                printf("\tAddress cache:\n");
                bridge_addresses(s, "\t\t");
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
                bridge_mac_nat(s, "\t\t");
+#endif
        }
        return;
 
@@ -865,6 +869,7 @@ unsetbridge_hostfilter(const char *ifn, int d, int s, const struct afswtch *afp)
                err(1, "BRDGSHOSTFILTER");
 }
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 static void
 setbridge_macnat(const char *val, int d, int s, const struct afswtch *afp)
 {
@@ -878,6 +883,7 @@ unsetbridge_macnat(const char *val, int d, int s, const struct afswtch *afp)
 
        do_bridgeflag(s, val, IFBIF_MAC_NAT,  0);
 }
+#endif
 
 static struct cmd bridge_cmds[] = {
        DEF_CMD_ARG("addm",             setbridge_add),
@@ -930,8 +936,10 @@ static struct cmd bridge_cmds[] = {
 #endif
         DEF_CMD_ARG2("hostfilter",     setbridge_hostfilter),
         DEF_CMD_ARG("-hostfilter",     unsetbridge_hostfilter),
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
        DEF_CMD_ARG("macnat",           setbridge_macnat),
        DEF_CMD_ARG("-macnat",          unsetbridge_macnat),
+#endif
 };
 static struct afswtch af_bridge = {
        .af_name        = "af_bridge",
index 3449301dab642809d9ea0784244e72dbe47cd812..3acc59cf3980a3f206bc52bf4629a9138db0a2ff 100644 (file)
@@ -109,6 +109,10 @@ __unused static const char copyright[] =
 #include <TargetConditionals.h>
 #endif
 
+#ifndef IF_NETEM_PARAMS_PSCALE
+#define IF_NETEM_PARAMS_PSCALE 100000
+#endif
+
 /*
  * Since "struct ifreq" is composed of various union members, callers
  * should pay special attention to interprete the value.
@@ -935,6 +939,7 @@ settbr(const char *val, int dummy __unused, int s, const struct afswtch *afp)
        }
 }
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 static int
 get_int64(uint64_t *i, char const *s)
 {
@@ -1255,6 +1260,7 @@ bad_args:
                        "\t\tnetem\n\n");
        return (-1);
 }
+#endif
 
 static void
 setthrottle(const char *val, int dummy __unused, int s,
@@ -1363,6 +1369,7 @@ setconstrained(const char *vname, int value, int s, const struct afswtch *afp)
 }
 #endif
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 static void
 setifmpklog(const char *vname, int value, int s, const struct afswtch *afp)
 {
@@ -1372,6 +1379,7 @@ setifmpklog(const char *vname, int value, int s, const struct afswtch *afp)
        if (ioctl(s, SIOCSIFMPKLOG, (caddr_t)&ifr) < 0)
                Perror(vname);
 }
+#endif
 
 void
 settimestamp(const char *vname, int value, int s, const struct afswtch *afp)
@@ -1441,8 +1449,10 @@ setqosmarking(const char *cmd, const char *arg, int s, const struct afswtch *afp
                
                if (strcmp(arg, "fastlane") == 0)
                        ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_FASTLANE;
+#if defined(IFRTYPE_QOSMARKING_RFC4594)
         else if (strcmp(arg, "rfc4594") == 0)
             ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_RFC4594;
+#endif
                else if (strcasecmp(arg, "none") == 0 || strcasecmp(arg, "off") == 0)
                        ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_MODE_NONE;
                else
@@ -1567,6 +1577,7 @@ setlowpowermode(const char *vname, int value, int s, const struct afswtch *afp)
                Perror(vname);
 }
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
 struct str2num {
        const char *str;
        uint32_t num;
@@ -1633,6 +1644,7 @@ setifavailability(const char *vname, int value, int s, const struct afswtch *afp
        if (ioctl(s, SIOCSIFINTERFACESTATE, (caddr_t)&ifr) < 0)
                warn("ioctl(SIOCSIFINTERFACESTATE)");
 }
+#endif
 
 static void
 show_routermode(int s)
@@ -1750,11 +1762,13 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                putchar('\n');
        }
 
+#if defined(SIOCGIFXFLAGS)
        if (verbose && ioctl(s, SIOCGIFXFLAGS, (caddr_t)&ifr) != -1 &&
            (xflags = ifr.ifr_xflags) != 0) {
                printb("\txflags", xflags, IFXFBITS);
                putchar('\n');
        }
+#endif
 
        if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
                if (ifr.ifr_curcap != 0) {
@@ -2116,9 +2130,11 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                                case IFRTYPE_QOSMARKING_FASTLANE:
                                        printf("fastlane\n");
                                        break;
+#if defined(IFRTYPE_QOSMARKING_RFC4594)
                 case IFRTYPE_QOSMARKING_RFC4594:
                     printf("RFC4594\n");
                     break;
+#endif
                                case IFRTYPE_QOSMARKING_MODE_NONE:
                                        printf("none\n");
                                        break;
@@ -2134,10 +2150,12 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                printf("\tlow power mode: %s\n",
                       (ifr.ifr_low_power_mode != 0) ? "enabled" : "disabled");
        }
+#if defined(SIOCGIFMPKLOG)
        if (ioctl(s, SIOCGIFMPKLOG, &ifr) != -1) {
                printf("\tmulti layer packet logging (mpklog): %s\n",
                       (ifr.ifr_mpk_log != 0) ? "enabled" : "disabled");
        }
+#endif
        show_routermode(s);
        show_routermode6();
 
@@ -2424,8 +2442,10 @@ static struct cmd basic_cmds[] = {
        DEF_CMD("monitor",      IFF_MONITOR:,   setifflags),
        DEF_CMD("-monitor",     -IFF_MONITOR,   setifflags),
 #endif /* IFF_MONITOR */
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
        DEF_CMD("mpklog",       1,              setifmpklog),
        DEF_CMD("-mpklog",      0,              setifmpklog),
+#endif
 #ifdef IFF_STATICARP
        DEF_CMD("staticarp",    IFF_STATICARP,  setifflags),
        DEF_CMD("-staticarp",   -IFF_STATICARP, setifflags),
@@ -2486,7 +2506,9 @@ static struct cmd basic_cmds[] = {
        DEF_CMD_VA("routermode",                routermode),
        DEF_CMD_ARG("desc",                     setifdesc),
        DEF_CMD_ARG("tbr",                      settbr),
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
        DEF_CMD_VA("netem",                     setnetem),
+#endif
        DEF_CMD_ARG("throttle",                 setthrottle),
        DEF_CMD_ARG("log",                      setlog),
        DEF_CMD("cl2k", 1,                      setcl2k),
@@ -2507,10 +2529,14 @@ static struct cmd basic_cmds[] = {
        DEF_CMD("-probe_connectivity",  0,              setprobeconnectivity),
        DEF_CMD("lowpowermode", 1,              setlowpowermode),
        DEF_CMD("-lowpowermode",        0,      setlowpowermode),
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
        DEF_CMD_ARG("subfamily",                setifsubfamily),
+#endif
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 135000
        DEF_CMD("available",    1,      setifavailability),
        DEF_CMD("-available",   0,      setifavailability),
        DEF_CMD("unavailable",  0,      setifavailability),
+#endif
 };
 
 static __constructor void
@@ -2604,6 +2630,7 @@ ift2str(unsigned int t, unsigned int f, unsigned int sf)
                c = "Cellular";
                break;
 
+#if defined(APPLE_IF_FAM_IPSEC)
        case IFT_OTHER:
                if (ifr.ifr_type.ift_family == APPLE_IF_FAM_IPSEC) {
                        if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_BLUETOOTH) {
@@ -2617,6 +2644,7 @@ ift2str(unsigned int t, unsigned int f, unsigned int sf)
                        }
                }
                break;
+#endif
 
        case IFT_BRIDGE:
        case IFT_PFLOG:
@@ -2681,9 +2709,11 @@ iffunct2str(u_int32_t functional_type)
                case IFRTYPE_FUNCTIONAL_INTCOPROC:
                        break;
 
+#if defined(IFRTYPE_FUNCTIONAL_COMPANIONLINK)
                case IFRTYPE_FUNCTIONAL_COMPANIONLINK:
                        str = "companionlink";
                        break;
+#endif
 
                default:
                        break;
index 713c13693610bcd7969db67b7b9bc904758d2116..4f9ade189291ad3db2dd929acec150919a83afa3 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+#ifndef SIOCGIFXMEDIA
+#define SIOCGIFXMEDIA SIOCGIFMEDIA
+#endif
+
 #include "ifconfig.h"
 
 static void    domediaopt(const char *, int, int);
index 3df98428399a6d4a067c135bb394e215c9d4acb1..3717c157f84d58039c193c022febdd39c0946386 100644 (file)
 
 #include "ifconfig.h"
 
+#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 135000
+#define flowswitch multistack
+#define ifnr_flowswitch ifnr_multistack
+#endif
+
 static void
 nexus_status(int s)
 {
index b485fa14612e3302a79edb783d6082d014dcdead..e3e51b8e89ebecc7b7942e672f9cd04555d9f94a 100644 (file)
@@ -443,7 +443,9 @@ set(int argc, char **argv)
                    !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
                case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
                        case IFT_ISO88024: case IFT_ISO88025:
+#if defined(IFT_6LOWPAN)
                        case IFT_6LOWPAN:
+#endif
                        goto overwrite;
                }
                /*