lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <errno.h>
|
| 2 | #include <time.h>
|
| 3 | #include <stdio.h>
|
| 4 | #include <stdlib.h>
|
| 5 | #include <sys/ipc.h>
|
| 6 | #include <sys/msg.h>
|
| 7 | #include <sys/types.h>
|
| 8 | #include <string.h>
|
| 9 | #include <termios.h>
|
| 10 | #include "../../include/message.h"
|
| 11 | //#include "../../include/errorcode.h"
|
| 12 |
|
| 13 |
|
| 14 | #define do_cmd(format, cmds...) ({ \
|
| 15 | int __STATAS__; \
|
| 16 | char __TEMP__[256]; \
|
| 17 | sprintf(__TEMP__, format, ##cmds); \
|
| 18 | __STATAS__ = system(__TEMP__); \
|
| 19 | __STATAS__; \
|
| 20 | })
|
| 21 |
|
| 22 | #define cprintf(fmt, args...) do { \
|
| 23 | FILE *fp = fopen("/dev/console", "w"); \
|
| 24 | if (fp) { \
|
| 25 | fprintf(fp, fmt, ## args); \
|
| 26 | fclose(fp); \
|
| 27 | } \
|
| 28 | } while (0)
|
| 29 |
|
| 30 | int main(int argc, char **argv)
|
| 31 | {
|
| 32 | char * name = NULL;
|
| 33 | char *pValue = NULL;
|
| 34 | char buf[256];
|
| 35 | char ethwan[32];
|
| 36 | name = strrchr(argv[0], '/');
|
| 37 | name = name ? name + 1 : argv[0];
|
| 38 | sc_cfg_get("ethwan", ethwan, sizeof(ethwan));
|
| 39 | char path_sh[100]={0};
|
| 40 | char path_file[500]={0};
|
| 41 | /*
|
| 42 | nv set $wan_if"_ip"=0.0.0.0
|
| 43 | nv set $wan_if"_nm"=0.0.0.0
|
| 44 | nv set $wan_if"_gw"=0.0.0.0
|
| 45 | nv set $wan_if"_pridns"=0.0.0.0
|
| 46 | nv set $wan_if"_secdns"=0.0.0.0*/
|
| 47 | //printf(name);
|
| 48 | if (strstr(name, "pppoe-up"))
|
| 49 | {
|
| 50 |
|
| 51 | if (NULL!= (pValue = getenv("IPLOCAL")))
|
| 52 | {
|
| 53 | sprintf(buf,"%s_ip",ethwan);
|
| 54 | sc_cfg_set(buf, pValue);
|
| 55 | }
|
| 56 | if (NULL!=(pValue = getenv("IPREMOTE")))
|
| 57 | {
|
| 58 | sprintf(buf,"%s_gw",ethwan);
|
| 59 | sc_cfg_set(buf, pValue);
|
| 60 | }
|
| 61 |
|
| 62 | if (NULL!=(pValue = getenv("DNS1")))
|
| 63 | {
|
| 64 | sprintf(buf,"%s_pridns",ethwan);
|
| 65 | sc_cfg_set(buf, pValue);
|
| 66 | }
|
| 67 | if (NULL!=(pValue = getenv("DNS2")))
|
| 68 | {
|
| 69 | sprintf(buf,"%s_secdns",ethwan);
|
| 70 | sc_cfg_set(buf, pValue);
|
| 71 | }
|
| 72 | sprintf(buf,"%s_nm",ethwan);
|
| 73 | sc_cfg_set(buf,"255.255.255.255");
|
| 74 |
|
| 75 | sc_cfg_get("path_sh", path_sh, sizeof(path_sh));
|
| 76 | sprintf(path_file,"%s/pppoe_updown.sh up",path_sh);
|
| 77 | do_cmd(path_file);
|
| 78 | }
|
| 79 | else if (strstr(name, "pppoe-down"))
|
| 80 | {
|
| 81 | sprintf(buf,"%s_ip",ethwan);
|
| 82 | sc_cfg_set(buf, "0.0.0.0");
|
| 83 | sprintf(buf,"%s_gw",ethwan);
|
| 84 | sc_cfg_set(buf, "0.0.0.0");
|
| 85 | sprintf(buf,"%s_pridns",ethwan);
|
| 86 | sc_cfg_set(buf, "0.0.0.0");
|
| 87 | sprintf(buf,"%s_secdns",ethwan);
|
| 88 | sc_cfg_set(buf, "0.0.0.0");
|
| 89 | sprintf(buf,"%s_nm",ethwan);
|
| 90 | sc_cfg_set(buf,"0.0.0.0");
|
| 91 | sc_cfg_get("path_sh", path_sh, sizeof(path_sh));
|
| 92 | sprintf(path_file,"%s/pppoe_updown.sh down",path_sh);
|
| 93 | do_cmd(path_file);
|
| 94 | //sc_cfg_set("ppp_status","ppp_disconnected");
|
| 95 | }
|
| 96 | return 0;
|
| 97 |
|
| 98 | } |