add osmo_sccp_addr_to_id_c()
Change-Id: Iadd34a167a7712796b2501f6a75b5a8d26a828eb
This commit is contained in:
parent
134e463230
commit
7a4f614ba9
|
@ -63,5 +63,9 @@ int osmo_sccp_addr_to_str_buf(char *buf, size_t buf_len, const struct osmo_ss7_i
|
|||
const struct osmo_sccp_addr *addr);
|
||||
char *osmo_sccp_addr_to_str_c(void *ctx, const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr);
|
||||
|
||||
int osmo_sccp_addr_to_id_buf(char *buf, size_t buf_len, const struct osmo_ss7_instance *ss7,
|
||||
const struct osmo_sccp_addr *addr);
|
||||
char *osmo_sccp_addr_to_id_c(void *ctx, const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr);
|
||||
|
||||
char *osmo_sccp_addr_name(const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr);
|
||||
char *osmo_sccp_inst_addr_name(const struct osmo_sccp_instance *sccp, const struct osmo_sccp_addr *addr);
|
||||
|
|
|
@ -311,8 +311,8 @@ char *osmo_sccp_addr_dump(const struct osmo_sccp_addr *addr)
|
|||
return buf;
|
||||
}
|
||||
|
||||
int osmo_sccp_addr_to_str_buf(char *buf, size_t buf_len, const struct osmo_ss7_instance *ss7,
|
||||
const struct osmo_sccp_addr *addr)
|
||||
static int sccp_addr_to_str_buf(char *buf, size_t buf_len, const struct osmo_ss7_instance *ss7,
|
||||
const struct osmo_sccp_addr *addr, char sep_char)
|
||||
{
|
||||
struct osmo_strbuf sb = { .buf = buf, .len = buf_len };
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
@ -320,26 +320,53 @@ int osmo_sccp_addr_to_str_buf(char *buf, size_t buf_len, const struct osmo_ss7_i
|
|||
OSMO_STRBUF_PRINTF(sb, "RI=%s", osmo_sccp_routing_ind_name(addr->ri));
|
||||
|
||||
if (addr->presence & OSMO_SCCP_ADDR_T_PC)
|
||||
OSMO_STRBUF_PRINTF(sb, ",PC=%s", osmo_ss7_pointcode_print(ss7, addr->pc));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cPC=%s", sep_char, osmo_ss7_pointcode_print(ss7, addr->pc));
|
||||
if (addr->presence & OSMO_SCCP_ADDR_T_SSN)
|
||||
OSMO_STRBUF_PRINTF(sb, ",SSN=%s", osmo_sccp_ssn_name(addr->ssn));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cSSN=%s", sep_char, osmo_sccp_ssn_name(addr->ssn));
|
||||
if (addr->presence & OSMO_SCCP_ADDR_T_IPv4)
|
||||
OSMO_STRBUF_PRINTF(sb, ",IP=%s", inet_ntop(AF_INET, &addr->ip.v4, ipbuf, sizeof(ipbuf)));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cIP=%s", sep_char, inet_ntop(AF_INET, &addr->ip.v4, ipbuf, sizeof(ipbuf)));
|
||||
else if (addr->presence & OSMO_SCCP_ADDR_T_IPv6)
|
||||
OSMO_STRBUF_PRINTF(sb, ",IP=%s", inet_ntop(AF_INET6, &addr->ip.v6, ipbuf, sizeof(ipbuf)));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cIP=%s", sep_char, inet_ntop(AF_INET6, &addr->ip.v6, ipbuf, sizeof(ipbuf)));
|
||||
if (addr->gt.gti != OSMO_SCCP_GTI_NO_GT || addr->presence & OSMO_SCCP_ADDR_T_GT)
|
||||
OSMO_STRBUF_PRINTF(sb, ",GTI=%s", osmo_sccp_gti_name(addr->gt.gti));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cGTI=%s", sep_char, osmo_sccp_gti_name(addr->gt.gti));
|
||||
if (addr->presence & OSMO_SCCP_ADDR_T_GT)
|
||||
OSMO_STRBUF_PRINTF(sb, ",GT=(%s)", osmo_sccp_gt_dump(&addr->gt));
|
||||
OSMO_STRBUF_PRINTF(sb, "%cGT=(%s)", sep_char, osmo_sccp_gt_dump(&addr->gt));
|
||||
|
||||
return sb.chars_needed;
|
||||
}
|
||||
|
||||
int osmo_sccp_addr_to_str_buf(char *buf, size_t buf_len, const struct osmo_ss7_instance *ss7,
|
||||
const struct osmo_sccp_addr *addr)
|
||||
{
|
||||
return sccp_addr_to_str_buf(buf, buf_len, ss7, addr, ',');
|
||||
}
|
||||
|
||||
char *osmo_sccp_addr_to_str_c(void *ctx, const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr)
|
||||
{
|
||||
OSMO_NAME_C_IMPL(ctx, 64, "ERROR", osmo_sccp_addr_to_str_buf, ss7, addr)
|
||||
}
|
||||
|
||||
/*! like osmo_sccp_addr_to_str_buf, but using only characters passing osmo_identifier_valid(). Useful for FSM and CTRL
|
||||
* IDs.
|
||||
*
|
||||
* The advantage over using osmo_sccp_addr_to_str_buf() followed by osmo_identifier_sanitize_buf() is that here, the
|
||||
* address elements are separated by ':', while osmo_identifier_sanitize_buf() would replace all characters with the
|
||||
* same, e.g. '-'.
|
||||
*/
|
||||
int osmo_sccp_addr_to_id_buf(char *buf, size_t buf_len, const struct osmo_ss7_instance *ss7,
|
||||
const struct osmo_sccp_addr *addr)
|
||||
{
|
||||
int rc = sccp_addr_to_str_buf(buf, buf_len, ss7, addr, ':');
|
||||
/* inet_ntop() and osmo_sccp_gt_dump() may have written non-id chars. */
|
||||
osmo_identifier_sanitize_buf(buf, "", '-');
|
||||
return rc;
|
||||
}
|
||||
|
||||
char *osmo_sccp_addr_to_id_c(void *ctx, const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr)
|
||||
{
|
||||
OSMO_NAME_C_IMPL(ctx, 64, "ERROR", osmo_sccp_addr_to_id_buf, ss7, addr)
|
||||
}
|
||||
|
||||
/* Rather use osmo_sccp_addr_to_str_buf() or osmo_sccp_addr_to_str_c() to not use a static buffer */
|
||||
char *osmo_sccp_addr_name(const struct osmo_ss7_instance *ss7, const struct osmo_sccp_addr *addr)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue