2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
14 * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
15 * Copyright (C) 2008 Steven Barth <steven@midlink.org>
18 #include <linux/sockios.h>
19 #include <net/route.h>
20 #include <sys/ioctl.h>
24 extern int sock_ifconfig;
26 int route_add(char *dev, int flag_gateway, int flag_host, char *dst, char *gateway, char *mask)
32 r.rt_flags |= RTF_GATEWAY;
34 r.rt_flags |= RTF_HOST;
35 r.rt_dst.sa_family = AF_INET;
36 r.rt_gateway.sa_family = AF_INET;
37 r.rt_genmask.sa_family = AF_INET;
39 ((struct sockaddr_in *) &r.rt_dst)->sin_addr.s_addr = (unsigned int)ip;
40 char2ipv4(gateway, ip);
41 ((struct sockaddr_in *) &r.rt_gateway)->sin_addr.s_addr = (unsigned int)ip;
43 ((struct sockaddr_in *) &r.rt_genmask)->sin_addr.s_addr = (unsigned int)ip;
44 return ioctl(sock_ifconfig, SIOCADDRT, (void *) &r);