11285115cSWilliam A. Kennington III /* 21285115cSWilliam A. Kennington III * Copyright 2021 Google LLC 31285115cSWilliam A. Kennington III * 41285115cSWilliam A. Kennington III * Licensed under the Apache License, Version 2.0 (the "License"); 51285115cSWilliam A. Kennington III * you may not use this file except in compliance with the License. 61285115cSWilliam A. Kennington III * You may obtain a copy of the License at 71285115cSWilliam A. Kennington III * 81285115cSWilliam A. Kennington III * http://www.apache.org/licenses/LICENSE-2.0 91285115cSWilliam A. Kennington III * 101285115cSWilliam A. Kennington III * Unless required by applicable law or agreed to in writing, software 111285115cSWilliam A. Kennington III * distributed under the License is distributed on an "AS IS" BASIS, 121285115cSWilliam A. Kennington III * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131285115cSWilliam A. Kennington III * See the License for the specific language governing permissions and 141285115cSWilliam A. Kennington III * limitations under the License. 151285115cSWilliam A. Kennington III */ 161285115cSWilliam A. Kennington III 171285115cSWilliam A. Kennington III #pragma once 181285115cSWilliam A. Kennington III 191285115cSWilliam A. Kennington III #include "net_iface.h" 201285115cSWilliam A. Kennington III #include "net_sockio.h" 211285115cSWilliam A. Kennington III 221285115cSWilliam A. Kennington III #include <cstddef> 231285115cSWilliam A. Kennington III 241285115cSWilliam A. Kennington III namespace ncsi 251285115cSWilliam A. Kennington III { 261285115cSWilliam A. Kennington III 271285115cSWilliam A. Kennington III class SockIO : public net::SockIO 281285115cSWilliam A. Kennington III { 291285115cSWilliam A. Kennington III public: 301285115cSWilliam A. Kennington III SockIO() = default; 311285115cSWilliam A. Kennington III SockIO(int sockfd)322be45238SPatrick Williams explicit SockIO(int sockfd) : net::SockIO(sockfd) {} 331285115cSWilliam A. Kennington III 341285115cSWilliam A. Kennington III // This function creates a raw socket and initializes sockfd_. 351285115cSWilliam A. Kennington III // If the default constructor for this class was used, 361285115cSWilliam A. Kennington III // this function MUST be called before the object can be used 371285115cSWilliam A. Kennington III // for anything else. 381285115cSWilliam A. Kennington III int init(); 391285115cSWilliam A. Kennington III 401285115cSWilliam A. Kennington III // Since raw packet socket is used for NC-SI, it needs to be bound 411285115cSWilliam A. Kennington III // to the interface. This function needs to be called after init, 421285115cSWilliam A. Kennington III // before the socket it used for communication. 431285115cSWilliam A. Kennington III int bind_to_iface(const net::IFaceBase& iface); 441285115cSWilliam A. Kennington III 451285115cSWilliam A. Kennington III // Applies a filter to the interface to ignore VLAN tagged packets 461285115cSWilliam A. Kennington III int filter_vlans(); 471285115cSWilliam A. Kennington III 481285115cSWilliam A. Kennington III // Non-blocking version of recv. Uses poll with timeout. 491285115cSWilliam A. Kennington III int recv(void* buf, size_t maxlen) override; 501285115cSWilliam A. Kennington III 511285115cSWilliam A. Kennington III private: 521285115cSWilliam A. Kennington III const int kpoll_timeout_ = 10; 531285115cSWilliam A. Kennington III }; 541285115cSWilliam A. Kennington III 551285115cSWilliam A. Kennington III } // namespace ncsi 56