pppd 强制设置默认网关?
int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
{
struct rtentry rt;
/* if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) {
u_int32_t old_gateway = SIN_ADDR(rt.rt_gateway);
if (old_gateway != gateway)
error("not replacing existing default route to %s [%I]",
rt.rt_dev, old_gateway);
return 0;
}
*/
memset (&rt, '\0', sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
rt.rt_dev = ifname;
if (kernel_version > KVERSION(2,1,0)) {
SET_SA_FAMILY (rt.rt_genmask, AF_INET);
SIN_ADDR(rt.rt_genmask) = 0L;
}
SIN_ADDR(rt.rt_gateway) = gateway;
rt.rt_flags = RTF_UP | RTF_GATEWAY;
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
if ( ! ok_error ( errno ))
error("default route ioctl(SIOCADDRT): %m");
return 0;
}
default_route_gateway = gateway;
return 1;
}
{
struct rtentry rt;
/* if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) {
u_int32_t old_gateway = SIN_ADDR(rt.rt_gateway);
if (old_gateway != gateway)
error("not replacing existing default route to %s [%I]",
rt.rt_dev, old_gateway);
return 0;
}
*/
memset (&rt, '\0', sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
rt.rt_dev = ifname;
if (kernel_version > KVERSION(2,1,0)) {
SET_SA_FAMILY (rt.rt_genmask, AF_INET);
SIN_ADDR(rt.rt_genmask) = 0L;
}
SIN_ADDR(rt.rt_gateway) = gateway;
rt.rt_flags = RTF_UP | RTF_GATEWAY;
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
if ( ! ok_error ( errno ))
error("default route ioctl(SIOCADDRT): %m");
return 0;
}
default_route_gateway = gateway;
return 1;
}