diff options
author | Toshiki Nishioka <toshiki.nishioka@intel.com> | 2017-05-24 06:56:15 +0200 |
---|---|---|
committer | Toshiki Nishioka <toshiki.nishioka@intel.com> | 2017-05-24 07:10:36 +0200 |
commit | 179b4a64f4db5179bf7694f3bf30042b1ade5262 (patch) | |
tree | 47b95b0b6fb63dc9759445ac998652ca5c7630b1 /daemons | |
parent | 8fb233d7c7c70acae6e19e6a02ff96a8dce77cfd (diff) | |
download | Open-AVB-179b4a64f4db5179bf7694f3bf30042b1ade5262.tar.gz |
gPTP: fix SIOCGIFNAME ioctl failure
Use an INET socket rather than a NETLINK socket to get link speed
with ioctl() since NETLINK sockets do not support ioctl().
Diffstat (limited to 'daemons')
-rw-r--r-- | daemons/gptp/linux/src/linux_hal_common.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/daemons/gptp/linux/src/linux_hal_common.cpp b/daemons/gptp/linux/src/linux_hal_common.cpp index 1000a265..f31901eb 100644 --- a/daemons/gptp/linux/src/linux_hal_common.cpp +++ b/daemons/gptp/linux/src/linux_hal_common.cpp @@ -310,6 +310,7 @@ void LinuxNetworkInterface::watchNetLink( CommonPort *iPort ) { fd_set netLinkFD; int netLinkSocket; + int inetSocket; struct sockaddr_nl addr; EtherPort *pPort = @@ -334,6 +335,20 @@ void LinuxNetworkInterface::watchNetLink( CommonPort *iPort ) if (bind (netLinkSocket, (struct sockaddr *) &addr, sizeof (addr)) < 0) { GPTP_LOG_ERROR("Socket bind failed"); + close (netLinkSocket); + return; + } + + /* + * Open an INET family socket to be passed to getLinkSpeed() which calls + * ioctl() because NETLINK sockets do not support ioctl(). Since we will + * enter an infinite loop, there are no apparent close() calls for the + * open sockets, but they will be closed on process termination. + */ + inetSocket = socket (AF_INET, SOCK_STREAM, 0); + if (inetSocket < 0) { + GPTP_LOG_ERROR("watchNetLink error opening socket: %s", strerror(errno)); + close (netLinkSocket); return; } @@ -341,7 +356,7 @@ void LinuxNetworkInterface::watchNetLink( CommonPort *iPort ) if( pPort->getLinkUpState() ) { uint32_t link_speed; - getLinkSpeed( netLinkSocket, &link_speed ); + getLinkSpeed( inetSocket, &link_speed ); pPort->setLinkSpeed((int32_t) link_speed ); } else { @@ -367,7 +382,7 @@ void LinuxNetworkInterface::watchNetLink( CommonPort *iPort ) if( pPort->getLinkUpState() ) { uint32_t link_speed; - getLinkSpeed( netLinkSocket, &link_speed ); + getLinkSpeed( inetSocket, &link_speed ); pPort->setLinkSpeed((int32_t) link_speed ); } else { |