pjsip cli: Change Identify to show CIDR notation instead of netmasks.

* Added ast_sockaddr_cidr_bits() to count the 1 bits in an ast_sockaddr.
* Added ast_ha_join_cidr() which uses ast_sockaddr_cidr_bits() for the netmask
  instead of ast_sockaddr_stringify_addr.
* Changed res_pjsip_endpoint_identifier_ip to call ast_ha_join_cidr() instead
  of ast_ha_join() for the CLI output.

This is a CLI change only.  AMI was not affected.

Tested by: George Joseph
Review: https://reviewboard.asterisk.org/r/3652/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@416737 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
George Joseph
2014-06-19 20:12:15 +00:00
parent 252187f955
commit 43e0a4ddea
5 changed files with 65 additions and 1 deletions

View File

@@ -129,6 +129,40 @@ char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *sa, int format)
return ast_str_buffer(str);
}
int ast_sockaddr_cidr_bits(const struct ast_sockaddr *sa)
{
struct ast_sockaddr sa_ipv4;
const struct ast_sockaddr *sa_tmp;
int bits = 0;
int bytes;
int i;
int j;
char *addr;
if (ast_sockaddr_isnull(sa)) {
return 0;
}
if (ast_sockaddr_ipv4_mapped(sa, &sa_ipv4)) {
sa_tmp = &sa_ipv4;
} else {
sa_tmp = sa;
}
bytes = sa_tmp->len;
addr = ((struct sockaddr *)&sa_tmp->ss)->sa_data;
for (i = 0; i < bytes ; ++i) {
for (j = 0; j < 8; ++j) {
if ((addr[i] >> j) & 1) {
bits++;
}
}
}
return bits;
}
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
{
char *s = str;