void callback(unsigned char *user, const struct pcap_pkthdr *h, const unsigned char *bytes) { int len; const unsigned char *buf; const unsigned char *cur; unsigned char url[1024]; int url_len = 0; char data[1400]; int is_req; int hdr_len; int ret; buf = bytes; len = h->caplen; cur = buf; if (!is_tcp(buf, len)){ return; } cur += 54; len -= 54;//tcp hdr ip hdr is_req = is_http_request(cur, len); hdr_len = http_hdr_len(cur, len); switch (is_req){ case 0: break; case 1: ret = get_url(url,&url_len, cur, hdr_len); if (ret == 0){ logging(url,url_len); //printf("url_len:%d\n",url_len); } break; case 2: ret = get_url(url,&url_len, cur, hdr_len); if (ret == 0){ logging(url,url_len); } //get_data(data, curl, len); break; default: break; } }
inline void process_input() { char c; cli(); while ( ! input_buffer_.empty()) { c = input_buffer_.front(); input_buffer_.pop_front(); sei(); cmd_buffer_.append(c); switch (session_type_) { case UNDECIDED: if ( c == '\n') { if (is_http_request()) { session_type_ = HTTP_SESSION; handle_http_request(c); } else { session_type_ = CLI_SESSION; handle_cli_session(c); } } break; case CLI_SESSION: handle_cli_session(c); break; case HTTP_SESSION: handle_http_request(c); break; } cli(); } sei(); }