| 942 | Field.__init__(self, name, default, "16s") |
| 943 | |
| 944 | def h2i(self, pkt, x): |
| 945 | # type: (Optional[Packet], Any) -> str |
| 946 | if isinstance(x, bytes): |
| 947 | x = plain_str(x) |
| 948 | if isinstance(x, _ScopedIP): |
| 949 | return x |
| 950 | elif isinstance(x, str): |
| 951 | x = ScopedIP(x) |
| 952 | try: |
| 953 | x = ScopedIP(in6_ptop(x), scope=x.scope) |
| 954 | except socket.error: |
| 955 | return Net6(x) # type: ignore |
| 956 | elif isinstance(x, tuple): |
| 957 | if len(x) != 2: |
| 958 | raise ValueError("Invalid IPv6 format") |
| 959 | return Net6(*x) # type: ignore |
| 960 | elif isinstance(x, list): |
| 961 | x = [self.h2i(pkt, n) for n in x] |
| 962 | return x # type: ignore |
| 963 | |
| 964 | def i2h(self, pkt, x): |
| 965 | # type: (Optional[Packet], Optional[Union[str, Net6]]) -> str |