/* parse a multipart encoded form (for file upload) see rfc1867 */ static void load_multipart(struct cgi_state *cgi) { char *boundary; FILE *f = stdin; int len = cgi->content_length; char *line; if (!cgi->content_type) return; boundary = strstr(cgi->content_type, "boundary="); if (!boundary) return; boundary += 9; trim_tail(boundary, CRLF); line = grab_line(f, CRLF, &len); if (strncmp(line,"--", 2) != 0 || strncmp(line+2,boundary,strlen(boundary)) != 0) { fprintf(stderr,"Malformed multipart?\n"); free(line); return; } if (strcmp(line+2+strlen(boundary), "--") == 0) { /* the end is only the beginning ... */ free(line); return; } free(line); while (load_one_part(cgi, f, &len, boundary) == 0) ; }
/* we are a mini-web server. We need to read the request from stdin */ static int setup_standalone(struct cgi_state *cgi) { char line[1024]; char *url=NULL; char *p; while (fgets(line, sizeof(line)-1, stdin)) { trim_tail(line, CRLF); if (line[0] == 0) break; if (strncasecmp(line,"GET ", 4)==0) { cgi->got_request = 1; url = strdup(&line[4]); } else if (strncasecmp(line,"POST ", 5)==0) { cgi->got_request = 1; cgi->request_post = 1; url = strdup(&line[5]); } else if (strncasecmp(line,"PUT ", 4)==0) { cgi->got_request = 1; cgi->http_error(cgi, "400 Bad Request", "", "This server does not accept PUT requests"); return -1; } else if (strncasecmp(line,"Content-Length: ", 16)==0) { add_header(cgi, line); cgi->content_length = atoi(&line[16]); } else if (strncasecmp(line,"Content-Type: ", 14)==0) { add_header(cgi, line); cgi->content_type = strdup(&line[14]); } else { add_header(cgi, line); } /* ignore all other requests! */ } if (!url) { cgi->http_error(cgi, "400 Bad Request", "", "You must specify a GET or POST request"); exit(1); } /* trim the URL */ if ((p = strchr(url,' ')) || (p=strchr(url,'\t'))) { *p = 0; } /* anything following a ? in the URL is part of the query string */ if ((p=strchr(url,'?'))) { cgi->query_string = p+1; *p = 0; } cgi->url = url; cgi->pathinfo = url; return 0; }
static enum ofp_return_code ofp_ip_output_add_eth(odp_packet_t pkt, struct ip_out *odata) { uint32_t l2_size; void *l2_addr; struct ofp_ether_header *eth; uint32_t addr; uint32_t is_link_local = 0; trim_tail(pkt, odp_be_to_cpu_16(odata->ip->ip_len)); if (!odata->gw) { /* link local */ odata->gw = odata->ip->ip_dst.s_addr; is_link_local = 1; } if (!ETH_WITH_VLAN(odata->dev_out)) l2_size = sizeof(struct ofp_ether_header); else l2_size = sizeof(struct ofp_ether_vlan_header); l2_addr = trim_for_output(pkt, l2_size, odata->ip->ip_hl * 4); if (odp_unlikely(l2_addr == NULL)) { OFP_DBG("l2_addr == NULL"); return OFP_PKT_DROP; } eth = l2_addr; addr = odp_be_to_cpu_32(odata->ip->ip_dst.s_addr); if (OFP_IN_MULTICAST(addr)) { eth->ether_dhost[0] = 0x01; eth->ether_dhost[1] = 0x00; eth->ether_dhost[2] = 0x5e; eth->ether_dhost[3] = (addr >> 16) & 0x7f; eth->ether_dhost[4] = (addr >> 8) & 0xff; eth->ether_dhost[5] = addr & 0xff; } else if (odata->dev_out->ip_addr == odata->ip->ip_dst.s_addr ||