blob: 6c38edd86a3e0150acc1302f3ec4a5ca229a7f33 [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001/*
2 * Copyright 2021 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
William A. Kennington III7d6fa422021-02-08 17:04:02 -080017#pragma once
18
19#include "net_iface.h"
20#include "net_sockio.h"
21
William A. Kennington III7d6fa422021-02-08 17:04:02 -080022#include <cstddef>
William A. Kennington III7d6fa422021-02-08 17:04:02 -080023
24namespace ncsi
25{
26
27class SockIO : public net::SockIO
28{
29 public:
30 SockIO() = default;
31
Patrick Williams2be45232023-05-10 07:51:22 -050032 explicit SockIO(int sockfd) : net::SockIO(sockfd) {}
William A. Kennington III7d6fa422021-02-08 17:04:02 -080033
34 // This function creates a raw socket and initializes sockfd_.
35 // If the default constructor for this class was used,
36 // this function MUST be called before the object can be used
37 // for anything else.
38 int init();
39
40 // Since raw packet socket is used for NC-SI, it needs to be bound
41 // to the interface. This function needs to be called after init,
42 // before the socket it used for communication.
43 int bind_to_iface(const net::IFaceBase& iface);
44
45 // Applies a filter to the interface to ignore VLAN tagged packets
46 int filter_vlans();
47
48 // Non-blocking version of recv. Uses poll with timeout.
49 int recv(void* buf, size_t maxlen) override;
50
51 private:
William A. Kennington III7d6fa422021-02-08 17:04:02 -080052 const int kpoll_timeout_ = 10;
53};
54
55} // namespace ncsi