|
| 1 | +const RESERVED: u8 = 0; |
| 2 | +const REQUEST: u8 = 1; |
| 3 | +const REPLY: u8 = 2; |
| 4 | +const REQUEST_REVERSE: u8 = 3; |
| 5 | +const REPLY_REVERSE: u8 = 4; |
| 6 | +const DRARP_REQUEST: u8 = 5; |
| 7 | +const DRARP_REPLY: u8 = 6; |
| 8 | +const DRARP_ERROR: u8 = 7; |
| 9 | +const IN_ARP_REQUEST: u8 = 8; |
| 10 | +const IN_ARP_REPLY: u8 = 9; |
| 11 | +const ARP_NAK: u8 = 10; |
| 12 | +const MARS_REQUEST: u8 = 11; |
| 13 | +const MARS_MULTI: u8 = 12; |
| 14 | +const MARS_MSERV: u8 = 13; |
| 15 | +const MARS_JOIN: u8 = 14; |
| 16 | +const MARS_LEAVE: u8 = 15; |
| 17 | +const MARS_NAK: u8 = 16; |
| 18 | +const MARS_UNSERV: u8 = 17; |
| 19 | +const MARS_SJOIN: u8 = 18; |
| 20 | +const MARS_SLEAVE: u8 = 19; |
| 21 | +const MARS_GROUP_LIST_REQUEST: u8 = 20; |
| 22 | +const MARS_GROUP_LIST_REPLY: u8 = 21; |
| 23 | +const MARS_REDIRECT_MAP: u8 = 22; |
| 24 | +const MAPO_SUNARP: u8 = 23; |
| 25 | +const OP_EXP1: u8 = 24; |
| 26 | +const OP_EXP2: u8 = 25; |
| 27 | + |
| 28 | +/// Enum of ARP operation codes. |
| 29 | +/// |
| 30 | +/// List from [iana.org][1] |
| 31 | +/// |
| 32 | +/// [1]: https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml |
| 33 | +#[derive(Debug, PartialEq, Eq, Clone, Copy, Ord, PartialOrd, Hash)] |
| 34 | +#[non_exhaustive] |
| 35 | +#[repr(u8)] |
| 36 | +pub enum Operation { |
| 37 | + Reserved = RESERVED, |
| 38 | + Request = REQUEST, |
| 39 | + Reply = REPLY, |
| 40 | + RequestReverse = REQUEST_REVERSE, |
| 41 | + ReplyReverse = REPLY_REVERSE, |
| 42 | + DrarpRequest = DRARP_REQUEST, |
| 43 | + DrarpReply = DRARP_REPLY, |
| 44 | + DrarpError = DRARP_ERROR, |
| 45 | + InArpRequest = IN_ARP_REQUEST, |
| 46 | + InArpReply = IN_ARP_REPLY, |
| 47 | + ArpNak = ARP_NAK, |
| 48 | + MarsRequest = MARS_REQUEST, |
| 49 | + MarsMulti = MARS_MULTI, |
| 50 | + MarsMServ = MARS_MSERV, |
| 51 | + MarsJoin = MARS_JOIN, |
| 52 | + MarsLeave = MARS_LEAVE, |
| 53 | + MarsNAK = MARS_NAK, |
| 54 | + MarsUnserv = MARS_UNSERV, |
| 55 | + MarsSJoin = MARS_SJOIN, |
| 56 | + MarsSLeave = MARS_SLEAVE, |
| 57 | + MarsGroupListRequest = MARS_GROUP_LIST_REQUEST, |
| 58 | + MarsGroupListReply = MARS_GROUP_LIST_REPLY, |
| 59 | + MarsRedirectMap = MARS_REDIRECT_MAP, |
| 60 | + MapoSUnarp = MAPO_SUNARP, |
| 61 | + OpExp1 = OP_EXP1, |
| 62 | + OpExp2 = OP_EXP2, |
| 63 | + Other(u8), |
| 64 | +} |
| 65 | + |
| 66 | +impl AsRef<u8> for Operation { |
| 67 | + fn as_ref(&self) -> &u8 { |
| 68 | + match self { |
| 69 | + Operation::Reserved => &RESERVED, |
| 70 | + Operation::Request => &REQUEST, |
| 71 | + Operation::Reply => &REPLY, |
| 72 | + Operation::RequestReverse => &REQUEST_REVERSE, |
| 73 | + Operation::ReplyReverse => &REPLY_REVERSE, |
| 74 | + Operation::DrarpRequest => &DRARP_REQUEST, |
| 75 | + Operation::DrarpReply => &DRARP_REPLY, |
| 76 | + Operation::DrarpError => &DRARP_ERROR, |
| 77 | + Operation::InArpRequest => &IN_ARP_REQUEST, |
| 78 | + Operation::InArpReply => &IN_ARP_REPLY, |
| 79 | + Operation::ArpNak => &ARP_NAK, |
| 80 | + Operation::MarsRequest => &MARS_REQUEST, |
| 81 | + Operation::MarsMulti => &MARS_MULTI, |
| 82 | + Operation::MarsMServ => &MARS_MSERV, |
| 83 | + Operation::MarsJoin => &MARS_JOIN, |
| 84 | + Operation::MarsLeave => &MARS_LEAVE, |
| 85 | + Operation::MarsNAK => &MARS_NAK, |
| 86 | + Operation::MarsUnserv => &MARS_UNSERV, |
| 87 | + Operation::MarsSJoin => &MARS_SJOIN, |
| 88 | + Operation::MarsSLeave => &MARS_SLEAVE, |
| 89 | + Operation::MarsGroupListRequest => &MARS_GROUP_LIST_REQUEST, |
| 90 | + Operation::MarsGroupListReply => &MARS_GROUP_LIST_REPLY, |
| 91 | + Operation::MarsRedirectMap => &MARS_REDIRECT_MAP, |
| 92 | + Operation::MapoSUnarp => &MAPO_SUNARP, |
| 93 | + Operation::OpExp1 => &OP_EXP1, |
| 94 | + Operation::OpExp2 => &OP_EXP2, |
| 95 | + Operation::Other(x) => x, |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +impl From<u8> for Operation { |
| 101 | + fn from(value: u8) -> Self { |
| 102 | + match value { |
| 103 | + RESERVED => Operation::Reserved, |
| 104 | + REQUEST => Operation::Request, |
| 105 | + REPLY => Operation::Reply, |
| 106 | + REQUEST_REVERSE => Operation::RequestReverse, |
| 107 | + REPLY_REVERSE => Operation::ReplyReverse, |
| 108 | + DRARP_REQUEST => Operation::DrarpRequest, |
| 109 | + DRARP_REPLY => Operation::DrarpReply, |
| 110 | + DRARP_ERROR => Operation::DrarpError, |
| 111 | + IN_ARP_REQUEST => Operation::InArpRequest, |
| 112 | + IN_ARP_REPLY => Operation::InArpReply, |
| 113 | + ARP_NAK => Operation::ArpNak, |
| 114 | + MARS_REQUEST => Operation::MarsRequest, |
| 115 | + MARS_MULTI => Operation::MarsMulti, |
| 116 | + MARS_MSERV => Operation::MarsMServ, |
| 117 | + MARS_JOIN => Operation::MarsJoin, |
| 118 | + MARS_LEAVE => Operation::MarsLeave, |
| 119 | + MARS_NAK => Operation::MarsNAK, |
| 120 | + MARS_UNSERV => Operation::MarsUnserv, |
| 121 | + MARS_SJOIN => Operation::MarsSJoin, |
| 122 | + MARS_SLEAVE => Operation::MarsSLeave, |
| 123 | + MARS_GROUP_LIST_REQUEST => Operation::MarsGroupListRequest, |
| 124 | + MARS_GROUP_LIST_REPLY => Operation::MarsGroupListReply, |
| 125 | + MARS_REDIRECT_MAP => Operation::MarsRedirectMap, |
| 126 | + MAPO_SUNARP => Operation::MapoSUnarp, |
| 127 | + OP_EXP1 => Operation::OpExp1, |
| 128 | + OP_EXP2 => Operation::OpExp2, |
| 129 | + x => Operation::Other(x), |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +impl From<Operation> for u8 { |
| 135 | + fn from(value: Operation) -> Self { |
| 136 | + *value.as_ref() |
| 137 | + } |
| 138 | +} |
0 commit comments