Browse code

core: helper function to get address family name

Daniel-Constantin Mierla authored on 16/09/2022 14:42:16
Showing 2 changed files
... ...
@@ -717,6 +717,22 @@ char* get_proto_name(unsigned int proto)
717 717
 	}
718 718
 }
719 719
 
720
+/** get address family name (asciiz).
721
+ * @param af - address family id
722
+ * @return  string with the adderess family name or "unknown".
723
+ */
724
+char* get_af_name(unsigned int af)
725
+{
726
+	switch(af) {
727
+		case AF_INET:
728
+			return "IPv4";
729
+		case AF_INET6:
730
+			return "IPv6";
731
+		default:
732
+			return "unknown";
733
+	}
734
+}
735
+
720 736
 
721 737
 /**
722 738
  * match ip address with net address and bitmask
... ...
@@ -304,6 +304,8 @@ char* get_proto_name(unsigned int proto);
304 304
 int get_valid_proto_string(unsigned int iproto, int utype, int vtype,
305 305
 		str *sproto);
306 306
 
307
+char* get_af_name(unsigned int af);
308
+
307 309
 #ifdef USE_MCAST
308 310
 /* Returns 1 if the given address is a multicast address */
309 311
 int is_mcast(struct ip_addr* ip);