summaryrefslogtreecommitdiffstats
path: root/dev-tools/debugging-tools/network.functions
blob: 89ca5a20d7241dd0d676868495ae2abfb3a1f40c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
wait_for_iface() {
    local DEVICE=$1
    local TIMEOUT=10
    echo -n "Waiting for interface $DEVICE: "
    # Some systems don't have operstate. Seems to be hardware dependent
    [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000
    if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then
        while true; do
            # check linkstate
            [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break
            TIMEOUT=$(( $TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working
            [ "$TIMEOUT" -le 0 ] && break
            # else
            echo -n "."
            usleep 500000
        done
    else
        # we really don't have a operstate .. then just wait a sec and hope for the best.
        sleep 1
    fi
    echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)"
}
true