In order to be able to convert to a generic address struct, separate source
and destination address into separate fields.

Signed-off-by: Jiri Benc <jb...@redhat.com>
---
 ether.h |   13 ++++++-------
 raw.c   |   22 +++++++++++-----------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/ether.h b/ether.h
index 07d0f31dae26..89e22c879058 100644
--- a/ether.h
+++ b/ether.h
@@ -26,25 +26,24 @@
 #define PTP_DST_MAC 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00
 #define P2P_DST_MAC 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E
 
-struct eth_addr {
-       uint8_t dst[MAC_LEN];
-       uint8_t src[MAC_LEN];
-} __attribute__((packed));
+typedef uint8_t eth_addr[MAC_LEN];
 
 struct eth_hdr {
-       struct eth_addr mac;
+       eth_addr dst;
+       eth_addr src;
        uint16_t type;
 } __attribute__((packed));
 
 #define VLAN_HLEN 4
 
 struct vlan_hdr {
-       struct eth_addr mac;
+       eth_addr dst;
+       eth_addr src;
        uint16_t tpid;
        uint16_t tci;
        uint16_t type;
 } __attribute__((packed));
 
-#define OFF_ETYPE sizeof(struct eth_addr)
+#define OFF_ETYPE (2 * sizeof(eth_addr))
 
 #endif
diff --git a/raw.c b/raw.c
index 2afe8a25f85a..2de0793745ee 100644
--- a/raw.c
+++ b/raw.c
@@ -45,8 +45,9 @@
 
 struct raw {
        struct transport t;
-       struct eth_addr ptp_addr;
-       struct eth_addr p2p_addr;
+       eth_addr src_addr;
+       eth_addr ptp_addr;
+       eth_addr p2p_addr;
        int vlan;
 };
 
@@ -190,14 +191,12 @@ static int raw_open(struct transport *t, const char *name,
        struct raw *raw = container_of(t, struct raw, t);
        int efd, gfd;
 
-       memcpy(raw->ptp_addr.dst, ptp_dst_mac, MAC_LEN);
-       memcpy(raw->p2p_addr.dst, p2p_dst_mac, MAC_LEN);
+       memcpy(raw->ptp_addr, ptp_dst_mac, MAC_LEN);
+       memcpy(raw->p2p_addr, p2p_dst_mac, MAC_LEN);
 
-       if (sk_interface_macaddr(name, raw->ptp_addr.src, MAC_LEN))
+       if (sk_interface_macaddr(name, raw->src_addr, MAC_LEN))
                goto no_mac;
 
-       memcpy(raw->p2p_addr.src, raw->ptp_addr.src, MAC_LEN);
-
        efd = open_socket(name, 1);
        if (efd < 0)
                goto no_event;
@@ -277,9 +276,10 @@ static int raw_send(struct transport *t, struct fdarray 
*fda, int event, int pee
 
        hdr = (struct eth_hdr *) ptr;
        if (peer)
-               memcpy(&hdr->mac, &raw->p2p_addr, sizeof(hdr->mac));
+               memcpy(&hdr->dst, &raw->p2p_addr, MAC_LEN);
        else
-               memcpy(&hdr->mac, &raw->ptp_addr, sizeof(hdr->mac));
+               memcpy(&hdr->dst, &raw->ptp_addr, MAC_LEN);
+       memcpy(&hdr->src, &raw->src_addr, MAC_LEN);
 
        hdr->type = htons(ETH_P_1588);
 
@@ -303,14 +303,14 @@ static void raw_release(struct transport *t)
 static int raw_physical_addr(struct transport *t, uint8_t *addr)
 {
        struct raw *raw = container_of(t, struct raw, t);
-       memcpy(addr, raw->ptp_addr.src, MAC_LEN);
+       memcpy(addr, raw->src_addr, MAC_LEN);
        return MAC_LEN;
 }
 
 static int raw_protocol_addr(struct transport *t, uint8_t *addr)
 {
        struct raw *raw = container_of(t, struct raw, t);
-       memcpy(addr, raw->ptp_addr.src, MAC_LEN);
+       memcpy(addr, raw->src_addr, MAC_LEN);
        return MAC_LEN;
 }
 
-- 
1.7.6.5


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to