#include <errno.h> | |
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/ipc.h> | |
#include <sys/msg.h> | |
#include <sys/types.h> | |
#include <string.h> | |
#include <termios.h> | |
#include "../../include/message.h" | |
//#include "../../include/errorcode.h" | |
#define do_cmd(format, cmds...) ({ \ | |
int __STATAS__; \ | |
char __TEMP__[256]; \ | |
sprintf(__TEMP__, format, ##cmds); \ | |
__STATAS__ = system(__TEMP__); \ | |
__STATAS__; \ | |
}) | |
#define cprintf(fmt, args...) do { \ | |
FILE *fp = fopen("/dev/console", "w"); \ | |
if (fp) { \ | |
fprintf(fp, fmt, ## args); \ | |
fclose(fp); \ | |
} \ | |
} while (0) | |
int main(int argc, char **argv) | |
{ | |
char * name = NULL; | |
char *pValue = NULL; | |
char buf[256]; | |
char ethwan[32]; | |
name = strrchr(argv[0], '/'); | |
name = name ? name + 1 : argv[0]; | |
sc_cfg_get("ethwan", ethwan, sizeof(ethwan)); | |
char path_sh[100]={0}; | |
char path_file[500]={0}; | |
/* | |
nv set $wan_if"_ip"=0.0.0.0 | |
nv set $wan_if"_nm"=0.0.0.0 | |
nv set $wan_if"_gw"=0.0.0.0 | |
nv set $wan_if"_pridns"=0.0.0.0 | |
nv set $wan_if"_secdns"=0.0.0.0*/ | |
//printf(name); | |
if (strstr(name, "pppoe-up")) | |
{ | |
if (NULL!= (pValue = getenv("IPLOCAL"))) | |
{ | |
sprintf(buf,"%s_ip",ethwan); | |
sc_cfg_set(buf, pValue); | |
} | |
if (NULL!=(pValue = getenv("IPREMOTE"))) | |
{ | |
sprintf(buf,"%s_gw",ethwan); | |
sc_cfg_set(buf, pValue); | |
} | |
if (NULL!=(pValue = getenv("DNS1"))) | |
{ | |
sprintf(buf,"%s_pridns",ethwan); | |
sc_cfg_set(buf, pValue); | |
} | |
if (NULL!=(pValue = getenv("DNS2"))) | |
{ | |
sprintf(buf,"%s_secdns",ethwan); | |
sc_cfg_set(buf, pValue); | |
} | |
sprintf(buf,"%s_nm",ethwan); | |
sc_cfg_set(buf,"255.255.255.255"); | |
sc_cfg_get("path_sh", path_sh, sizeof(path_sh)); | |
sprintf(path_file,"%s/pppoe_updown.sh up",path_sh); | |
do_cmd(path_file); | |
} | |
else if (strstr(name, "pppoe-down")) | |
{ | |
sprintf(buf,"%s_ip",ethwan); | |
sc_cfg_set(buf, "0.0.0.0"); | |
sprintf(buf,"%s_gw",ethwan); | |
sc_cfg_set(buf, "0.0.0.0"); | |
sprintf(buf,"%s_pridns",ethwan); | |
sc_cfg_set(buf, "0.0.0.0"); | |
sprintf(buf,"%s_secdns",ethwan); | |
sc_cfg_set(buf, "0.0.0.0"); | |
sprintf(buf,"%s_nm",ethwan); | |
sc_cfg_set(buf,"0.0.0.0"); | |
sc_cfg_get("path_sh", path_sh, sizeof(path_sh)); | |
sprintf(path_file,"%s/pppoe_updown.sh down",path_sh); | |
do_cmd(path_file); | |
//sc_cfg_set("ppp_status","ppp_disconnected"); | |
} | |
return 0; | |
} |