| 210 | |
| 211 | |
| 212 | class CoAP(Packet): |
| 213 | __slots__ = ["content_format"] |
| 214 | name = "CoAP" |
| 215 | |
| 216 | fields_desc = [BitField("ver", 1, 2), |
| 217 | BitEnumField("type", 0, 2, {0: "CON", 1: "NON", 2: "ACK", 3: "RST"}), # noqa: E501 |
| 218 | BitFieldLenField("tkl", None, 4, length_of='token'), |
| 219 | ByteEnumField("code", 0, coap_codes), |
| 220 | ShortField("msg_id", 0), |
| 221 | StrLenField("token", "", length_from=lambda pkt: pkt.tkl), |
| 222 | _CoAPOptsField("options", []), |
| 223 | _CoAPPaymark("paymark", b"") |
| 224 | ] |
| 225 | |
| 226 | def getfieldval(self, attr): |
| 227 | v = getattr(self, attr) |
| 228 | if v: |
| 229 | return v |
| 230 | return Packet.getfieldval(self, attr) |
| 231 | |
| 232 | def post_dissect(self, pay): |
| 233 | for k in self.options: |
| 234 | if k[0] == "Content-Format": |
| 235 | self.content_format = k[1] |
| 236 | return pay |
| 237 | |
| 238 | |
| 239 | bind_layers(UDP, CoAP, sport=5683) |
nothing calls this directly
no test coverage detected