Added a new function to ip_addr.h, for converting the internal protocol number to an ascii name (proto2a(...)).
@@ -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";
+}
@@ -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);