diff --git a/dataformats.c b/dataformats.c index 21132ce9..4f6b9012 100644 --- a/dataformats.c +++ b/dataformats.c @@ -58,10 +58,10 @@ int is_xstring(const char *text, int len) } /* Does this whole buffer contain the same value? */ -int is_all_matching(unsigned char *ptr, int len, int value){ - int i; - for (i=0;iout.dst.sid)){ + if (!is_sid_broadcast(mdp->out.dst.sid)){ destination = find_subscriber(mdp->out.dst.sid, SID_SIZE, 1); } @@ -542,7 +536,7 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now) } /* If the packet was sent to broadcast, then replace broadcast address with our local address. For now just responds with first local address */ - if (is_broadcast(mdp->out.src.sid)) + if (is_sid_broadcast(mdp->out.src.sid)) { if (my_subscriber) bcopy(my_subscriber->sid, @@ -661,7 +655,7 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP, /* set source to ourselves */ frame->source = my_subscriber; bcopy(frame->source->sid, mdp->out.src.sid, SID_SIZE); - }else if (is_broadcast(mdp->out.src.sid)){ + }else if (is_sid_broadcast(mdp->out.src.sid)){ /* This is rather naughty if it happens, since broadcasting a response can lead to all manner of nasty things. Picture a packet with broadcast as the source address, sent @@ -700,7 +694,7 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP, " you can send packets")); } - if (is_broadcast(mdp->out.dst.sid)){ + if (is_sid_broadcast(mdp->out.dst.sid)){ /* broadcast packets cannot be encrypted, so complain if MDP_NOCRYPT flag is not set. Also, MDP_NOSIGN must also be applied, until NaCl cryptobox keys can be used for signing. */ diff --git a/serval.h b/serval.h index 976ad904..2402592a 100644 --- a/serval.h +++ b/serval.h @@ -458,7 +458,13 @@ int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t bytes); int hexvalue(char c); char *str_toupper_inplace(char *s); -int is_all_matching(unsigned char *ptr, int len, int value); +int is_all_matching(const unsigned char *ptr, size_t len, unsigned char value); + +// is the SID entirely 0xFF? +#define is_sid_broadcast(SID) is_all_matching(SID, SID_SIZE, 0xFF) + +// is the SID entirely 0x00? +#define is_sid_any(SID) is_all_matching(SID, SID_SIZE, 0) int str_is_subscriber_id(const char *sid); int strn_is_subscriber_id(const char *sid, size_t *lenp);