1 // 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 
15 #include "net_iface_mock.h"
16 
17 #include <linux/if.h>
18 #include <sys/ioctl.h>
19 
20 namespace mock
21 {
22 
bind_sock(int sockfd) const23 int IFace::bind_sock(int sockfd) const
24 {
25     bound_socks.push_back(sockfd);
26     return 0;
27 }
28 
ioctl_sock(int,int request,struct ifreq * ifr) const29 int IFace::ioctl_sock(int, int request, struct ifreq* ifr) const
30 {
31     return ioctl(request, ifr);
32 }
33 
ioctl(int request,struct ifreq * ifr) const34 int 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
56