Module: sip-router Branch: master Commit: 10117562935ffef52126cce5b290213e327442bb URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=10117562...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Wed Sep 22 12:44:06 2010 +0200
core: function for getting the name of a protocol
Added a new function to ip_addr.h, for converting the internal protocol number to an ascii name (proto2a(...)).
---
ip_addr.c | 23 +++++++++++++++++++++++ ip_addr.h | 4 ++++ 2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/ip_addr.c b/ip_addr.c index 5651809..331bfaa 100644 --- a/ip_addr.c +++ b/ip_addr.c @@ -330,3 +330,26 @@ int is_mcast(struct ip_addr* ip) }
#endif /* USE_MCAST */ + + + +/** get protocol name (asciiz). + * @param proto - protocol number + * @return string with the protocol name or "unknown". + */ +char* proto2a(enum sip_protos proto) +{ + switch(proto){ + case PROTO_NONE: + return "*"; + case PROTO_UDP: + return "udp"; + case PROTO_TCP: + return "tcp"; + case PROTO_TLS: + return "tls"; + case PROTO_SCTP: + return "sctp"; + } + return "unknown"; +} diff --git a/ip_addr.h b/ip_addr.h index d751781..2f04693 100644 --- a/ip_addr.h +++ b/ip_addr.h @@ -250,6 +250,10 @@ void print_ip(char* prefix, struct ip_addr* ip, char* suffix); void stdout_print_ip(struct ip_addr* ip); void print_net(struct net* net);
+char* proto2a(enum sip_protos proto); + + + #ifdef USE_MCAST /* Returns 1 if the given address is a multicast address */ int is_mcast(struct ip_addr* ip);