ncsid: Fix if_packet warnings
The new Docker CI now hits the following error.
```
/usr/include/linux/if_packet.h:24:17: error: flexible array member 'sockaddr_ll::<unnamed union>::<unnamed struct>::sll_addr_flex' not at end of 'class ncsi::SockIO'
24 | __DECLARE_FLEX_ARRAY(unsigned char, sll_addr_flex);
| ^~~~~~~~~~~~~~~~~~~~
../subprojects/ncsid/src/ncsi_sockio.h:55:15: note: next member 'const int ncsi::SockIO::kpoll_timeout_' declared here
55 | const int kpoll_timeout_ = 10;
| ^~~~~~~~~~~~~~
../subprojects/ncsid/src/ncsi_sockio.h:29:7: note: in the definition of 'class ncsi::SockIO'
29 | class SockIO : public net::SockIO
```
Removed the sockaddr_ll variable.
Change-Id: I67e700f6cd728bfbc822c1b8661915f8306711a1
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/subprojects/ncsid/src/ncsi_sockio.cpp b/subprojects/ncsid/src/ncsi_sockio.cpp
index 259386c..ec28c42 100644
--- a/subprojects/ncsid/src/ncsi_sockio.cpp
+++ b/subprojects/ncsid/src/ncsi_sockio.cpp
@@ -41,12 +41,7 @@
{
iface.set_sock_flags(sockfd_, IFF_PROMISC);
- std::memset(&sock_addr_, 0, sizeof(sock_addr_));
-
- sock_addr_.sll_family = AF_PACKET;
- sock_addr_.sll_protocol = htons(ETH_P_ALL);
-
- RETURN_IF_ERROR(iface.bind_sock(sockfd_, &sock_addr_),
+ RETURN_IF_ERROR(iface.bind_sock(sockfd_),
"ncsi::SockIO::bind_to_iface failed");
return 0;
diff --git a/subprojects/ncsid/src/ncsi_sockio.h b/subprojects/ncsid/src/ncsi_sockio.h
index 72cc473..6c38edd 100644
--- a/subprojects/ncsid/src/ncsi_sockio.h
+++ b/subprojects/ncsid/src/ncsi_sockio.h
@@ -19,8 +19,6 @@
#include "net_iface.h"
#include "net_sockio.h"
-#include <linux/if_packet.h>
-
#include <cstddef>
namespace ncsi
@@ -51,7 +49,6 @@
int recv(void* buf, size_t maxlen) override;
private:
- struct sockaddr_ll sock_addr_;
const int kpoll_timeout_ = 10;
};
diff --git a/subprojects/ncsid/src/net_iface.cpp b/subprojects/ncsid/src/net_iface.cpp
index f3e0732..18f9b41 100644
--- a/subprojects/ncsid/src/net_iface.cpp
+++ b/subprojects/ncsid/src/net_iface.cpp
@@ -14,7 +14,9 @@
#include "net_iface.h"
+#include <arpa/inet.h>
#include <linux/if.h>
+#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -99,17 +101,15 @@
return ::ioctl(sockfd, request, ifr);
}
-int IFace::bind_sock(int sockfd, struct sockaddr_ll* saddr) const
+int IFace::bind_sock(int sockfd) const
{
- if (saddr == nullptr)
- {
- return -1;
- }
-
- saddr->sll_ifindex = get_index();
-
- return bind(sockfd, reinterpret_cast<struct sockaddr*>(saddr),
- sizeof(*saddr));
+ struct sockaddr_ll saddr;
+ std::memset(&saddr, 0, sizeof(saddr));
+ saddr.sll_family = AF_PACKET;
+ saddr.sll_protocol = htons(ETH_P_ALL);
+ saddr.sll_ifindex = get_index();
+ return bind(sockfd, reinterpret_cast<struct sockaddr*>(&saddr),
+ sizeof(saddr));
}
int IFace::ioctl(int request, struct ifreq* ifr) const
diff --git a/subprojects/ncsid/src/net_iface.h b/subprojects/ncsid/src/net_iface.h
index 23bcb91..a60b6e3 100644
--- a/subprojects/ncsid/src/net_iface.h
+++ b/subprojects/ncsid/src/net_iface.h
@@ -55,7 +55,7 @@
* syscall, except that it fills in sll_ifindex field
* of struct sockaddr_ll with the index of this interface.
*/
- virtual int bind_sock(int sockfd, struct sockaddr_ll* saddr) const = 0;
+ virtual int bind_sock(int sockfd) const = 0;
protected:
std::string name_;
@@ -89,7 +89,7 @@
* syscall, except that it fills in sll_ifindex field
* of struct sockaddr_ll with the index of this interface.
*/
- int bind_sock(int sockfd, struct sockaddr_ll* saddr) const override;
+ int bind_sock(int sockfd) const override;
private:
/** @brief Similar to ioctl syscall, but the socket is created inside
diff --git a/subprojects/ncsid/test/net_iface_mock.cpp b/subprojects/ncsid/test/net_iface_mock.cpp
index 5e2d223..88d3177 100644
--- a/subprojects/ncsid/test/net_iface_mock.cpp
+++ b/subprojects/ncsid/test/net_iface_mock.cpp
@@ -20,7 +20,7 @@
namespace mock
{
-int IFace::bind_sock(int sockfd, struct sockaddr_ll*) const
+int IFace::bind_sock(int sockfd) const
{
bound_socks.push_back(sockfd);
return 0;
diff --git a/subprojects/ncsid/test/net_iface_mock.h b/subprojects/ncsid/test/net_iface_mock.h
index 118ca03..a8a5be1 100644
--- a/subprojects/ncsid/test/net_iface_mock.h
+++ b/subprojects/ncsid/test/net_iface_mock.h
@@ -29,7 +29,7 @@
public:
IFace() : net::IFaceBase("mock0") {}
explicit IFace(const std::string& name) : net::IFaceBase(name) {}
- int bind_sock(int sockfd, struct sockaddr_ll* saddr) const override;
+ int bind_sock(int sockfd) const override;
mutable std::vector<int> bound_socks;
int index;