diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2006-11-02 07:51:53 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2006-11-02 07:51:53 +0000 |
commit | 3b62f53fa465ce1a57bc18a244ac14d002c6be77 (patch) | |
tree | 2625a4d11858add84674928559a3ddad0dc19945 /src | |
parent | 5661bf86239bbd307070ca3c0255e0b2ebbb67ac (diff) | |
download | strongswan-3b62f53fa465ce1a57bc18a244ac14d002c6be77.tar.bz2 strongswan-3b62f53fa465ce1a57bc18a244ac14d002c6be77.tar.xz |
fixed output of proto/port selectors
Diffstat (limited to 'src')
-rw-r--r-- | src/charon/config/traffic_selector.c | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/src/charon/config/traffic_selector.c b/src/charon/config/traffic_selector.c index 2361f67f4..2b99b9180 100644 --- a/src/charon/config/traffic_selector.c +++ b/src/charon/config/traffic_selector.c @@ -160,11 +160,10 @@ static int print(FILE *stream, const struct printf_info *info, { private_traffic_selector_t *this = *((private_traffic_selector_t**)(args[0])); char addr_str[INET6_ADDRSTRLEN] = ""; - u_int8_t mask; - struct protoent *proto; - struct servent *serv; char *serv_proto = NULL; - bool has_proto = FALSE; + u_int8_t mask; + bool has_proto; + bool has_ports; size_t written = 0; if (this == NULL) @@ -184,56 +183,62 @@ static int print(FILE *stream, const struct printf_info *info, written += fprintf(stream, "%s/%d", addr_str, mask); + /* check if we have protocol and/or port selectors */ + has_proto = this->protocol != 0; + has_ports = !(this->from_port == 0 && this->to_port == 0xFFFF); + + if (!has_proto && !has_ports) + { + return written; + } + + written += fprintf(stream, "["); + /* build protocol string */ - if (this->protocol) + if (has_proto) { - proto = getprotobynumber(this->protocol); + struct protoent *proto = getprotobynumber(this->protocol); + if (proto) { - written += fprintf(stream, "[%s", proto->p_name); + written += fprintf(stream, "%s", proto->p_name); serv_proto = proto->p_name; } else { - written += fprintf(stream, "[%d", this->protocol); + written += fprintf(stream, "%d", this->protocol); } - has_proto = TRUE; } - /* build port string */ - if (this->from_port == this->to_port) + if (has_proto && has_ports) { - if (has_proto) - { - written += fprintf(stream, "/"); - } - else - { - written += fprintf(stream, "["); - } - serv = getservbyport(htons(this->from_port), serv_proto); - if (serv) - { - written += fprintf(stream, "%s]", serv->s_name); - } - else - { - written += fprintf(stream, "%d]", this->from_port); - } + written += fprintf(stream, "/"); } - else if (!(this->from_port == 0 && this->to_port == 0xFFFF)) + + /* build port string */ + if (has_ports) { - if (has_proto) + if (this->from_port == this->to_port) { - written += fprintf(stream, "/"); + struct servent *serv = getservbyport(htons(this->from_port), serv_proto); + + if (serv) + { + written += fprintf(stream, "%s", serv->s_name); + } + else + { + written += fprintf(stream, "%d", this->from_port); + } } else { - written += fprintf(stream, "["); + written += fprintf(stream, "%d-%d", this->from_port, this->to_port); } - written += fprintf(stream, "%d-%d]", this->from_port, this->to_port); } + written += fprintf(stream, "]"); + return written; } |