Skip to content

Instantly share code, notes, and snippets.

@kota65535
Last active November 23, 2015 04:41
Show Gist options
  • Save kota65535/e4717e61df1df33e49c1 to your computer and use it in GitHub Desktop.
Save kota65535/e4717e61df1df33e49c1 to your computer and use it in GitHub Desktop.
SSDP:Discoverに利用するブロードキャストアドレスの経路追加 (Linux版, Raspberry Pi対応)
#!/bin/bash
set -u
export LANG="C"
function usage() {
cat <<EOT
Usage: bash ${0##*/} <interface-name>
EOT
}
# 引数チェック
if [ $# -ne 1 ]; then usage && exit 1; fi
# SSDP discoverで使用するブロードキャストアドレス
SSDP_ADDR=239.255.255.250
# 所定のインターフェース経由の経路があるか調べる
ip route get ${SSDP_ADDR} | grep -q "dev $1"
if [ $? -eq 0 ]; then
echo 'Route already configured.'
exit 0
fi
# 所定のインターフェース経由の経路を追加する
route add -host ${SSDP_ADDR} dev $1
if [ $? -ne 0 ]; then
echo "Failed to add route to host ${SSDP_ADDR} via $1"
exit 1
fi
# 最後に再度確認
ip route get ${SSDP_ADDR} | grep -q "dev $1"
if [ $? -ne 0 ]; then
echo "Something goes wrong!"
exit 2
fi
echo 'Route added successfully.'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment