Fix the gcov build error
[platform/core/api/tethering.git] / tests / mocks / tethering_ioctl.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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
17 #include <arpa/inet.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdarg.h>
23
24 #define TETHERING_TEST_IP_ADDRESS       0xC0A82B01  /* 192.168.43.1 */
25
26 static void _set_mac_address(void *arg)
27 {
28         struct ifreq *ifr = (struct ifreq *) arg;
29
30         for (int i = 0; i < 6; i++)
31                 ifr->ifr_hwaddr.sa_data[i] = 0x00;
32 }
33
34 static void _set_ip_address(void *arg)
35 {
36         struct ifreq *ifr = (struct ifreq *) arg;
37         struct sockaddr_in addr;
38
39         memset(&addr, 0, sizeof(struct sockaddr));
40         addr.sin_family = AF_INET;
41         addr.sin_port = 0;
42         addr.sin_addr.s_addr = htonl(TETHERING_TEST_IP_ADDRESS);
43
44         memcpy(&ifr->ifr_addr, &addr, sizeof(struct sockaddr));
45 }
46
47 int __wrap_ioctl(int fd, unsigned long int request, ...)
48 {
49         int ret = 0;
50         void *arg;
51         va_list vl;
52
53         va_start(vl, request);
54         arg = va_arg(vl, void *);
55
56         switch (request) {
57         case SIOCGIFHWADDR:
58                 _set_mac_address(arg);
59                 break;
60         case SIOCGIFADDR:
61                 _set_ip_address(arg);
62                 break;
63         default:
64                 ret = 1;
65         }
66
67         va_end(vl);
68
69         return ret;
70 }