get_new_macaddr: add 1 to the mac address instead of starting from 0x14

If someone have 2 adapters with the same hardware, there is a possibility
the first 5 bytes of their mac address to be the same.
I this case we will have mac address collision if we change both of them to
XX:XX:XX:XX:XX:14, one way to avoid this is to add 1 to their last byte.

Fix #47
This commit is contained in:
oblique 2014-09-18 20:44:22 +03:00
parent ddd6bfad45
commit 5b2d7984db

View File

@ -209,8 +209,9 @@ get_virt_iface_name() {
get_new_macaddr() {
OLDMAC=$(get_macaddr "$1")
for i in {20..255}; do
NEWMAC="${OLDMAC%:*}:$(printf %02x $i)"
LAST_BYTE=$(printf %d 0x${OLDMAC##*:})
for i in {1..255}; do
NEWMAC="${OLDMAC%:*}:$(printf %02x $(( ($LAST_BYTE + $i) % 256 )))"
(ip link | grep "ether ${NEWMAC}" > /dev/null 2>&1) || break
done
echo $NEWMAC