Browse code

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 authored on 22/09/2010 10:44:06
Showing 2 changed files
... ...
@@ -330,3 +330,26 @@ int is_mcast(struct ip_addr* ip)
330 330
 }
331 331
 
332 332
 #endif /* USE_MCAST */
333
+
334
+
335
+
336
+/** get protocol name (asciiz).
337
+ * @param proto - protocol number
338
+ * @return  string with the protocol name or "unknown".
339
+ */
340
+char* proto2a(enum sip_protos proto)
341
+{
342
+	switch(proto){
343
+		case PROTO_NONE:
344
+			return "*";
345
+		case PROTO_UDP:
346
+			return "udp";
347
+		case PROTO_TCP:
348
+			return "tcp";
349
+		case PROTO_TLS:
350
+			return "tls";
351
+		case PROTO_SCTP:
352
+			return "sctp";
353
+	}
354
+	return "unknown";
355
+}
... ...
@@ -250,6 +250,10 @@ void print_ip(char* prefix, struct ip_addr* ip, char* suffix);
250 250
 void stdout_print_ip(struct ip_addr* ip);
251 251
 void print_net(struct net* net);
252 252
 
253
+char* proto2a(enum sip_protos proto);
254
+
255
+
256
+
253 257
 #ifdef USE_MCAST
254 258
 /* Returns 1 if the given address is a multicast address */
255 259
 int is_mcast(struct ip_addr* ip);