summaryrefslogtreecommitdiff
path: root/pcap_io.h
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-06-18 00:57:07 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2015-06-18 00:59:53 +0200
commit15801106bd8ddbccd4125e8fe5d146cb908107ab (patch)
tree1a278f868c54d33fddc640645a78153bd6b5d39e /pcap_io.h
parentda8fcdd7d8ce59ea334ec24cdaddcc02eb611f04 (diff)
pcap_io: add sockaddr_ll to pcap_ll
Add relevant structure and conversion functions in both directions. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> [ dbkm: split out patch ] Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'pcap_io.h')
-rw-r--r--pcap_io.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/pcap_io.h b/pcap_io.h
index e9251bf..497e453 100644
--- a/pcap_io.h
+++ b/pcap_io.h
@@ -58,6 +58,14 @@ struct pcap_timeval_ns {
int32_t tv_nsec;
};
+struct pcap_ll {
+ uint16_t pkttype;
+ uint16_t hatype;
+ uint16_t len;
+ uint8_t addr[8];
+ uint16_t protocol;
+};
+
struct pcap_pkthdr {
struct pcap_timeval ts;
uint32_t caplen;
@@ -138,6 +146,28 @@ extern const struct pcap_file_ops pcap_rw_ops __maybe_unused;
extern const struct pcap_file_ops pcap_sg_ops __maybe_unused;
extern const struct pcap_file_ops pcap_mm_ops __maybe_unused;
+static inline void sockaddr_to_ll(const struct sockaddr_ll *sll,
+ struct pcap_ll *ll)
+{
+ ll->pkttype = cpu_to_be16(sll->sll_pkttype);
+ ll->hatype = cpu_to_be16(sll->sll_hatype);
+ ll->len = cpu_to_be16(sll->sll_halen);
+ ll->protocol = sll->sll_protocol; /* already be16 */
+
+ memcpy(ll->addr, sll->sll_addr, sizeof(ll->addr));
+}
+
+static inline void ll_to_sockaddr(const struct pcap_ll *ll,
+ struct sockaddr_ll *sll)
+{
+ sll->sll_pkttype = be16_to_cpu(ll->pkttype);
+ sll->sll_hatype = be16_to_cpu(ll->hatype);
+ sll->sll_halen = be16_to_cpu(ll->len);
+ sll->sll_protocol = ll->protocol; /* stays be16 */
+
+ memcpy(sll->sll_addr, ll->addr, sizeof(ll->addr));
+}
+
static inline uint16_t tp_to_pcap_tsource(uint32_t status)
{
if (status & TP_STATUS_TS_RAW_HARDWARE)