ranap_common: Add helper function to get IP from transport layer addr

This commit is contained in:
Daniel Willmann 2016-02-04 18:00:36 +01:00
parent 49f99cd265
commit 4870b995ec
2 changed files with 18 additions and 0 deletions

View File

@ -634,3 +634,4 @@ RANAP_ProtocolIE_FieldPair_t *ranap_new_ie_pair(RANAP_ProtocolIE_ID_t id,
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);

View File

@ -523,3 +523,20 @@ void ranap_set_log_area(int log_area)
{
_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;
}