util: Add a method to compare binary addresses.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
40480f3b28
commit
bc18131d27
28
util.c
28
util.c
|
@ -69,6 +69,34 @@ const char *ev_str[] = {
|
|||
"RS_PASSIVE",
|
||||
};
|
||||
|
||||
int addreq(enum transport_type type, struct address *a, struct address *b)
|
||||
{
|
||||
void *bufa, *bufb;
|
||||
int len;
|
||||
|
||||
switch (type) {
|
||||
case TRANS_UDP_IPV4:
|
||||
bufa = &a->sin.sin_addr;
|
||||
bufb = &b->sin.sin_addr;
|
||||
len = sizeof(a->sin);
|
||||
break;
|
||||
case TRANS_IEEE_802_3:
|
||||
bufa = &a->sll.sll_addr;
|
||||
bufb = &b->sll.sll_addr;
|
||||
len = MAC_LEN;
|
||||
break;
|
||||
case TRANS_UDS:
|
||||
case TRANS_UDP_IPV6:
|
||||
case TRANS_DEVICENET:
|
||||
case TRANS_CONTROLNET:
|
||||
case TRANS_PROFINET:
|
||||
default:
|
||||
pr_err("sorry, cannot compare addresses for this transport");
|
||||
return 0;
|
||||
}
|
||||
return memcmp(bufa, bufb, len) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
char *bin2str_impl(Octet *data, int len, char *buf, int buf_len)
|
||||
{
|
||||
int i, offset = 0;
|
||||
|
|
9
util.h
9
util.h
|
@ -41,6 +41,15 @@ extern const char *ps_str[];
|
|||
*/
|
||||
extern const char *ev_str[];
|
||||
|
||||
/**
|
||||
* Compares two binary addresses for equality.
|
||||
* @param type One of the enumerated transport types.
|
||||
* @param a One address to compare.
|
||||
* @param b The second address to compare.
|
||||
* @return One if the addresses are identical, zero otherwise.
|
||||
*/
|
||||
int addreq(enum transport_type type, struct address *a, struct address *b);
|
||||
|
||||
static inline uint16_t align16(uint16_t *p)
|
||||
{
|
||||
uint16_t v;
|
||||
|
|
Loading…
Reference in New Issue