aboutsummaryrefslogtreecommitdiff
path: root/x11-wm/epplets/files/patch-epplets_net.c
blob: f964e7714ab35609d06561ff3b1cd40bbb34e8e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
--- epplets/net.c.orig	2012-09-30 11:38:35.000000000 +0200
+++ epplets/net.c	2012-10-10 14:56:21.000000000 +0200
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1999-2000, Michael Jennings
+ * 		 2008, Pietro Cerutti <gahr@FreeBSD.org> (FreeBSD adaptation)
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -38,6 +39,14 @@
 #ifdef linux
 #include <linux/version.h>
 #endif
+#ifdef __FreeBSD__
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <sys/sysctl.h>
+# include <sys/time.h>
+# include <net/if.h>
+# include <net/if_mib.h>
+#endif
 #include "epplet.h"
 #include "net.h"
 
@@ -86,6 +95,48 @@
      }
    fclose(fp);
    return (names);
+
+#elif defined(__FreeBSD__)
+
+   struct ifmibdata data;
+   int ifno_mib[5];
+   int fmib_mib[6];
+   int nof_rows, idx, row;
+   size_t len;
+
+   ifno_mib[0] = CTL_NET;
+   ifno_mib[1] = PF_LINK;
+   ifno_mib[2] = NETLINK_GENERIC;
+   ifno_mib[3] = IFMIB_SYSTEM;
+   ifno_mib[4] = IFMIB_IFCOUNT;
+
+   fmib_mib[0] = CTL_NET;
+   fmib_mib[1] = PF_LINK;
+   fmib_mib[2] = NETLINK_GENERIC;
+   fmib_mib[3] = IFMIB_IFDATA;
+   fmib_mib[5] = IFDATA_GENERAL;
+
+   len = sizeof(nof_rows);
+
+   sysctl(ifno_mib, 5, &nof_rows, &len, NULL, 0);
+
+   len = sizeof(data);
+
+   for(row=1, idx=0; row <= nof_rows; row++) {
+      fmib_mib[4] = row;
+      if(sysctl(fmib_mib, 6, &data, &len, NULL, 0) && errno == ENOENT)
+         continue;
+      else  {
+         names = realloc(names, sizeof(char *) * ++idx);
+         names[idx-1] = strdup(data.ifmd_name);
+      }
+   }
+   names[idx] = NULL;
+
+   if(count) *count = idx;
+   return (names);
+
+
 #elif defined(__sun__)
    return ((char **)NULL);
 #else
@@ -107,6 +158,10 @@
    FILE               *fp;
    char                buff[256], *colon =
       NULL, dev[64], in_str[64], out_str[64];
+#elif defined(__FreeBSD__)
+   struct ifmibdata data;
+   int mib[6], ifno_mib[5], row, nof_ifaces;
+   size_t len;
 #endif
 
    if (!device)
@@ -173,6 +228,43 @@
      }
    fclose(fp);
    return ((match) ? (0) : (ENODEV));
+#elif defined(__FreeBSD__)
+   ifno_mib[0] = CTL_NET;
+   ifno_mib[1] = PF_LINK;
+   ifno_mib[2] = NETLINK_GENERIC;
+   ifno_mib[3] = IFMIB_SYSTEM;
+   ifno_mib[4] = IFMIB_IFCOUNT;
+
+   len = sizeof(nof_ifaces);
+
+   sysctl(ifno_mib, 5, &nof_ifaces, &len, NULL, 0);
+
+   mib[0] = CTL_NET;
+   mib[1] = PF_LINK;
+   mib[2] = NETLINK_GENERIC;
+   mib[3] = IFMIB_IFDATA;
+   mib[5] = IFDATA_GENERAL;
+   
+   len = sizeof(data);
+
+   for(row=1; row<=nof_ifaces; row++) {
+      mib[4] = row;
+
+      if(sysctl(mib, 6, &data, &len, NULL, 0) && errno == ENOENT)
+         continue;
+
+      if(strcmp(device, data.ifmd_name))
+         continue;
+
+      if(in_bytes)
+         *in_bytes = (double)data.ifmd_data.ifi_ibytes;
+      if(out_bytes)
+         *out_bytes = (double)data.ifmd_data.ifi_obytes;
+      return (0);
+   }
+
+   return (ENODEV);
+
 #else
    /* Unsupported platform. */
    if (in_bytes)