From 15801106bd8ddbccd4125e8fe5d146cb908107ab Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Thu, 18 Jun 2015 00:57:07 +0200 Subject: pcap_io: add sockaddr_ll to pcap_ll Add relevant structure and conversion functions in both directions. Signed-off-by: Vadim Kochan [ dbkm: split out patch ] Signed-off-by: Daniel Borkmann --- pcap_io.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'pcap_io.h') 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) -- cgit v1.2.3-54-g00ecf