{
const auto* old_opt = opt;
opt = &opt->next();
- if (opt == old_opt) // defend against option length = 0
+ if (opt == old_opt or opt->code == TcpOptCode::EOL) // defend against option length = 0
{
*this = iter->end();
tcpStats.zero_len_tcp_opt++;
inline const TcpOption& next() const
{
-#ifdef __GNUC__
- const uint8_t tmp_len = ((uint8_t)code <= 1) ? 1 : len;
- const uint8_t* const tmp = reinterpret_cast<const uint8_t*>(this);
- const TcpOption* opt = reinterpret_cast<const TcpOption*>(&tmp[tmp_len]);
- return *opt;
-
-#else
if ( (uint8_t)code <= 1 )
return reinterpret_cast<const TcpOption&>(len);
else
return reinterpret_cast<const TcpOption&>(data[len -2]);
-#endif
}
};
uint32_t TcpSegmentDescriptor::init_wscale(uint16_t* value)
{
- tcp::TcpOptIterator iter(tcph, pkt);
-
- for (const tcp::TcpOption& opt : iter)
+ if ( pkt->ptrs.decode_flags & DECODE_TCP_WS )
{
- if (opt.code == tcp::TcpOptCode::WSCALE)
+ tcp::TcpOptIterator iter(tcph, pkt);
+
+ for (const tcp::TcpOption& opt : iter)
{
- *value = (uint16_t)opt.data[0];
+ if (opt.code == tcp::TcpOptCode::WSCALE)
+ {
+ *value = (uint16_t)opt.data[0];
- // If scale specified in option is larger than 14, use 14 because of limitation
- // in the math of shifting a 32bit value (max scaled window is 2^30th).
- // See RFC 1323 for details.
- if (*value > 14)
- *value = 14;
+ // If scale specified in option is larger than 14, use 14 because of limitation
+ // in the math of shifting a 32bit value (max scaled window is 2^30th).
+ // See RFC 1323 for details.
+ if (*value > 14)
+ *value = 14;
- return TF_WSCALE;
+ return TF_WSCALE;
+ }
}
}
-
*value = 0;
-
return TF_NONE;
}