summaryrefslogtreecommitdiff
path: root/net/wmnd/files/patch-src::drivers.c
blob: e2bf6e9155ec3f9fa0cdc7cb538c9ce777f8574f (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
--- src/drivers.c.orig	Tue May 22 11:11:25 2001
+++ src/drivers.c	Thu Nov 29 16:29:44 2001
@@ -17,6 +17,117 @@
  * *_term: deallocate name, eventually drvdata and close fds
  */
 
+#ifdef USE_FREEBSD_SYSCTL
+
+/* functions prototypes */
+int freebsd_dev_list(const char *devname, struct Devices *list) {
+    char *devn;
+    struct Devices *ndev;
+    int mib[5], len;
+  int i;
+  struct ifmibdata ifmd; 
+  
+  mib[0]=CTL_NET;
+  mib[1]=PF_LINK;
+  mib[2]=NETLINK_GENERIC;
+  mib[3]=IFMIB_SYSTEM;
+  mib[4]=IFMIB_IFCOUNT;
+
+  len=sizeof(int);
+
+  if (sysctl(mib, 5, &freebsd_interface_count, &len ,NULL, 0)==-1) {perror("systcl failed");exit(-1);}
+  printf("freebsd_interface_count: %d\n",freebsd_interface_count);
+
+    printf("devname: %s\n", devname);  
+    if (devname != NULL) {
+ 	// fill in the Devices structure
+	ndev=malloc(sizeof(struct Devices));
+	list->next=ndev;
+	// name of device
+	devn=strdup(devname);
+	ndev->name=devn;
+	// next Devices field used to create the chain
+	ndev->next=NULL;  
+	// internale driver data
+	ndev->drvdata=NULL;
+	// driver number
+	ndev->drvnum=0;
+	// status indicator (0 online, 1 offline)
+	ndev->online=0;
+	// device activity start
+	ndev->devstart=time(NULL);
+	// end of initialization
+	printf("freebsd_dev_list finished ok!!!\n");
+	return 1;
+    }
+    else { // we don't have a specific interface to monitor, so we must first retrieve the name of all available interfaces
+printf("any interface defined!\n");	
+  
+  len=sizeof(ifmd);
+  
+  for(i=1;i<=freebsd_interface_count;i++) {
+
+  
+    if (get_ifmib_general(i, &ifmd)==-1) {perror("sysctl2");exit(-1);}
+
+ 	// fill in the Devices structure
+	ndev=malloc(sizeof(struct Devices));
+	list->next=ndev;
+	// name of device
+	devn=strdup(ifmd.ifmd_name);
+	ndev->name=devn;
+	// next Devices field used to create the chain
+	ndev->next=NULL;  
+	// internale driver data
+	ndev->drvdata=NULL;
+	// driver number
+	ndev->drvnum=0;
+	// status indicator (0 online, 1 offline)
+	ndev->online=0;
+	// device activity start
+	ndev->devstart=time(NULL);
+	//update the list pointer
+	list=ndev;
+	// end of initialization
+  
+}
+	
+	return 1;
+    }
+}
+
+int freebsd_dev_init(struct Devices *dev) {
+  printf("nothing to do here!\n");
+    return 0;
+}
+
+int freebsd_dev_get(struct Devices *dev, unsigned long *ip, unsigned long *op, unsigned long *ib, unsigned long *ob) {
+  struct ifmibdata ifmd;
+  int i;
+for(i=1;i<=freebsd_interface_count;i++) {
+  if(get_ifmib_general(i, &ifmd)==-1) {perror("systcl3");exit(-1);}
+  //printf("comparing devname: %s with ifmdname: %s\n",dev->name, ifmd.ifmd_name);
+  if(strcmp(dev->name,ifmd.ifmd_name)==0) {
+    //printf("interface name: %s\n",ifmd.ifmd_name);
+    //printf("ipacktes: %ld opackets: %ld\n",ifmd.ifmd_data.ifi_ipackets,ifmd.ifmd_data.ifi_opackets);
+    //printf("ibytes: %ld obytes: %ld\n",ifmd.ifmd_data.ifi_ibytes,ifmd.ifmd_data.ifi_obytes);  
+    //printf("\n");
+    *ip=ifmd.ifmd_data.ifi_ipackets; *op=ifmd.ifmd_data.ifi_opackets;
+    *ib=ifmd.ifmd_data.ifi_ibytes; *ob=ifmd.ifmd_data.ifi_obytes;
+    return 0;
+  }
+} printf("interface %s not found!\n",dev->name); exit(-1); 
+    
+  return 0;
+}
+
+void freebsd_dev_term(struct Devices *dev) {
+      printf("freebsd_dev_term: %s\n",dev->name); 
+      //free(dev);
+}
+
+#endif /*USE_FREESD_SYSCTL*/
+
 #ifdef USE_SOLARIS_FPPPD
 
 /* strioclt is a support function, not previously declared */