1 #pragma once 2 3 #include "net_iface.h" 4 #include "net_sockio.h" 5 6 #include <sys/socket.h> 7 8 #include <cstddef> 9 #include <cstring> 10 11 namespace ncsi 12 { 13 14 class SockIO : public net::SockIO 15 { 16 public: 17 SockIO() = default; 18 19 explicit SockIO(int sockfd) : net::SockIO(sockfd) 20 {} 21 22 // This function creates a raw socket and initializes sockfd_. 23 // If the default constructor for this class was used, 24 // this function MUST be called before the object can be used 25 // for anything else. 26 int init(); 27 28 // Since raw packet socket is used for NC-SI, it needs to be bound 29 // to the interface. This function needs to be called after init, 30 // before the socket it used for communication. 31 int bind_to_iface(const net::IFaceBase& iface); 32 33 // Applies a filter to the interface to ignore VLAN tagged packets 34 int filter_vlans(); 35 36 // Non-blocking version of recv. Uses poll with timeout. 37 int recv(void* buf, size_t maxlen) override; 38 39 private: 40 struct sockaddr_ll sock_addr_; 41 const int kpoll_timeout_ = 10; 42 }; 43 44 } // namespace ncsi 45