Special Field that gets its value from the end of the *packet* (Note: not layer, but packet). Mostly used for FCS
| 709 | |
| 710 | |
| 711 | class TrailerField(_FieldContainer): |
| 712 | """Special Field that gets its value from the end of the *packet* |
| 713 | (Note: not layer, but packet). |
| 714 | |
| 715 | Mostly used for FCS |
| 716 | """ |
| 717 | __slots__ = ["fld"] |
| 718 | |
| 719 | def __init__(self, fld): |
| 720 | # type: (Field[Any, Any]) -> None |
| 721 | self.fld = fld |
| 722 | |
| 723 | # Note: this is ugly. Very ugly. |
| 724 | # Do not copy this crap elsewhere, so that if one day we get |
| 725 | # brave enough to refactor it, it'll be easier. |
| 726 | |
| 727 | def getfield(self, pkt, s): |
| 728 | # type: (Packet, bytes) -> Tuple[bytes, int] |
| 729 | previous_post_dissect = pkt.post_dissect |
| 730 | |
| 731 | def _post_dissect(self, s): |
| 732 | # type: (Packet, bytes) -> bytes |
| 733 | # Reset packet to allow post_build |
| 734 | self.raw_packet_cache = None |
| 735 | self.post_dissect = previous_post_dissect # type: ignore |
| 736 | return previous_post_dissect(s) |
| 737 | pkt.post_dissect = MethodType(_post_dissect, pkt) # type: ignore |
| 738 | s = TrailerBytes(s) |
| 739 | s, val = self.fld.getfield(pkt, s) |
| 740 | return bytes(s), val |
| 741 | |
| 742 | def addfield(self, pkt, s, val): |
| 743 | # type: (Packet, bytes, Optional[int]) -> bytes |
| 744 | previous_post_build = pkt.post_build |
| 745 | value = self.fld.addfield(pkt, b"", val) |
| 746 | |
| 747 | def _post_build(self, p, pay): |
| 748 | # type: (Packet, bytes, bytes) -> bytes |
| 749 | pay += value |
| 750 | self.post_build = previous_post_build # type: ignore |
| 751 | return previous_post_build(p, pay) |
| 752 | pkt.post_build = MethodType(_post_build, pkt) # type: ignore |
| 753 | return s |
| 754 | |
| 755 | |
| 756 | class FCSField(TrailerField): |
no outgoing calls
no test coverage detected