1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00

new format chars in formatted output.

This commit is contained in:
Alexandre Snarskii
2015-09-23 19:29:08 +03:00
parent aed1554fca
commit 2df0a54811
5 changed files with 54 additions and 6 deletions

View File

@ -1,12 +1,17 @@
untagged yet (2015-07-13)
untagged yet (2015-09-23)
- bugfix: stoplist shall be able to catch AS numbers as promised.
- bugfix: bgpq3 shall not hang at unknown escapes in -M..
- gotcha: "ANY" object in recursive mode ignored: shut complaints on
"ERROR:unexpected object 'ANY' in expanded_macro_limit (in response
to !iAS-SET-SCOPESKY)" (object contains mbrs-by-ref: ANY).
(additions from 2015-08-30)
- bugfix: OpenBSD sys/queue.h does not have STAILQ_ interface. Untested yet.
- bugfix: OpenBSD sys/queue.h does not have STAILQ_ interface.
Thanks to Pedro Caetano for reporting and testing.
- feature: alternate whois port can be configured with -h host[:port]
- feature: new format char %N (object name) in formatted output.
Thanks to Denis Fondras.
- feature: new format chars %m (prefix mask) and %i (inverse mask) in
formatted output.
0.1.32-rc5 (2015-07-12)
- feature: -L <depth>: limit recursion depth when expanding as-sets

View File

@ -271,7 +271,8 @@ example below:
ipfw add pass all from 91.219.30.0/24 to any
ipfw add pass all from 193.193.192.0/19 to any
Recognized format characters: '%n' - network, '%l' - mask length.
Recognized format characters: '%n' - network, '%l' - mask length,
'%N' - object name, '%m' - object mask and '%i' - inversed mask.
Recognized escape characters: '\n' - new line, '\t' - tabulation.
Please note that no new lines inserted automatically after each sentence,
you have to add them into format string manually, elsewhere output will

View File

@ -646,7 +646,8 @@ bgpq3_print_format_prefix(struct sx_radix_node* n, void* ff)
if(!f)
f=stdout;
memset(prefix, 0, sizeof(prefix));
sx_prefix_snprintf_fmt(&n->prefix, prefix, sizeof(prefix), b->format);
sx_prefix_snprintf_fmt(&n->prefix, prefix, sizeof(prefix),
b->name?b->name:"NN", b->format);
fprintf(f, "%s", prefix);
};

View File

@ -47,6 +47,33 @@ sx_prefix_adjust_masklen(struct sx_prefix* p)
};
};
void
sx_prefix_mask(struct sx_prefix* p, struct sx_prefix* q)
{
int i;
memset(q->addr.addrs, 0, sizeof(q->addr.addrs));
q->family=p->family;
q->masklen=p->masklen;
for(i=0;i<p->masklen/8;i++)
q->addr.addrs[i]=0xff;
for(i=1;i<=p->masklen%8;i++)
q->addr.addrs[p->masklen/8]|=(1<<(8-i));
};
void
sx_prefix_imask(struct sx_prefix* p, struct sx_prefix* q)
{
int i;
memset(q->addr.addrs, 0xff, sizeof(q->addr.addrs));
q->family=p->family;
q->masklen=p->masklen;
for(i=0;i<p->masklen/8;i++)
q->addr.addrs[i]=0;
for(i=1;i<=p->masklen%8;i++)
q->addr.addrs[p->masklen/8]&=~(1<<(8-i));
};
int
sx_prefix_parse(struct sx_prefix* p, int af, char* text)
{
@ -266,10 +293,11 @@ sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb)
int
sx_prefix_snprintf_fmt(struct sx_prefix* p, char* buffer, int size,
const char* format)
const char* name, const char* format)
{
unsigned off=0;
const char* c=format;
struct sx_prefix q;
while(*c) {
if(*c=='%') {
switch(*(c+1)) {
@ -284,6 +312,19 @@ sx_prefix_snprintf_fmt(struct sx_prefix* p, char* buffer, int size,
case '%':
buffer[off++]='%';
break;
case 'N':
off+=snprintf(buffer+off,size-off,"%s",name);
break;
case 'm':
sx_prefix_mask(p, &q);
inet_ntop(p->family,&q.addr,buffer+off,size-off);
off=strlen(buffer);
break;
case 'i':
sx_prefix_imask(p, &q);
inet_ntop(p->family,&q.addr,buffer+off,size-off);
off=strlen(buffer);
break;
default :
sx_report(SX_ERROR, "Unknown format char '%c'\n", *(c+1));
return 0;

View File

@ -50,7 +50,7 @@ int sx_prefix_range_parse(struct sx_radix_tree* t, int af, int ml, char* text);
int sx_prefix_fprint(FILE* f, struct sx_prefix* p);
int sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb);
int sx_prefix_snprintf_fmt(struct sx_prefix* p, char* rbuffer, int srb,
const char* fmt);
const char* name, const char* fmt);
int sx_prefix_jsnprintf(struct sx_prefix* p, char* rbuffer, int srb);
struct sx_radix_tree* sx_radix_tree_new(int af);
struct sx_radix_node* sx_radix_node_new(struct sx_prefix* prefix);