diff --git a/sys/net/network_layer/ng_ndp/ng_ndp.c b/sys/net/network_layer/ng_ndp/ng_ndp.c index d244569e74..25dc636e12 100644 --- a/sys/net/network_layer/ng_ndp/ng_ndp.c +++ b/sys/net/network_layer/ng_ndp/ng_ndp.c @@ -636,23 +636,27 @@ static uint16_t _get_l2src(uint8_t *l2src, size_t l2src_size, kernel_pid_t iface bool try_long = false; int res; uint16_t l2src_len; + /* maximum address length that fits into a minimum length (8) S/TL2A option */ + const uint16_t max_short_len = 6; /* try getting source address */ if ((ng_netapi_get(iface, NETCONF_OPT_SRC_LEN, 0, &l2src_len, sizeof(l2src_len)) >= 0) && - (l2src_len == 8)) { + (l2src_len > max_short_len)) { try_long = true; } - if ((try_long && ((res = ng_netapi_get(iface, NETCONF_OPT_ADDRESS_LONG, 0, - l2src, l2src_size)) < 0)) || - ((res = ng_netapi_get(iface, NETCONF_OPT_ADDRESS, 0, l2src, - l2src_size)) < 0)) { - DEBUG("ndp: no link-layer address found.\n"); - l2src_len = 0; + if (try_long && ((res = ng_netapi_get(iface, NETCONF_OPT_ADDRESS_LONG, 0, + l2src, l2src_size)) > max_short_len)) { + l2src_len = (uint16_t)res; + } + else if ((res = ng_netapi_get(iface, NETCONF_OPT_ADDRESS, 0, l2src, + l2src_size)) >= 0) { + l2src_len = (uint16_t)res; } else { - l2src_len = (uint16_t)res; + DEBUG("ndp: no link-layer address found.\n"); + l2src_len = 0; } return l2src_len;