void network_change_ip(unsigned char *datasave) { int s_fd=0; int ret = 0; int i = 0; unsigned char sys_id[6]; unsigned char buf[64]; unsigned char request_buf[13]; unsigned char h_ip[4]; unsigned char s_ip[16]; unsigned char s_gw[16]; unsigned char setip[32] = "ifconfig eth0 "; int s_len = strlen(setip); unsigned char setgw[64] = "route add default gw "; int g_len = strlen(setgw); unsigned char k_ip[4]; unsigned char smk[6]; int sys_id_flag = 0; read_identifier(sys_id); memcpy(smk, datasave, 6); for(i = 0; i < 6; i+=1) { if(smk[i] != sys_id[i]) { sys_id_flag = 1; break; } } if(sys_id_flag == 0) { memcpy(k_ip, datasave+6, 4); if(k_ip[0] != 0x0) { //continue; writ_txt_ip(k_ip); read_txt_ip(s_ip,h_ip); memcpy(setip+s_len, s_ip, strlen(s_ip)+1); system(setip); myread_txt_ip(s_gw, h_ip); memcpy(setgw+g_len, s_gw, strlen(s_gw)+1); system(setgw); } } }
static grub_err_t read_property (struct parsebuf *p) { char *name; /* Read the property name. */ name = read_identifier (p); if (! name) { advance_to_next_line (p); return grub_errno; } /* Skip whitespace before separator. */ skip_whitespace (p); /* Read separator. */ if (read_char (p) != ':') { grub_error (GRUB_ERR_IO, "%s:%d:%d missing separator after property name `%s'", p->filename, p->line_num, p->col_num, name); goto done; } /* Skip whitespace after separator. */ skip_whitespace (p); /* Get the value based on its type. */ if (peek_char (p) == '"') { /* String value (e.g., '"My string"'). */ char *value = read_expression (p); if (! value) { grub_error (GRUB_ERR_IO, "%s:%d:%d missing property value", p->filename, p->line_num, p->col_num); goto done; } /* If theme_set_string results in an error, grub_errno will be returned below. */ theme_set_string (p->view, name, value, p->theme_dir, p->filename, p->line_num, p->col_num); grub_free (value); } else { grub_error (GRUB_ERR_IO, "%s:%d:%d property value invalid; " "enclose literal values in quotes (\")", p->filename, p->line_num, p->col_num); goto done; } done: grub_free (name); return grub_errno; }
void network_respond_ip(int tcp_fd) { int s_fd=0; int ret = 0; int i = 0; unsigned char sys_id[6]; unsigned char buf[64]; unsigned char request_buf[13]; unsigned char h_ip[4]; unsigned char s_ip[16]; unsigned char s_gw[16]; unsigned char setip[32] = "ifconfig eth0 "; int s_len = strlen(setip); unsigned char setgw[64] = "route add default gw "; int g_len = strlen(setgw); unsigned char k_ip[4]; unsigned char smk[6]; int sys_id_flag = 0; read_identifier(sys_id);//读取identifier.ini中保存的信息 request_buf[0] = DATAUP_TOP1; request_buf[1] = DATAUP_TOP2; request_buf[2] = 0x08; memcpy(request_buf+3, sys_id, 6); unsigned char versionbuf[2]; //获取系统本身IP //ret = save_system_ip(ip, strlen(ip)); ret = read_txt_ip(s_ip, h_ip);//读取systemip.ini中的信息 if(ret < 0) { //获取文本的IP错误 printf("read system ip file error!!!\n"); GetIP_v4_and_v6_linux(AF_INET,s_ip,16); //获取系统的IP ret = save_system_ip(s_ip, strlen(s_ip)); } read_txt_ip(s_ip, h_ip); memcpy(request_buf+9, h_ip, 4); versionbuf[0]=0x01; versionbuf[1]=0x01; //当前版本号为1.01 累计到1.10后,进到2.00。依次类推 //版本更新内容用txt文档记录,交由上层显示 memcpy(request_buf+13, versionbuf, 2); ret=write(tcp_fd, request_buf, 15); printf("---sendret=%d\n",ret); }
int ft_expect(const char **s, const char *format, ...) { va_list argp; char c; va_start(argp, format); while ((c = *format) != '\0') { if (c == '$' && (c = *++format)) { if (c == 'n') read_number(s, argp); else if (c == 'i') read_identifier(s, argp); format++; continue ; } if (**s != c) return (0); format++; (*s)++; } return (1); }
/* Read a GUI object specification from the theme file. Any components created will be added to the GUI container PARENT. */ static grub_err_t read_object (struct parsebuf *p, grub_gui_container_t parent) { grub_video_rect_t bounds; char *name; name = read_identifier (p); if (! name) goto cleanup; grub_gui_component_t component = 0; if (grub_strcmp (name, "label") == 0) { component = grub_gui_label_new (); } else if (grub_strcmp (name, "image") == 0) { component = grub_gui_image_new (); } else if (grub_strcmp (name, "vbox") == 0) { component = (grub_gui_component_t) grub_gui_vbox_new (); } else if (grub_strcmp (name, "hbox") == 0) { component = (grub_gui_component_t) grub_gui_hbox_new (); } else if (grub_strcmp (name, "canvas") == 0) { component = (grub_gui_component_t) grub_gui_canvas_new (); } else if (grub_strcmp (name, "progress_bar") == 0) { component = grub_gui_progress_bar_new (); } else if (grub_strcmp (name, "circular_progress") == 0) { component = grub_gui_circular_progress_new (); } else if (grub_strcmp (name, "boot_menu") == 0) { component = grub_gui_list_new (); } else { /* Unknown type. */ grub_error (GRUB_ERR_IO, "%s:%d:%d unknown object type `%s'", p->filename, p->line_num, p->col_num, name); goto cleanup; } if (! component) goto cleanup; /* Inform the component about the theme so it can find its resources. */ component->ops->set_property (component, "theme_dir", p->theme_dir); component->ops->set_property (component, "theme_path", p->filename); /* Add the component as a child of PARENT. */ bounds.x = 0; bounds.y = 0; bounds.width = -1; bounds.height = -1; component->ops->set_bounds (component, &bounds); parent->ops->add (parent, component); skip_whitespace (p); if (read_char (p) != '{') { grub_error (GRUB_ERR_IO, "%s:%d:%d expected `{' after object type name `%s'", p->filename, p->line_num, p->col_num, name); goto cleanup; } while (has_more (p)) { skip_whitespace (p); /* Check whether the end has been encountered. */ if (peek_char (p) == '}') { /* Skip the closing brace. */ read_char (p); break; } if (peek_char (p) == '#') { /* Skip comments. */ advance_to_next_line (p); continue; } if (peek_char (p) == '+') { /* Skip the '+'. */ read_char (p); /* Check whether this component is a container. */ if (component->ops->is_instance (component, "container")) { /* Read the sub-object recursively and add it as a child. */ if (read_object (p, (grub_gui_container_t) component) != 0) goto cleanup; /* After reading the sub-object, resume parsing, expecting another property assignment or sub-object definition. */ continue; } else { grub_error (GRUB_ERR_IO, "%s:%d:%d attempted to add object to non-container", p->filename, p->line_num, p->col_num); goto cleanup; } } char *property; property = read_identifier (p); if (! property) { grub_error (GRUB_ERR_IO, "%s:%d:%d identifier expected in theme file", p->filename, p->line_num, p->col_num); goto cleanup; } skip_whitespace (p); if (read_char (p) != '=') { grub_error (GRUB_ERR_IO, "%s:%d:%d expected `=' after property name `%s'", p->filename, p->line_num, p->col_num, property); grub_free (property); goto cleanup; } skip_whitespace (p); char *value; value = read_expression (p); if (! value) { grub_free (property); goto cleanup; } /* Handle the property value. */ if (grub_strcmp (property, "left") == 0) parse_proportional_spec (value, &component->x, &component->xfrac); else if (grub_strcmp (property, "top") == 0) parse_proportional_spec (value, &component->y, &component->yfrac); else if (grub_strcmp (property, "width") == 0) parse_proportional_spec (value, &component->w, &component->wfrac); else if (grub_strcmp (property, "height") == 0) parse_proportional_spec (value, &component->h, &component->hfrac); else /* General property handling. */ component->ops->set_property (component, property, value); grub_free (value); grub_free (property); if (grub_errno != GRUB_ERR_NONE) goto cleanup; } cleanup: grub_free (name); return grub_errno; }
//--------------------------------------------------- // 自动返回控制器器IP主函数 //--------------------------------------------------- int main(int argc, char *argv[]) //int configpalen_ipdetaup(void) { int s_fd, r_fd; int ret = 0; int i = 0; unsigned char sys_id[6]; unsigned char buf[64]; unsigned char request_buf[13]; unsigned char h_ip[4]; unsigned char s_ip[16]; //unsigned char *ip="192.172.1.125"; unsigned char setip[32] = "ifconfig eth0 "; int s_len = strlen(setip); read_identifier(sys_id); request_buf[0] = CAM_TYPE_TOP1; request_buf[1] = CAM_TYPE_TOP2; request_buf[2] = CAM_TYPE_REPLY; memcpy(request_buf+3, sys_id, 6); /* request_buf[3] = 0x01; request_buf[4] = 0x02; request_buf[5] = 0x03; request_buf[6] = 0x04; request_buf[7] = 0x05; request_buf[8] = 0x06; */ //获取系统本身IP //ret = save_system_ip(ip, strlen(ip)); ret = read_txt_ip(s_ip, h_ip); if(ret < 0) { //获取文本的IP错误 printf("read system ip file error!!!\n"); GetIP_v4_and_v6_linux(AF_INET,s_ip,16); //获取系统的IP ret = save_system_ip(s_ip, strlen(s_ip)); } memcpy(setip+s_len, s_ip, strlen(s_ip)+1); printf("***********************\n"); printf("set ip:%s\n",setip); printf("***********************\n"); system(setip); //ret = writ_txt_ip(h_ip); s_fd = make_send_multicast_init(s_ip); //创建主播发送字符 r_fd = make_read_multicase_init(); //创建主播接送字符 while(1) { /* read_txt_ip(s_ip, h_ip); memcpy(request_buf+9, h_ip, 4); printf("sendIP==="); for(i = 0; i < 13; i++) printf("%02x ", request_buf[i]); printf("\n"); ret=sendto(s_fd,request_buf,13,0,(struct sockaddr *)&addr,sizeof(addr)); */ //ret = recvfrom(r_fd, buf, 64, 0, (struct sockaddr*)&r_peer, &len);; //if(ret == -1) // break; //else { //printf("-*******************************\n"); //buf[ret]='\0'; //if(buf[2] == CAM_TYPE_REQUEST) //得到请求IP命令 { read_txt_ip(s_ip, h_ip); memcpy(request_buf+9, h_ip, 4); printf("sendIP==="); for(i = 0; i < 13; i++) printf("%02x ", request_buf[i]); printf("\n"); //request_buf[8] = 0x2; ret=sendto(s_fd,request_buf,13,0,(struct sockaddr *)&addr,sizeof(addr)); sleep(1); } /* else if(buf[2] == CAM_TYPE_MODIFY) //得到设置IP命令 { // printf("================================================\n"); //for(i = 0; i < 13; i++) // printf("%02x ", buf[i]); //printf("\n"); unsigned char k_ip[4]; unsigned char smk[6]; int sys_id_flag = 0; //memset(k_ip, 0, 4); memcpy(smk, buf+3, 6); //sys_id[5] = 0x02; for(i = 0; i < 6; i+=1) { if(smk[i] != sys_id[i]) { sys_id_flag = 1; break; } } if(sys_id_flag == 0) { memcpy(k_ip, buf+9, 4); //printf("%02x %02x %02x %02x\n",k_ip[0],k_ip[1],k_ip[2],k_ip[3]); if(k_ip[0] != 0x0) { //continue; writ_txt_ip(k_ip); read_txt_ip(s_ip,h_ip); printf("sip:%s\n",s_ip); memcpy(setip+s_len, s_ip, strlen(s_ip)+1); //printf("set ip:%s\n",setip); close(s_fd); system(setip); s_fd = make_send_multicast_init(s_ip); } //printf("================================================\n"); } }*/ } } close(r_fd); close(s_fd); return 0; }
/*----------------------------------------------------------------------*/ static int next_token(lex_state_t *l) { token_t *token; char c; char cn; token = &l->out->tokens[l->out->token_count]; skip_comments_and_whitespace(l); token->source_pos = l->ptr - l->in->source; c = *(l->ptr + 0); cn = *(l->ptr + 1); if (c == '\0') { return 0; } else if (c == '\"') { read_string(l, token); } else if (is_decimal_digit(c)) { read_number(l, token); } else if (is_identifier_char(c)) { read_identifier(l, token); match_keyword(token); } else if (c == '<' && cn == '=') { token->type = TK_LESS_EQUAL; l->ptr += 2; } else if (c == '=' && cn == '=') { token->type = TK_EQUALS_EQUALS; l->ptr += 2; } else if (c == '>' && cn == '=') { token->type = TK_GREATER_EQUAL; l->ptr += 2; } else if (c == '+') { token->type = TK_PLUS; ++l->ptr; } else if (c == '-') { token->type = TK_MINUS; ++l->ptr; } else if (c == '*') { token->type = TK_STAR; ++l->ptr; } else if (c == '/') { token->type = TK_SLASH; ++l->ptr; } else if (c == '=') { token->type = TK_EQUALS; ++l->ptr; } else if (c == '<') { token->type = TK_LESS; ++l->ptr; } else if (c == '>') { token->type = TK_GREATER; ++l->ptr; } else if (c == '(') { token->type = TK_LBRACKET; ++l->ptr; } else if (c == ')') { token->type = TK_RBRACKET; ++l->ptr; } else if (c == ',') { token->type = TK_COMMA; ++l->ptr; } else if (c == ':') { token->type = TK_COLON; ++l->ptr; } else if (c == ';') { token->type = TK_SEMICOLON; ++l->ptr; } else { error(l); } return 1; }
object lisp_read(FILE *in) { int c; while ((c = fgetc(in)) != EOF) { /* atmosphere */ if (isspace(c)) { continue; } else if (c == ';') { while (c != EOF && c != '\n') c = fgetc(in); continue; } /* characters, booleans or numbers with radix */ else if (c == '#') { c = fgetc(in); switch (c) { /* number prefixes */ case 'b': case 'B': case 'o': case 'O': case 'x': case 'X': case 'd': case 'D': case 'e': case 'i': ungetc(c, in); return read_number(in); /* booleans */ case 't': case 'T': return the_truth; case 'f': case 'F': return the_falsity; /* characters */ case '\\': return read_character(in); /* vectors */ case '(': ungetc(c, in); return read_vector(in); /* commented form, read and discard */ case ';': lisp_read(in); continue; case '<': error("Object cannot be read back -- read", nil); default: error("Unexpected character -- read", nil); } } /* number */ else if (isdigit(c) || ((c == '-') && isdigit(peek_char(in))) || ((c == '+') && isdigit(peek_char(in)))) { ungetc(c, in); return read_number(in); } /* string */ else if (c == '"') { return read_string(in); } /* symbol */ else if (is_initial(c)) { ungetc(c, in); return read_identifier(in); } /* peculiar identifiers */ else if (((c == '+') || c == '-') && is_delimiter(peek_char(in))) { return make_symbol_c((c == '+' ? "+" : "-")); } /* stuff starting with dot, FIXME for floats */ else if (c == '.') { if (is_delimiter(peek_char(in))) error("Illegal use of . -- read", nil); c = fgetc(in); if (c != '.' || peek_char(in) != '.') error("Symbol has bad name -- read", nil); c = fgetc(in); if (!is_delimiter(peek_char(in))) error("Symbol has bad name -- read", nil); return _ellipsis; } /* pair */ else if (c == '(') { return read_pair(in); } /* quote */ else if (c == '\'') { return cons(_quote, cons(lisp_read(in), nil)); } /* quasiquote */ else if (c == '`') { return cons(_quasiquote, cons(lisp_read(in), nil)); } /* unquote & unquote-splicing */ else if (c == ',') { if (peek_char(in) == '@') { c = fgetc(in); return cons(_unquote_splicing, cons(lisp_read(in), nil)); } else return cons(_unquote, cons(lisp_read(in), nil)); } else error("Unexpected character -- read", nil); } return end_of_file; }
//--------------------------------------------------- // 自动返回控制器器IP主函数 //--------------------------------------------------- //int main(int argc, char *argv[]) int configpalen_ipdetaup(void) { int s_fd=0; int ret = 0; int i = 0; unsigned char sys_id[6]; unsigned char buf[64]; unsigned char request_buf[13]; unsigned char h_ip[4]; unsigned char s_ip[16]; unsigned char s_gw[16]; //unsigned char *ip="192.172.1.125"; unsigned char setip[32] = "ifconfig eth0 "; int s_len = strlen(setip); unsigned char setgw[64] = "route add default gw "; int g_len = strlen(setgw); unsigned char k_ip[4]; unsigned char smk[6]; int sys_id_flag = 0; read_identifier(sys_id);//读取identifier.ini中保存的信息 request_buf[0] = CAM_TYPE_TOP1; request_buf[1] = CAM_TYPE_TOP2; request_buf[2] = CAM_TYPE_REPLY; memcpy(request_buf+3, sys_id, 6); unsigned char versionbuf[2]; //获取系统本身IP //ret = save_system_ip(ip, strlen(ip)); ret = read_txt_ip(s_ip, h_ip);//读取systemip.ini中的信息 if(ret < 0) { //获取文本的IP错误 printf("read system ip file error!!!\n"); GetIP_v4_and_v6_linux(AF_INET,s_ip,16); //获取系统的IP ret = save_system_ip(s_ip, strlen(s_ip)); } //printf("s_ip=%s\n",s_ip); memcpy(setip+s_len, s_ip, strlen(s_ip)+1); printf("***********************\n"); printf("set ip:%s\n",setip); printf("***********************\n"); system(setip);//还进行了设置。 myread_txt_ip(s_gw, h_ip); memcpy(setgw+g_len, s_gw, strlen(s_gw)+1); printf("***********************\n"); printf("set gateway:%s\n",setgw); printf("***********************\n"); system(setgw); //ret = writ_txt_ip(h_ip); s_fd = make_send_multicast_init(s_ip); //创建主播发送字符,只使用一个套接字也完全可以的。ghf printf("s_fd=%d\n",s_fd); socklen_t len=sizeof(addr); extern int errno; static int val=0; cpufd = open("/dev/cpu_led",O_RDONLY); if (cpufd < 0) { system("insmod cpu_led.ko"); sleep(2); cpufd = open("/dev/cpu_led",O_RDONLY); if (cpufd < 0) { printf("error,open device cpu_led!!!\n"); } } else { printf("open device cpu_led!!!\n"); } //此接口走路由不行,但直连不同字段都可以 /*int sfd; sfd = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in peeraddr; bzero(&peeraddr, sizeof(peeraddr)); peeraddr.sin_family = AF_INET; peeraddr.sin_port = htons(MUTIL_PORT); peeraddr.sin_addr.s_addr = inet_addr(MUTIL_ADDR);*/ while(1) { //防止arm端ip被改 GetIP_v4_and_v6_linux(AF_INET,s_ip,16); save_system_ip(s_ip, strlen(s_ip)); val++; ret = recvfrom(s_fd, buf, 64, 0, (struct sockaddr*)&addr, &len);//最后一个参数的定义跟sendto不一样,注意! //printf("recvret=%d,buf[2]=%d\n",ret,buf[2]); if(ret == -1) { printf("in configpalen_ipdetaup recvfrom error\n"); break; } else { buf[ret]='\0'; if(buf[2] == CAM_TYPE_REQUEST) //得到请求IP命令,mt500将ip地址和网卡地址发上去显示,收到后会发一个 //CAM_TYPE_REPLY下来 { //printf("------1\n"); read_txt_ip(s_ip, h_ip); memcpy(request_buf+9, h_ip, 4); versionbuf[0]=0x01; versionbuf[1]=0x01; //当前版本号为1.01 累计到1.10后,进到2.00。依次类推 //版本更新内容用txt文档记录,交由上层显示 memcpy(request_buf+13, versionbuf, 2); //以下判断条件不加也可以,因为如果没有链接的话,while一开始的地方recvfrom会阻塞,不会进到下面来发送 ret=0; if(s_fd>0) ret=sendto(s_fd,request_buf,15,0,(struct sockaddr *)&addr,sizeof(addr)); //if(sfd>0) // ret=sendto(sfd,request_buf,15,0,(struct sockaddr *)&peeraddr,sizeof(peeraddr)); if(ret<0) { printf("errno=%d,---sendret=%d,%s\n",errno,ret,strerror(errno)); system("ifconfig eth0 192.172.1.85"); system("route add default gw 192.172.1.1"); ioctl(cpufd,0,0); } else { //printf("sendret=%d, ipaddr to serverok\n",ret); if(val%2==0) ioctl(cpufd,1,0); else ioctl(cpufd,0,0); } } else if(buf[2] == CAM_TYPE_MODIFY) //得到设置IP命令,上层可以直接设置ip才行!2015-9-16 { memcpy(smk, buf+3, 6); for(i = 0; i < 6; i+=1) { if(smk[i] != sys_id[i]) { sys_id_flag = 1; break; } } if(sys_id_flag == 0) { memcpy(k_ip, buf+9, 4); //printf("%02x %02x %02x %02x\n",k_ip[0],k_ip[1],k_ip[2],k_ip[3]); if(k_ip[0] != 0x0) { //continue; writ_txt_ip(k_ip); read_txt_ip(s_ip,h_ip); printf("sip:%s\n",s_ip); memcpy(setip+s_len, s_ip, strlen(s_ip)+1); //printf("set ip:%s\n",setip); close(s_fd); system(setip); myread_txt_ip(s_gw, h_ip); memcpy(setgw+g_len, s_gw, strlen(s_gw)+1); printf("***********************\n"); printf("set gateway:%s\n",setgw); printf("***********************\n"); system(setgw); s_fd = make_send_multicast_init(s_ip); } //printf("================================================\n"); } } else if(buf[2] == CAM_TYPE_REBOOT) //得到请求重启控制器命令 { //printf("------3\n"); memcpy(smk, buf+3, 6); for(i = 0; i < 6; i+=1) { if(smk[i] != sys_id[i]) { sys_id_flag = 1; break; } } if(sys_id_flag == 0) { printf("reboot!!!!!!!!!!!!!!!!!!!\n"); system("reboot"); } } } usleep(100000); } close(s_fd); return 0; }