parseSyncPacket parses SYNC/DELAY_REQ packets and returns the packet, source IP and source port
(packet gopacket.Packet)
| 157 | |
| 158 | // parseSyncPacket parses SYNC/DELAY_REQ packets and returns the packet, source IP and source port |
| 159 | func parseSyncPacket(packet gopacket.Packet) (*ptp.SyncDelayReq, string, string, error) { |
| 160 | ipHeader, ok := packet.NetworkLayer().(*layers.IPv6) |
| 161 | if !ok { |
| 162 | return nil, "", "", fmt.Errorf("unable to parse IPv6 Header") |
| 163 | } |
| 164 | udpHeader, ok := packet.TransportLayer().(*layers.UDP) |
| 165 | if !ok { |
| 166 | return nil, "", "", fmt.Errorf("unable to parse UDP Header") |
| 167 | } |
| 168 | |
| 169 | appLayer := packet.ApplicationLayer() |
| 170 | if appLayer == nil { |
| 171 | return nil, "", "", fmt.Errorf("unable to parse Application Layer") |
| 172 | } |
| 173 | ptpPacket, err := ptp.DecodePacket(appLayer.Payload()) |
| 174 | if err != nil { |
| 175 | return nil, "", "", fmt.Errorf("unable to decode PTP packet: %w", err) |
| 176 | } |
| 177 | if ptpPacket.MessageType() != ptp.MessageSync && ptpPacket.MessageType() != ptp.MessageDelayReq { |
| 178 | return nil, "", "", fmt.Errorf("not parsing %v: not a SYNC/DELAY_REQ packet", ptpPacket.MessageType().String()) |
| 179 | } |
| 180 | return ptpPacket.(*ptp.SyncDelayReq), ipHeader.SrcIP.String(), strconv.Itoa(int(udpHeader.SrcPort)), nil |
| 181 | } |
searching dependent graphs…