2 * Copyright (C) 2009, 2010 Daniel Borkmann <daniel@netsniff-ng.org> and
3 * Emmanuel Roullit <emmanuel@netsniff-ng.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
20 #ifndef __PROTO_ETHERNET_H__
21 #define __PROTO_ETHERNET_H__
26 #include <netinet/if_ether.h>
31 static inline struct ethhdr
*get_ethhdr(uint8_t ** pkt
, uint32_t * pkt_len
)
33 struct ethhdr
*header
;
36 assert(*pkt_len
> ETH_HLEN
);
38 header
= (struct ethhdr
*)*pkt
;
46 static inline uint16_t get_ethertype(const struct ethhdr
*header
)
49 return (ntohs(header
->h_proto
));
53 * print_ethhdr - Just plain dumb formatting
54 * @eth: ethernet header
56 static inline void print_ethhdr(struct ethhdr
*eth
)
58 uint8_t *src_mac
= eth
->h_source
;
59 uint8_t *dst_mac
= eth
->h_dest
;
64 info("MAC (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x => %.2x:%.2x:%.2x:%.2x:%.2x:%.2x), ", src_mac
[0], src_mac
[1], src_mac
[2], src_mac
[3], src_mac
[4], src_mac
[5], dst_mac
[0], dst_mac
[1], dst_mac
[2], dst_mac
[3], dst_mac
[4], dst_mac
[5]);
65 info("Proto (0x%.4x, %s)", ntohs(eth
->h_proto
),
66 ether_types_find(eth
->h_proto
));
70 info("Vendor (%s => %s)", ieee_vendors_find(src_mac
),
71 ieee_vendors_find(dst_mac
));
76 * print_ethhdr_less - Just plain dumb formatting
77 * @eth: ethernet header
79 static inline void print_ethhdr_less(struct ethhdr
*eth
)
81 uint8_t *src_mac
= eth
->h_source
;
82 uint8_t *dst_mac
= eth
->h_dest
;
86 info("0x%.4x, %.2x:%.2x:%.2x:%.2x:%.2x:%.2x => %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, %s => %s, ", ntohs(eth
->h_proto
), src_mac
[0], src_mac
[1], src_mac
[2], src_mac
[3], src_mac
[4], src_mac
[5], dst_mac
[0], dst_mac
[1], dst_mac
[2], dst_mac
[3], dst_mac
[4], dst_mac
[5], ieee_vendors_find(src_mac
), ieee_vendors_find(dst_mac
));
89 #endif /* __PROTO_ETHERNET_H__ */