Преглед изворни кода

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(...)).
Andrei Pelinescu-Onciul пре 15 година
родитељ
комит
1011756293
2 измењених фајлова са 27 додато и 0 уклоњено
  1. 23 0
      ip_addr.c
  2. 4 0
      ip_addr.h

+ 23 - 0
ip_addr.c

@@ -330,3 +330,26 @@ int is_mcast(struct ip_addr* ip)
 }
 }
 
 
 #endif /* USE_MCAST */
 #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";
+}

+ 4 - 0
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 stdout_print_ip(struct ip_addr* ip);
 void print_net(struct net* net);
 void print_net(struct net* net);
 
 
+char* proto2a(enum sip_protos proto);
+
+
+
 #ifdef USE_MCAST
 #ifdef USE_MCAST
 /* Returns 1 if the given address is a multicast address */
 /* Returns 1 if the given address is a multicast address */
 int is_mcast(struct ip_addr* ip);
 int is_mcast(struct ip_addr* ip);