1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, |
---|
5 | * New Zealand. |
---|
6 | * |
---|
7 | * Authors: Daniel Lawson |
---|
8 | * Perry Lorier |
---|
9 | * Shane Alcock |
---|
10 | * |
---|
11 | * All rights reserved. |
---|
12 | * |
---|
13 | * This code has been developed by the University of Waikato WAND |
---|
14 | * research group. For further information please see http://www.wand.net.nz/ |
---|
15 | * |
---|
16 | * libtrace is free software; you can redistribute it and/or modify |
---|
17 | * it under the terms of the GNU General Public License as published by |
---|
18 | * the Free Software Foundation; either version 2 of the License, or |
---|
19 | * (at your option) any later version. |
---|
20 | * |
---|
21 | * libtrace is distributed in the hope that it will be useful, |
---|
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | * GNU General Public License for more details. |
---|
25 | * |
---|
26 | * You should have received a copy of the GNU General Public License |
---|
27 | * along with libtrace; if not, write to the Free Software |
---|
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
29 | * |
---|
30 | * $Id$ |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | #include "libtrace_int.h" |
---|
35 | #include "libtrace.h" |
---|
36 | #include "protocols.h" |
---|
37 | #include <assert.h> |
---|
38 | #include <stdlib.h> |
---|
39 | |
---|
40 | |
---|
41 | /* This file contains all the protocol decoding functions for layer 2 |
---|
42 | * (and 2.5) protocols. This includes functions for accessing MAC addresses. |
---|
43 | * |
---|
44 | * Supported protocols include (but are not limited to): |
---|
45 | * Ethernet |
---|
46 | * 802.11 |
---|
47 | * 802.1q (vlan) |
---|
48 | * MPLS |
---|
49 | * PPPoE |
---|
50 | * LLCSnap |
---|
51 | * ATM |
---|
52 | */ |
---|
53 | |
---|
54 | |
---|
55 | /* Returns the payload from 802.3 ethernet. Type optionally returned in |
---|
56 | * "type" in host byte order. This will return a vlan header. |
---|
57 | */ |
---|
58 | void *trace_get_payload_from_ethernet(void *ethernet, |
---|
59 | uint16_t *type, |
---|
60 | uint32_t *remaining) |
---|
61 | { |
---|
62 | libtrace_ether_t *eth = (libtrace_ether_t*)ethernet; |
---|
63 | |
---|
64 | if (remaining) { |
---|
65 | if (*remaining < sizeof(*eth)) { |
---|
66 | *remaining = 0; |
---|
67 | return NULL; |
---|
68 | } |
---|
69 | *remaining-=sizeof(*eth); |
---|
70 | } |
---|
71 | |
---|
72 | if (type) |
---|
73 | *type = ntohs(eth->ether_type); |
---|
74 | |
---|
75 | return (void*)((char *)eth + sizeof(*eth)); |
---|
76 | } |
---|
77 | |
---|
78 | /* Skip any 802.1q headers if necessary |
---|
79 | * type is now output only (why check it if we don't need to?) |
---|
80 | */ |
---|
81 | void *trace_get_payload_from_vlan(void *ethernet, uint16_t *type, |
---|
82 | uint32_t *remaining) |
---|
83 | { |
---|
84 | libtrace_8021q_t *vlanhdr = (libtrace_8021q_t *)ethernet; |
---|
85 | |
---|
86 | if (remaining) { |
---|
87 | if (*remaining < sizeof(libtrace_8021q_t)) { |
---|
88 | *remaining = 0; |
---|
89 | return NULL; |
---|
90 | } |
---|
91 | |
---|
92 | *remaining=*remaining-sizeof(libtrace_8021q_t); |
---|
93 | } |
---|
94 | |
---|
95 | if (type) |
---|
96 | *type = ntohs(vlanhdr->vlan_ether_type); |
---|
97 | |
---|
98 | return (void*)((char *)ethernet + sizeof(*vlanhdr)); |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | /* Skip any MPLS headers if necessary, guessing what the next type is |
---|
103 | * type is input/output. If the next type is "ethernet" this will |
---|
104 | * return a type of 0x0000. |
---|
105 | */ |
---|
106 | void *trace_get_payload_from_mpls(void *ethernet, uint16_t *type, |
---|
107 | uint32_t *remaining) |
---|
108 | { |
---|
109 | |
---|
110 | assert(type); |
---|
111 | if ((((char*)ethernet)[2]&0x01)==0) { |
---|
112 | /* The MPLS Stack bit is set */ |
---|
113 | *type = TRACE_ETHERTYPE_MPLS; |
---|
114 | } |
---|
115 | else { |
---|
116 | if (!remaining || *remaining>=5) { |
---|
117 | switch (((char*)ethernet)[4]&0xF0) { |
---|
118 | case 0x40: /* IPv4 */ |
---|
119 | *type = TRACE_ETHERTYPE_IP; |
---|
120 | break; |
---|
121 | case 0x60: /* IPv6 */ |
---|
122 | *type = TRACE_ETHERTYPE_IPV6; |
---|
123 | break; |
---|
124 | default: /* VPLS */ |
---|
125 | /* Ethernet */ |
---|
126 | *type = 0; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | ethernet=(char*)ethernet+4; |
---|
131 | if (remaining) { |
---|
132 | if (*remaining<4) |
---|
133 | return NULL; |
---|
134 | else |
---|
135 | *remaining-=4; |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | return ethernet; |
---|
140 | } |
---|
141 | |
---|
142 | static void *trace_get_payload_from_llcsnap(void *link, |
---|
143 | uint16_t *type, uint32_t *remaining) |
---|
144 | { |
---|
145 | /* 64 byte capture. */ |
---|
146 | libtrace_llcsnap_t *llc = (libtrace_llcsnap_t*)link; |
---|
147 | |
---|
148 | if (remaining) { |
---|
149 | if (*remaining < sizeof(libtrace_llcsnap_t)) { |
---|
150 | *remaining = 0; |
---|
151 | return NULL; |
---|
152 | } |
---|
153 | *remaining-=(sizeof(libtrace_llcsnap_t)); |
---|
154 | } |
---|
155 | |
---|
156 | llc = (libtrace_llcsnap_t*)((char *)llc); |
---|
157 | |
---|
158 | if (type) *type = ntohs(llc->type); |
---|
159 | |
---|
160 | return (void*)((char*)llc+sizeof(*llc)); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | static void *trace_get_payload_from_80211(void *link, uint16_t *type, uint32_t *remaining) |
---|
165 | { |
---|
166 | libtrace_80211_t *wifi; |
---|
167 | uint16_t *eth; /* ethertype */ |
---|
168 | int8_t extra = 0; /* how many QoS bytes to skip */ |
---|
169 | |
---|
170 | if (remaining && *remaining < sizeof(libtrace_80211_t)) { |
---|
171 | *remaining = 0; |
---|
172 | return NULL; |
---|
173 | } |
---|
174 | |
---|
175 | wifi=(libtrace_80211_t*)link; |
---|
176 | |
---|
177 | /* Data packet? */ |
---|
178 | if (wifi->type != 2) { |
---|
179 | return NULL; |
---|
180 | } |
---|
181 | |
---|
182 | /* If FromDS and ToDS are both set then we have a four-address |
---|
183 | * frame. Otherwise we have a three-address frame */ |
---|
184 | if (!(wifi->to_ds && wifi->from_ds)) |
---|
185 | extra -= 6; |
---|
186 | |
---|
187 | /* Indicates QoS field present, see IEEE802.11e-2005 pg 21 */ |
---|
188 | if (wifi->subtype & 0x8) |
---|
189 | extra += 2; |
---|
190 | |
---|
191 | if (remaining && *remaining < sizeof(*eth)) { |
---|
192 | *remaining = 0; |
---|
193 | return NULL; |
---|
194 | } |
---|
195 | |
---|
196 | eth=(uint16_t *)((char*)wifi+sizeof(*wifi)+extra); |
---|
197 | |
---|
198 | if (*eth == 0xaaaa) |
---|
199 | /* Payload contains an 802.2 LLC/SNAP frame */ |
---|
200 | return trace_get_payload_from_llcsnap((void *)eth, type, remaining); |
---|
201 | |
---|
202 | /* Otherwise we assume an Ethernet II frame */ |
---|
203 | if (type) *type=ntohs(*eth); |
---|
204 | if (remaining) *remaining = *remaining - sizeof(libtrace_80211_t) - extra - sizeof(*eth); |
---|
205 | |
---|
206 | return (void*)((char*)eth+sizeof(*eth)); |
---|
207 | } |
---|
208 | |
---|
209 | static void *trace_get_payload_from_ppp(void *link, |
---|
210 | uint16_t *type, uint32_t *remaining) |
---|
211 | { |
---|
212 | /* 64 byte capture. */ |
---|
213 | libtrace_ppp_t *ppp = (libtrace_ppp_t*)link; |
---|
214 | |
---|
215 | if (remaining) { |
---|
216 | if (*remaining < sizeof(libtrace_ppp_t)) { |
---|
217 | *remaining = 0; |
---|
218 | return NULL; |
---|
219 | } |
---|
220 | *remaining-=sizeof(libtrace_ppp_t); |
---|
221 | } |
---|
222 | |
---|
223 | if (type) { |
---|
224 | switch(ntohs(ppp->protocol)) { |
---|
225 | case 0x0021: *type = TRACE_ETHERTYPE_IP; break; |
---|
226 | /* If it isn't IP, then it is probably PPP control and |
---|
227 | * I can't imagine anyone caring about that too much |
---|
228 | */ |
---|
229 | default: *type = 0; break; |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | return (void*)((char *)ppp+sizeof(*ppp)); |
---|
235 | } |
---|
236 | |
---|
237 | void *trace_get_payload_from_pppoe(void *link, uint16_t *type, |
---|
238 | uint32_t *remaining) { |
---|
239 | assert(type); |
---|
240 | |
---|
241 | if (remaining) { |
---|
242 | if (*remaining < sizeof(libtrace_pppoe_t)) { |
---|
243 | *remaining = 0; |
---|
244 | return NULL; |
---|
245 | } |
---|
246 | *remaining -= sizeof(libtrace_pppoe_t); |
---|
247 | } |
---|
248 | |
---|
249 | /* PPPoE is always followed by PPP */ |
---|
250 | return trace_get_payload_from_ppp(link + sizeof(libtrace_pppoe_t), |
---|
251 | type, remaining); |
---|
252 | } |
---|
253 | |
---|
254 | /* Header for CHDLC framing */ |
---|
255 | typedef struct libtrace_chdlc_t { |
---|
256 | uint8_t address; /** 0xF0 for unicast, 0xF8 for multicast */ |
---|
257 | uint8_t control; /** Always 0x00 */ |
---|
258 | uint16_t ethertype; |
---|
259 | } libtrace_chdlc_t; |
---|
260 | |
---|
261 | /* Header for PPP in HDLC-like framing */ |
---|
262 | typedef struct libtrace_ppp_hdlc_t { |
---|
263 | uint8_t address; /** Always should be 0xff */ |
---|
264 | uint8_t control; /** Always should be 0x03 */ |
---|
265 | uint16_t protocol; |
---|
266 | } libtrace_ppp_hdlc_t; |
---|
267 | |
---|
268 | static void *trace_get_payload_from_chdlc(void *link, uint16_t *type, |
---|
269 | uint32_t *remaining) { |
---|
270 | |
---|
271 | libtrace_chdlc_t *chdlc = (libtrace_chdlc_t *)link; |
---|
272 | |
---|
273 | if (remaining) { |
---|
274 | if (*remaining < sizeof(libtrace_chdlc_t)) { |
---|
275 | *remaining = 0; |
---|
276 | return NULL; |
---|
277 | } |
---|
278 | *remaining -= sizeof(libtrace_chdlc_t); |
---|
279 | } |
---|
280 | |
---|
281 | if (type) { |
---|
282 | *type = ntohs(chdlc->ethertype); |
---|
283 | } |
---|
284 | |
---|
285 | return (void *)((char *)chdlc + sizeof(*chdlc)); |
---|
286 | |
---|
287 | } |
---|
288 | |
---|
289 | static void *trace_get_payload_from_ppp_hdlc(void *link, |
---|
290 | uint16_t *type, uint32_t *remaining) |
---|
291 | { |
---|
292 | libtrace_ppp_hdlc_t *ppp_hdlc = (libtrace_ppp_hdlc_t*)link; |
---|
293 | |
---|
294 | if (remaining) { |
---|
295 | if (*remaining < sizeof(libtrace_ppp_hdlc_t)) { |
---|
296 | *remaining = 0; |
---|
297 | return NULL; |
---|
298 | } |
---|
299 | *remaining-=sizeof(libtrace_ppp_hdlc_t); |
---|
300 | } |
---|
301 | |
---|
302 | if (type) { |
---|
303 | /* http://www.iana.org/assignments/ppp-numbers */ |
---|
304 | |
---|
305 | switch(ntohs(ppp_hdlc->protocol)) { |
---|
306 | case 0x0021: /* IP */ |
---|
307 | *type = TRACE_ETHERTYPE_IP; |
---|
308 | break; |
---|
309 | case 0xc021: /* Link Control Protocol */ |
---|
310 | *type = 0; /* No ethertype for this */ |
---|
311 | break; |
---|
312 | |
---|
313 | default: |
---|
314 | printf("Unknown chdlc type: %04x\n", |
---|
315 | ntohs(ppp_hdlc->protocol)); |
---|
316 | *type = 0; /* Unknown */ |
---|
317 | } |
---|
318 | } |
---|
319 | |
---|
320 | |
---|
321 | return (void*)((char *)ppp_hdlc+sizeof(*ppp_hdlc)); |
---|
322 | } |
---|
323 | |
---|
324 | void *trace_get_payload_from_link(void *link, libtrace_linktype_t linktype, |
---|
325 | uint16_t *ethertype, uint32_t *remaining) |
---|
326 | { |
---|
327 | void *l = NULL; |
---|
328 | |
---|
329 | do { |
---|
330 | l = trace_get_payload_from_meta(link, &linktype, remaining); |
---|
331 | if (l != NULL) { |
---|
332 | link=l; |
---|
333 | } |
---|
334 | } while (l != NULL); |
---|
335 | |
---|
336 | return trace_get_payload_from_layer2(link,linktype,ethertype,remaining); |
---|
337 | |
---|
338 | } |
---|
339 | |
---|
340 | DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet, |
---|
341 | libtrace_linktype_t *linktype, |
---|
342 | uint32_t *remaining) |
---|
343 | { |
---|
344 | uint32_t dummyrem; |
---|
345 | void *meta = NULL; |
---|
346 | |
---|
347 | assert(packet != NULL); |
---|
348 | assert(linktype != NULL); |
---|
349 | |
---|
350 | if (remaining == NULL) |
---|
351 | remaining = &dummyrem; |
---|
352 | |
---|
353 | meta = trace_get_packet_meta(packet, linktype, remaining); |
---|
354 | |
---|
355 | /* If there are no meta-data headers, we just return the start of the |
---|
356 | * packet buffer, along with the linktype, etc. |
---|
357 | */ |
---|
358 | if (meta == NULL) |
---|
359 | return trace_get_packet_buffer(packet, linktype, remaining); |
---|
360 | |
---|
361 | /* If there are meta-data headers, we need to skip over them until we |
---|
362 | * find a non-meta data header and return that. |
---|
363 | */ |
---|
364 | for(;;) { |
---|
365 | void *nexthdr = trace_get_payload_from_meta(meta, |
---|
366 | linktype, remaining); |
---|
367 | |
---|
368 | if (nexthdr == NULL) { |
---|
369 | switch (*linktype) { |
---|
370 | /* meta points to a layer 2 header! */ |
---|
371 | case TRACE_TYPE_HDLC_POS: |
---|
372 | case TRACE_TYPE_ETH: |
---|
373 | case TRACE_TYPE_ATM: |
---|
374 | case TRACE_TYPE_80211: |
---|
375 | case TRACE_TYPE_NONE: |
---|
376 | case TRACE_TYPE_POS: |
---|
377 | case TRACE_TYPE_AAL5: |
---|
378 | case TRACE_TYPE_DUCK: |
---|
379 | case TRACE_TYPE_LLCSNAP: |
---|
380 | case TRACE_TYPE_PPP: |
---|
381 | case TRACE_TYPE_METADATA: |
---|
382 | case TRACE_TYPE_NONDATA: |
---|
383 | return meta; |
---|
384 | case TRACE_TYPE_LINUX_SLL: |
---|
385 | case TRACE_TYPE_80211_RADIO: |
---|
386 | case TRACE_TYPE_80211_PRISM: |
---|
387 | case TRACE_TYPE_PFLOG: |
---|
388 | break; |
---|
389 | } |
---|
390 | |
---|
391 | /* Otherwise, we must have hit the end of the packet */ |
---|
392 | return NULL; |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | meta = nexthdr; |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | DLLEXPORT |
---|
401 | void *trace_get_payload_from_atm(void *link, |
---|
402 | uint8_t *type, uint32_t *remaining) |
---|
403 | { |
---|
404 | libtrace_atm_capture_cell_t *cell; |
---|
405 | if (remaining && *remaining<sizeof(libtrace_atm_capture_cell_t)) { |
---|
406 | *remaining = 0; |
---|
407 | return NULL; |
---|
408 | } |
---|
409 | cell=(libtrace_atm_capture_cell_t*)link; |
---|
410 | |
---|
411 | if (type) |
---|
412 | *type=cell->pt; |
---|
413 | |
---|
414 | if (remaining) |
---|
415 | *remaining-=sizeof(libtrace_atm_capture_cell_t); |
---|
416 | |
---|
417 | return ((char*)link)+sizeof(libtrace_atm_capture_cell_t); |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | |
---|
422 | DLLEXPORT void *trace_get_payload_from_layer2(void *link, |
---|
423 | libtrace_linktype_t linktype, |
---|
424 | uint16_t *ethertype, |
---|
425 | uint32_t *remaining) |
---|
426 | { |
---|
427 | void *l; |
---|
428 | |
---|
429 | if (linktype == ~0U) { |
---|
430 | fprintf(stderr, "Unable to determine linktype for packet\n"); |
---|
431 | return NULL; |
---|
432 | } |
---|
433 | |
---|
434 | switch(linktype) { |
---|
435 | /* Packet Metadata headers, not layer2 headers */ |
---|
436 | case TRACE_TYPE_80211_PRISM: |
---|
437 | case TRACE_TYPE_80211_RADIO: |
---|
438 | case TRACE_TYPE_PFLOG: |
---|
439 | case TRACE_TYPE_LINUX_SLL: |
---|
440 | return NULL; |
---|
441 | |
---|
442 | /* duck packets have no payload! */ |
---|
443 | case TRACE_TYPE_DUCK: |
---|
444 | return NULL; |
---|
445 | |
---|
446 | /* The payload is in these packets does |
---|
447 | not correspond to a genuine link-layer |
---|
448 | */ |
---|
449 | case TRACE_TYPE_METADATA: |
---|
450 | case TRACE_TYPE_NONDATA: |
---|
451 | return NULL; |
---|
452 | |
---|
453 | case TRACE_TYPE_80211: |
---|
454 | return trace_get_payload_from_80211(link,ethertype,remaining); |
---|
455 | case TRACE_TYPE_ETH: |
---|
456 | return trace_get_payload_from_ethernet(link,ethertype,remaining); |
---|
457 | case TRACE_TYPE_NONE: |
---|
458 | if ((*(char*)link&0xF0) == 0x40) |
---|
459 | *ethertype=TRACE_ETHERTYPE_IP; /* IPv4 */ |
---|
460 | else if ((*(char*)link&0xF0) == 0x60) |
---|
461 | *ethertype=TRACE_ETHERTYPE_IPV6; /* IPv6 */ |
---|
462 | return link; /* I love the simplicity */ |
---|
463 | case TRACE_TYPE_PPP: |
---|
464 | return trace_get_payload_from_ppp(link,ethertype,remaining); |
---|
465 | case TRACE_TYPE_ATM: |
---|
466 | l=trace_get_payload_from_atm(link,NULL,remaining); |
---|
467 | /* FIXME: We shouldn't skip llcsnap here, we should |
---|
468 | * return an ethertype for it (somehow) |
---|
469 | */ |
---|
470 | return (l ? trace_get_payload_from_llcsnap(l, |
---|
471 | ethertype, remaining):NULL); |
---|
472 | case TRACE_TYPE_LLCSNAP: |
---|
473 | return trace_get_payload_from_llcsnap(link,ethertype,remaining); |
---|
474 | |
---|
475 | case TRACE_TYPE_HDLC_POS: |
---|
476 | return trace_get_payload_from_chdlc(link,ethertype, |
---|
477 | remaining); |
---|
478 | case TRACE_TYPE_POS: |
---|
479 | return trace_get_payload_from_ppp_hdlc(link,ethertype, |
---|
480 | remaining); |
---|
481 | /* TODO: Unsupported */ |
---|
482 | case TRACE_TYPE_AAL5: |
---|
483 | return NULL; |
---|
484 | } |
---|
485 | return NULL; |
---|
486 | |
---|
487 | } |
---|
488 | |
---|
489 | /* Take a pointer to the start of an IEEE 802.11 MAC frame and return a pointer |
---|
490 | * to the source MAC address. |
---|
491 | * If the frame does not contain a sender address, e.g. ACK frame, return NULL. |
---|
492 | * If the frame is a 4-address WDS frame, return TA, i.e. addr2. |
---|
493 | * NB: This function decodes the 802.11 header, so it assumes that there are no |
---|
494 | * bit-errors. If there are, all bets are off. |
---|
495 | */ |
---|
496 | static |
---|
497 | uint8_t *get_source_mac_from_wifi(void *wifi) { |
---|
498 | struct libtrace_80211_t *w; |
---|
499 | if (wifi == NULL) return NULL; |
---|
500 | w = (struct libtrace_80211_t *) wifi; |
---|
501 | |
---|
502 | /* If the frame is of type CTRL */ |
---|
503 | if (w->type == 0x1) |
---|
504 | /* If bit 2 of the subtype field is zero, this indicates that |
---|
505 | * there is no transmitter address, i.e. the frame is either an |
---|
506 | * ACK or a CTS frame */ |
---|
507 | if ((w->subtype & 0x2) == 0) |
---|
508 | return NULL; |
---|
509 | |
---|
510 | /* Always return the address of the transmitter, i.e. address 2 */ |
---|
511 | return (uint8_t *) &w->mac2; |
---|
512 | } |
---|
513 | |
---|
514 | DLLEXPORT uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { |
---|
515 | void *link; |
---|
516 | uint32_t remaining; |
---|
517 | libtrace_linktype_t linktype; |
---|
518 | assert(packet); |
---|
519 | link = trace_get_layer2(packet,&linktype,&remaining); |
---|
520 | |
---|
521 | if (!link) |
---|
522 | return NULL; |
---|
523 | |
---|
524 | switch (linktype) { |
---|
525 | case TRACE_TYPE_ETH: |
---|
526 | return (uint8_t *)&(((libtrace_ether_t*)link)->ether_shost); |
---|
527 | case TRACE_TYPE_80211: |
---|
528 | return get_source_mac_from_wifi(link); |
---|
529 | /* These packets don't have MAC addresses */ |
---|
530 | case TRACE_TYPE_POS: |
---|
531 | case TRACE_TYPE_NONE: |
---|
532 | case TRACE_TYPE_HDLC_POS: |
---|
533 | case TRACE_TYPE_PFLOG: |
---|
534 | case TRACE_TYPE_ATM: |
---|
535 | case TRACE_TYPE_DUCK: |
---|
536 | case TRACE_TYPE_METADATA: |
---|
537 | case TRACE_TYPE_AAL5: |
---|
538 | case TRACE_TYPE_LLCSNAP: |
---|
539 | case TRACE_TYPE_PPP: |
---|
540 | case TRACE_TYPE_NONDATA: |
---|
541 | return NULL; |
---|
542 | |
---|
543 | /* Metadata headers should already be skipped */ |
---|
544 | case TRACE_TYPE_LINUX_SLL: |
---|
545 | case TRACE_TYPE_80211_PRISM: |
---|
546 | case TRACE_TYPE_80211_RADIO: |
---|
547 | assert(!"Metadata headers should already be skipped"); |
---|
548 | break; |
---|
549 | } |
---|
550 | fprintf(stderr,"%s not implemented for linktype %i\n", __func__, linktype); |
---|
551 | assert(0); |
---|
552 | return NULL; |
---|
553 | } |
---|
554 | |
---|
555 | DLLEXPORT uint8_t *trace_get_destination_mac(libtrace_packet_t *packet) |
---|
556 | { |
---|
557 | void *link; |
---|
558 | libtrace_linktype_t linktype; |
---|
559 | uint32_t remaining; |
---|
560 | libtrace_80211_t *wifi; |
---|
561 | libtrace_ether_t *ethptr; |
---|
562 | |
---|
563 | link = trace_get_layer2(packet,&linktype,&remaining); |
---|
564 | |
---|
565 | ethptr = (libtrace_ether_t*)link; |
---|
566 | |
---|
567 | |
---|
568 | if (!link) |
---|
569 | return NULL; |
---|
570 | |
---|
571 | switch (linktype) { |
---|
572 | case TRACE_TYPE_80211: |
---|
573 | wifi=(libtrace_80211_t*)link; |
---|
574 | return (uint8_t*)&wifi->mac1; |
---|
575 | case TRACE_TYPE_ETH: |
---|
576 | return (uint8_t*)ðptr->ether_dhost; |
---|
577 | case TRACE_TYPE_POS: |
---|
578 | case TRACE_TYPE_NONE: |
---|
579 | case TRACE_TYPE_ATM: |
---|
580 | case TRACE_TYPE_HDLC_POS: |
---|
581 | case TRACE_TYPE_PFLOG: |
---|
582 | case TRACE_TYPE_DUCK: |
---|
583 | case TRACE_TYPE_METADATA: |
---|
584 | case TRACE_TYPE_AAL5: |
---|
585 | case TRACE_TYPE_LLCSNAP: |
---|
586 | case TRACE_TYPE_PPP: |
---|
587 | case TRACE_TYPE_NONDATA: |
---|
588 | /* No MAC address */ |
---|
589 | return NULL; |
---|
590 | /* Metadata headers should already be skipped */ |
---|
591 | case TRACE_TYPE_LINUX_SLL: |
---|
592 | case TRACE_TYPE_80211_PRISM: |
---|
593 | case TRACE_TYPE_80211_RADIO: |
---|
594 | assert(!"Metadata headers should already be skipped"); |
---|
595 | break; |
---|
596 | } |
---|
597 | fprintf(stderr,"Not implemented\n"); |
---|
598 | assert(0); |
---|
599 | return NULL; |
---|
600 | } |
---|
601 | |
---|