mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-07 11:30:18 +00:00
cli_puts()ify "dna lookup". Add duplicate suppression to dna lookup
This commit is contained in:
parent
44d0feb575
commit
92192654d0
@ -436,6 +436,9 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
|||||||
if (create_serval_instance_dir() == -1)
|
if (create_serval_instance_dir() == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
int sid_count=0;
|
||||||
|
unsigned char sids[128][SID_SIZE];
|
||||||
|
|
||||||
const char *did;
|
const char *did;
|
||||||
if (cli_arg(argc, argv, o, "did", &did, NULL, "*") == -1)
|
if (cli_arg(argc, argv, o, "did", &did, NULL, "*") == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -444,10 +447,7 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
|||||||
unsigned char srcsid[SID_SIZE];
|
unsigned char srcsid[SID_SIZE];
|
||||||
int port=32768+(random()&32767);
|
int port=32768+(random()&32767);
|
||||||
if (overlay_mdp_getmyaddr(0,srcsid)) return WHY("Could not get local address");
|
if (overlay_mdp_getmyaddr(0,srcsid)) return WHY("Could not get local address");
|
||||||
printf("binding to %s:%d\n",
|
|
||||||
overlay_render_sid(srcsid),port);
|
|
||||||
if (overlay_mdp_bind(srcsid,port)) return WHY("Could not bind to MDP socket");
|
if (overlay_mdp_bind(srcsid,port)) return WHY("Could not bind to MDP socket");
|
||||||
WHY("bound port");
|
|
||||||
|
|
||||||
/* use MDP to send the lookup request to MDP_PORT_DNALOOKUP, and wait for
|
/* use MDP to send the lookup request to MDP_PORT_DNALOOKUP, and wait for
|
||||||
replies. */
|
replies. */
|
||||||
@ -494,10 +494,22 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
|||||||
{
|
{
|
||||||
fprintf(stderr," Error message: %s\n",mdp.error.message);
|
fprintf(stderr," Error message: %s\n",mdp.error.message);
|
||||||
}
|
}
|
||||||
else if ((rx.packetTypeAndFlags&MDP_TYPE_MASK)==MDP_TX)
|
else if ((rx.packetTypeAndFlags&MDP_TYPE_MASK)==MDP_TX) {
|
||||||
fprintf(stderr,"%s:%s\n",
|
/* Display match unless it is a duplicate.
|
||||||
overlay_render_sid(&rx.in.src.sid[0]),
|
XXX - For wildcard searches, each sid will only show up once. */
|
||||||
&rx.in.payload[0]);
|
int i;
|
||||||
|
for(i=0;i<sid_count;i++)
|
||||||
|
if (!bcmp(&rx.in.src.sid[0],&sids[i][0],SID_SIZE))
|
||||||
|
break;
|
||||||
|
if (i==sid_count) {
|
||||||
|
cli_puts(overlay_render_sid(&rx.in.src.sid[0])); cli_delim(":");
|
||||||
|
cli_puts((char *)&rx.in.payload[0]); cli_delim("\n");
|
||||||
|
if (sid_count<128) {
|
||||||
|
bcopy(&rx.in.src.sid[0],&sids[i][0],SID_SIZE);
|
||||||
|
sid_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else WHYF("packettype=0x%x",rx.packetTypeAndFlags);
|
else WHYF("packettype=0x%x",rx.packetTypeAndFlags);
|
||||||
if (servalShutdown) break;
|
if (servalShutdown) break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user