void Connection::add_option(TCP::Option::Kind kind, TCP::Packet_ptr packet) { switch(kind) { case Option::MSS: { packet->add_option<Option::opt_mss>(host_.MSS()); debug2("<TCP::Connection::add_option@Option::MSS> Packet: %s - MSS: %u\n", packet->to_string().c_str(), ntohs(*(uint16_t*)(packet->options()+2))); break; } default: break; } }
void Connection::parse_options(TCP::Packet_ptr packet) { assert(packet->has_options()); debug("<TCP::parse_options> Parsing options. Offset: %u, Options: %u \n", packet->offset(), packet->options_length()); auto* opt = packet->options(); while((char*)opt < packet->data()) { auto* option = (TCP::Option*)opt; switch(option->kind) { case Option::END: { return; } case Option::NOP: { opt++; break; } case Option::MSS: { // unlikely if(option->length != 4) throw TCPBadOptionException{Option::MSS, "length != 4"}; // unlikely if(!packet->isset(SYN)) throw TCPBadOptionException{Option::MSS, "Non-SYN packet"}; auto* opt_mss = (Option::opt_mss*)option; uint16_t mss = ntohs(opt_mss->mss); cb.SND.MSS = mss; debug2("<TCP::parse_options@Option:MSS> MSS: %u \n", mss); opt += option->length; break; } default: return; } } }