diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 772006b9d5767774be0ff5180a231b94faf1cca6..c9b9565040b6deaafeb675176dbb1d62d7694068 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -380,6 +380,57 @@ DWORD getICMPStats(MIB_ICMP *stats)
 
 DWORD getIPStats(PMIB_IPSTATS stats)
 {
+#if defined(HAVE_SYS_SYSCTL_H) && defined(IPCTL_STATS)
+  int mib[] = {CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS};
+#define MIB_LEN (sizeof(mib) / sizeof(mib[0]))
+  int ip_ttl, ip_forwarding;
+  struct ipstat ip_stat;
+  size_t needed;
+
+  if (!stats)
+      return ERROR_INVALID_PARAMETER;
+
+  needed = sizeof(ip_stat);
+  if(sysctl(mib, MIB_LEN, &ip_stat, &needed, NULL, 0) == -1)
+  {
+      ERR ("failed to get ipstat\n");
+      return ERROR_NOT_SUPPORTED;
+  }
+
+  needed = sizeof(ip_ttl);
+  if (sysctlbyname ("net.inet.ip.ttl", &ip_ttl, &needed, NULL, 0) == -1)
+  {
+      ERR ("failed to get ip Default TTL\n");
+      return ERROR_NOT_SUPPORTED;
+  }
+
+  needed = sizeof(ip_forwarding);
+  if (sysctlbyname ("net.inet.ip.forwarding", &ip_forwarding, &needed, NULL, 0) == -1)
+  {
+      ERR ("failed to get ip forwarding\n");
+      return ERROR_NOT_SUPPORTED;
+  }
+
+  stats->dwForwarding = ip_forwarding;
+  stats->dwDefaultTTL = ip_ttl;
+  stats->dwInDelivers = ip_stat.ips_delivered;
+  stats->dwInHdrErrors = ip_stat.ips_badhlen + ip_stat.ips_badsum + ip_stat.ips_tooshort + ip_stat.ips_badlen;
+  stats->dwInAddrErrors = ip_stat.ips_cantforward;
+  stats->dwInReceives = ip_stat.ips_total;
+  stats->dwForwDatagrams = ip_stat.ips_forward;
+  stats->dwInUnknownProtos = ip_stat.ips_noproto;
+  stats->dwInDiscards = ip_stat.ips_fragdropped;
+  stats->dwOutDiscards = ip_stat.ips_odropped;
+  stats->dwReasmOks = ip_stat.ips_reassembled;
+  stats->dwFragOks = ip_stat.ips_fragmented;
+  stats->dwFragFails = ip_stat.ips_cantfrag;
+  stats->dwReasmTimeout = ip_stat.ips_fragtimeout;
+  stats->dwOutNoRoutes = ip_stat.ips_noroute;
+  stats->dwOutRequests = ip_stat.ips_localout;
+  stats->dwReasmReqds = ip_stat.ips_fragments;
+
+  return NO_ERROR;
+#else
   FILE *fp;
 
   if (!stats)
@@ -493,6 +544,7 @@ DWORD getIPStats(PMIB_IPSTATS stats)
   }
 
   return NO_ERROR;
+#endif
 }
 
 DWORD getTCPStats(MIB_TCPSTATS *stats)