From 3c30982409a0ee1e0d219b66de4bad9f253a4bd9 Mon Sep 17 00:00:00 2001
From: Daniel Czerwonk <czerwonk@users.noreply.github.com>
Date: Thu, 31 May 2018 21:49:10 +0200
Subject: [PATCH] Update path_attributes.go

---
 protocols/bgp/packet/path_attributes.go | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go
index 976dcb07..db23ea94 100644
--- a/protocols/bgp/packet/path_attributes.go
+++ b/protocols/bgp/packet/path_attributes.go
@@ -252,16 +252,11 @@ func (pa *PathAttribute) decodeCommunities(buf *bytes.Buffer) error {
 	coms := make([]uint32, count)
 
 	for i := uint16(0); i < count; i++ {
-		c := [CommunityLen]byte{}
-		n, err := buf.Read(c[:])
-		if err != nil {
-			return err
-		}
-		if n != 4 {
-			return fmt.Errorf("Unable to read next hop: buf.Read read %d bytes", n)
-		}
-
-		coms[i] = fourBytesToUint32(c)
+		v, err = read4BytesAsUin32(buf)
++		if err != nil {
++			return err
++		}
+		coms[i] = v
 	}
 
 	pa.Value = coms
-- 
GitLab