lib/proto/conv: Introduce API ogs_ip_to_paa()

The counterpart API ogs_paa_to_ip() was already present, but this was
missing. It will be required in open5gs-mmed in a follow-up patch.
This commit is contained in:
Pau Espin 2024-01-05 20:23:00 +01:00 committed by Sukchan Lee
parent 4ab275ad70
commit 7d60b13d3a
2 changed files with 18 additions and 0 deletions

View File

@ -69,3 +69,20 @@ int ogs_paa_to_ip(const ogs_paa_t *paa, ogs_ip_t *ip)
return OGS_OK;
}
int ogs_ip_to_paa(const ogs_ip_t *ip, ogs_paa_t *paa)
{
if (ip->ipv4 && ip->ipv6) {
paa->session_type = OGS_PDU_SESSION_TYPE_IPV4V6;
paa->both.addr = ip->addr;
memcpy(paa->both.addr6, ip->addr6, OGS_IPV6_LEN);
} else if (ip->ipv6) {
paa->session_type = OGS_PDU_SESSION_TYPE_IPV6;
memcpy(paa->addr6, ip->addr6, OGS_IPV6_LEN);
} else if (ip->ipv4) {
paa->session_type = OGS_PDU_SESSION_TYPE_IPV4;
paa->addr = ip->addr;
} else {
return OGS_ERROR;
}
return OGS_OK;
}

View File

@ -31,6 +31,7 @@ extern "C" {
void ogs_extract_digit_from_string(char *digit, char *string);
int ogs_paa_to_ip(const ogs_paa_t *paa, ogs_ip_t *ip);
int ogs_ip_to_paa(const ogs_ip_t *ip, ogs_paa_t *paa);
#ifdef __cplusplus
}