📄 sdhcpserver.c
字号:
/****************************************************************************by grandchips #gcc sDhcpServer.c -o sDhcpServer.cgi****************************************************************************/#include<sys/types.h>#include<stdio.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <fcntl.h>#define PATH "/config/www/" main() { int fd; char filename[100]; strcpy(filename,PATH); strcat(filename,"udhcpd.conf"); if ( (fd=open(filename,O_RDWR|O_CREAT|O_APPEND,0600))<0) {printf("can not open udhcpd.conf to write!<br>\n"); } flock(fd,LOCK_EX); // lseek(fd,0,SEEK_SET); char dhcpserver;int n;int i;char c;char static_str[13];int var_num=1;int write_flag;strcpy(static_str,"static_lease ");if (getenv("CONTENT_LENGTH")) n=atoi(getenv("CONTENT_LENGTH"));i=0; write_flag=0;while (i< n-20){ if(var_num % 4<2) //hostname and ends_time {while(1) {c=getchar();i++; if (c=='&') {var_num++;break;} }//in while }else if(var_num % 4==2) //mac{ write(fd,static_str,13); while(1) {c=getchar();i++; if (c=='&') {var_num++;write_flag=0;write(fd," ",1);break;} else if (c=='=') write_flag=1; else if (c=='%') {write(fd,":",1);c=getchar();c=getchar();i=i+2;} else {if (write_flag==1) write(fd,&c,1); else continue; } }//in while}else if(var_num % 4==3) //ip{ while(1) {c=getchar();i++; if (c=='&') {write(fd,"\n",1);var_num++;write_flag=0;break;} else if (c=='=') write_flag=1; //else if (c=='%') //maohao // { write(fd,":",1); getchar();i++;getchar();i++; } else if (write_flag==1) write(fd,&c,1); else continue; }//in while}else {printf("var_num error!.....\n"); break; } }//out while flock(fd,LOCK_UN);close(fd);if(fork()==0){//output pageprintf("Contenttype:text/html\n\n");printf("<html>\n");printf("<head><title> Setting udhcpd</title></head>\n");printf(" udhcpd..on............\n");printf("<body><br>\n");printf("</body><br>\n");printf("</html>\n");fflush(stdout);}system("/sbin/udhcpd &");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -