* Parse the v3 peer up BMP header * * \details This method will update the db peer_up_event struct with BMP header info. * * \param [in] sock Socket to read the message from * \param [out] up_event Reference to the peer up event storage (will be updated with bmp info) * * \returns true if successfully parsed the bmp peer up header, false otherwise */
| 648 | * \returns true if successfully parsed the bmp peer up header, false otherwise |
| 649 | */ |
| 650 | bool parseBMP::parsePeerUpEventHdr(int sock, MsgBusInterface::obj_peer_up_event &up_event) { |
| 651 | |
| 652 | |
| 653 | unsigned char local_addr[16]; |
| 654 | bool isParseGood = true; |
| 655 | int bytes_read = 0; |
| 656 | |
| 657 | // Get the local address |
| 658 | if ( Recv(sock, &local_addr, 16, MSG_WAITALL) != 16) |
| 659 | isParseGood = false; |
| 660 | else |
| 661 | bytes_read += 16; |
| 662 | |
| 663 | if (isParseGood and p_entry->isIPv4) { |
| 664 | snprintf(up_event.local_ip, sizeof(up_event.local_ip), "%d.%d.%d.%d", |
| 665 | local_addr[12], local_addr[13], local_addr[14], |
| 666 | local_addr[15]); |
| 667 | SELF_DEBUG("%s : Peer UP local address is IPv4 %s", peer_addr, up_event.local_ip); |
| 668 | |
| 669 | } else if (isParseGood) { |
| 670 | inet_ntop(AF_INET6, local_addr, up_event.local_ip, sizeof(up_event.local_ip)); |
| 671 | SELF_DEBUG("%s : Peer UP local address is IPv6 %s", peer_addr, up_event.local_ip); |
| 672 | } |
| 673 | |
| 674 | // Get the local port |
| 675 | if (isParseGood and Recv(sock, &up_event.local_port, 2, MSG_WAITALL) != 2) |
| 676 | isParseGood = false; |
| 677 | |
| 678 | else if (isParseGood) { |
| 679 | bytes_read += 2; |
| 680 | bgp::SWAP_BYTES(&up_event.local_port); |
| 681 | } |
| 682 | |
| 683 | // Get the remote port |
| 684 | if (isParseGood and Recv(sock, &up_event.remote_port, 2, MSG_WAITALL) != 2) |
| 685 | isParseGood = false; |
| 686 | |
| 687 | else if (isParseGood) { |
| 688 | bytes_read += 2; |
| 689 | bgp::SWAP_BYTES(&up_event.remote_port); |
| 690 | } |
| 691 | |
| 692 | // Update bytes read |
| 693 | bmp_len -= bytes_read; |
| 694 | |
| 695 | |
| 696 | // Buffer the remaining data for BMP message |
| 697 | bufferBMPMessage(sock); |
| 698 | |
| 699 | // Validate if still good |
| 700 | if (isParseGood == false) { |
| 701 | LOG_NOTICE("%s: PEER UP header failed to be parsed, read only %d bytes of the header", |
| 702 | peer_addr, bytes_read); |
| 703 | |
| 704 | // Buffer the remaining data for BMP message |
| 705 | bufferBMPMessage(sock); |
| 706 | } |
| 707 |
no test coverage detected