ranap_common: Add helper function to get IP from transport layer addr
diff --git a/include/osmocom/ranap/ranap_common.h b/include/osmocom/ranap/ranap_common.h
index 229d134..b7682e5 100644
--- a/include/osmocom/ranap/ranap_common.h
+++ b/include/osmocom/ranap/ranap_common.h
@@ -634,3 +634,4 @@
 void ranap_set_log_area(int log_area);
 
 int ranap_parse_lai(struct gprs_ra_id *ra_id, const RANAP_LAI_t *lai);
+int ranap_ip_from_transp_layer_addr(const BIT_STRING_t *in, uint32_t *ip);
diff --git a/src/ranap_common.c b/src/ranap_common.c
index 4bd088c..f2fdf9d 100644
--- a/src/ranap_common.c
+++ b/src/ranap_common.c
@@ -523,3 +523,20 @@
 {
 	_ranap_DRANAP = log_area;
 }
+
+int ranap_ip_from_transp_layer_addr(const BIT_STRING_t *in, uint32_t *ip)
+{
+	uint32_t addr;
+	uint8_t x213[] = {0x35, 0x00, 0x01};
+
+	/* Only support IPv4 for now - plain and with x213 encapsulation */
+	if (in->size == 4)
+		*ip = *(uint32_t *)in->buf;
+	else if ((in->size == 7) && !memcmp(in->buf, x213, sizeof(x213)))
+		*ip = htonl(*(uint32_t *)&in->buf[3]);
+	else
+		return -1;
+
+	return 0;
+
+}