Set the default port state and reason whenever PortList::createPort is

called. Formerly the only way to create a port was to call
PortList::addPort, which also set the state. Now ports are allocated on
demand whenever anything about a port is set. If we don't set the state
and reason, they're "unknown" and "unknown-reason". Because of the
special handling of PORT_UNKNOWN in the output table, this could lead to
an assertion failure reported by Jon Kibler.
This commit is contained in:
david 2010-01-21 23:40:10 +00:00
parent 349f0edad0
commit f1551332be

View file

@ -662,6 +662,7 @@ const Port *PortList::lookupPort(u16 portno, u8 protocol) const {
/* Create the port if it doesn't exist; otherwise this is like lookupPort. */
Port *PortList::createPort(u16 portno, u8 protocol) {
Port *p;
u16 mapped_portno;
u8 mapped_protocol;
@ -670,10 +671,13 @@ Port *PortList::createPort(u16 portno, u8 protocol) {
if (!mapPort(&mapped_portno, &mapped_protocol))
return NULL;
if (port_list[mapped_protocol][mapped_portno] == NULL) {
Port *p = new Port();
p = port_list[mapped_protocol][mapped_portno];
if (p == NULL) {
p = new Port();
p->portno = portno;
p->proto = protocol;
p->state = default_port_state[mapped_protocol].state;
p->reason.reason_id = ER_NORESPONSE;
port_list[mapped_protocol][mapped_portno] = p;
}