File: osdep.c

package info (click to toggle)
aircrack-ng 1%3A1.6%2Bgit20210130.91820bc-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,056 kB
  • sloc: ansic: 67,045; cs: 5,392; sh: 3,773; python: 2,565; pascal: 1,074; asm: 570; makefile: 253; cpp: 46
file content (264 lines) | stat: -rw-r--r-- 5,242 bytes parent folder | download | duplicates (3)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
  *  Copyright (c) 2007, 2008, Andrea Bittau <a.bittau@cs.ucl.ac.uk>
  *
  *  OS dependent API.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "osdep.h"
#include "network.h"

extern struct wif * file_open(char * iface);

EXPORT int wi_read(struct wif * wi,
				   struct timespec * ts,
				   int * dlt,
				   unsigned char * h80211,
				   int len,
				   struct rx_info * ri)
{
	assert(wi->wi_read);
	return wi->wi_read(wi, ts, dlt, h80211, len, ri);
}

EXPORT int wi_write(struct wif * wi,
					struct timespec * ts,
					int dlt,
					unsigned char * h80211,
					int len,
					struct tx_info * ti)
{
	assert(wi->wi_write);
	return wi->wi_write(wi, ts, dlt, h80211, len, ti);
}

EXPORT int wi_set_ht_channel(struct wif * wi, int chan, unsigned int htval)
{
	assert(wi->wi_set_ht_channel);
	return wi->wi_set_ht_channel(wi, chan, htval);
}

EXPORT int wi_set_channel(struct wif * wi, int chan)
{
	assert(wi->wi_set_channel);
	return wi->wi_set_channel(wi, chan);
}

EXPORT int wi_get_channel(struct wif * wi)
{
	assert(wi->wi_get_channel);
	return wi->wi_get_channel(wi);
}

EXPORT int wi_set_freq(struct wif * wi, int freq)
{
	assert(wi->wi_set_freq);
	return wi->wi_set_freq(wi, freq);
}

EXPORT int wi_get_freq(struct wif * wi)
{
	assert(wi->wi_get_freq);
	return wi->wi_get_freq(wi);
}

EXPORT int wi_get_monitor(struct wif * wi)
{
	assert(wi->wi_get_monitor);
	return wi->wi_get_monitor(wi);
}

EXPORT char * wi_get_ifname(struct wif * wi) { return wi->wi_interface; }

EXPORT void wi_close(struct wif * wi)
{
	assert(wi->wi_close);
	wi->wi_close(wi);
}

EXPORT int wi_fd(struct wif * wi)
{
	assert(wi->wi_fd);
	return wi->wi_fd(wi);
}

struct wif * wi_alloc(int sz)
{
	struct wif * wi;
	void * priv;

	/* Allocate wif & private state */
	wi = malloc(sizeof(*wi));
	if (!wi) return NULL;
	memset(wi, 0, sizeof(*wi));

	priv = malloc(sz);
	if (!priv)
	{
		free(wi);
		return NULL;
	}
	memset(priv, 0, sz);
	wi->wi_priv = priv;

	return wi;
}

void * wi_priv(struct wif * wi) { return wi->wi_priv; }

EXPORT int wi_get_mac(struct wif * wi, unsigned char * mac)
{
	assert(wi->wi_get_mac);
	return wi->wi_get_mac(wi, mac);
}

EXPORT int wi_set_mac(struct wif * wi, unsigned char * mac)
{
	assert(wi->wi_set_mac);
	return wi->wi_set_mac(wi, mac);
}

EXPORT int wi_get_rate(struct wif * wi)
{
	assert(wi->wi_get_rate);
	return wi->wi_get_rate(wi);
}

EXPORT int wi_set_rate(struct wif * wi, int rate)
{
	assert(wi->wi_set_rate);
	return wi->wi_set_rate(wi, rate);
}

EXPORT int wi_get_mtu(struct wif * wi)
{
	assert(wi->wi_get_mtu);
	return wi->wi_get_mtu(wi);
}

EXPORT int wi_set_mtu(struct wif * wi, int mtu)
{
	assert(wi->wi_set_mtu);
	return wi->wi_set_mtu(wi, mtu);
}

EXPORT struct wif * wi_open(char * iface)
{
	struct wif * wi;

	if (iface == NULL || iface[0] == 0)
	{
		return NULL;
	}

	wi = file_open(iface);
	if (wi == (struct wif *) -1) return NULL;
	if (!wi) wi = net_open(iface);
	if (!wi) wi = wi_open_osdep(iface);
	if (!wi) return NULL;

	strncpy(wi->wi_interface, iface, sizeof(wi->wi_interface) - 1);
	wi->wi_interface[sizeof(wi->wi_interface) - 1] = 0;

	return wi;
}

/* tap stuff */
EXPORT char * ti_name(struct tif * ti)
{
	assert(ti->ti_name);
	return ti->ti_name(ti);
}

EXPORT int ti_set_mtu(struct tif * ti, int mtu)
{
	assert(ti->ti_set_mtu);
	return ti->ti_set_mtu(ti, mtu);
}

EXPORT int ti_get_mtu(struct tif * ti)
{
	assert(ti->ti_get_mtu);
	return ti->ti_get_mtu(ti);
}

EXPORT void ti_close(struct tif * ti)
{
	assert(ti->ti_close);
	ti->ti_close(ti);
}

EXPORT int ti_fd(struct tif * ti)
{
	assert(ti->ti_fd);
	return ti->ti_fd(ti);
}

EXPORT int ti_read(struct tif * ti, void * buf, int len)
{
	assert(ti->ti_read);
	return ti->ti_read(ti, buf, len);
}

EXPORT int ti_write(struct tif * ti, void * buf, int len)
{
	assert(ti->ti_write);
	return ti->ti_write(ti, buf, len);
}

EXPORT int ti_set_mac(struct tif * ti, unsigned char * mac)
{
	assert(ti->ti_set_mac);
	return ti->ti_set_mac(ti, mac);
}

EXPORT int ti_set_ip(struct tif * ti, struct in_addr * ip)
{
	assert(ti->ti_set_ip);
	return ti->ti_set_ip(ti, ip);
}

struct tif * ti_alloc(int sz)
{
	struct tif * ti;
	void * priv;

	/* Allocate tif & private state */
	ti = malloc(sizeof(*ti));
	if (!ti) return NULL;
	memset(ti, 0, sizeof(*ti));

	priv = malloc(sz);
	if (!priv)
	{
		free(ti);
		return NULL;
	}
	memset(priv, 0, sz);
	ti->ti_priv = priv;

	return ti;
}

void * ti_priv(struct tif * ti) { return ti->ti_priv; }