blob: 88d3177ca49dd8842f0a184ad5257c536461c2dc [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
William A. Kennington III7d6fa422021-02-08 17:04:02 -080015#include "net_iface_mock.h"
16
Willy Tuadb8ffe2023-07-17 13:44:22 -070017#include <linux/if.h>
18#include <sys/ioctl.h>
19
William A. Kennington III7d6fa422021-02-08 17:04:02 -080020namespace mock
21{
22
Willy Tua9a98252023-09-18 14:49:23 -070023int IFace::bind_sock(int sockfd) const
William A. Kennington III7d6fa422021-02-08 17:04:02 -080024{
25 bound_socks.push_back(sockfd);
26 return 0;
27}
28
29int IFace::ioctl_sock(int, int request, struct ifreq* ifr) const
30{
31 return ioctl(request, ifr);
32}
33
34int IFace::ioctl(int request, struct ifreq* ifr) const
35{
36 int ret = 0;
37 switch (request)
38 {
39 case SIOCGIFINDEX:
40 ifr->ifr_ifindex = index;
41 break;
42 case SIOCGIFFLAGS:
43 ifr->ifr_flags = flags;
44 break;
45 case SIOCSIFFLAGS:
46 flags = ifr->ifr_flags;
47 break;
48 default:
49 ret = -1;
50 }
51
52 return ret;
53}
54
55} // namespace mock