Forráskód Böngészése

core: helper function to get address family name

Daniel-Constantin Mierla 3 éve
szülő
commit
8bdee74fa6
2 módosított fájl, 18 hozzáadás és 0 törlés
  1. 16 0
      src/core/ip_addr.c
  2. 2 0
      src/core/ip_addr.h

+ 16 - 0
src/core/ip_addr.c

@@ -717,6 +717,22 @@ char* get_proto_name(unsigned int proto)
 	}
 }
 
+/** get address family name (asciiz).
+ * @param af - address family id
+ * @return  string with the adderess family name or "unknown".
+ */
+char* get_af_name(unsigned int af)
+{
+	switch(af) {
+		case AF_INET:
+			return "IPv4";
+		case AF_INET6:
+			return "IPv6";
+		default:
+			return "unknown";
+	}
+}
+
 
 /**
  * match ip address with net address and bitmask

+ 2 - 0
src/core/ip_addr.h

@@ -304,6 +304,8 @@ char* get_proto_name(unsigned int proto);
 int get_valid_proto_string(unsigned int iproto, int utype, int vtype,
 		str *sproto);
 
+char* get_af_name(unsigned int af);
+
 #ifdef USE_MCAST
 /* Returns 1 if the given address is a multicast address */
 int is_mcast(struct ip_addr* ip);