⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 op_logdump.c

📁 知名的开源IDS的日志工具
💻 C
📖 第 1 页 / 共 2 页
字号:
    switch(p->icmph->icmp_type)    {        case ICMP_ECHOREPLY:            fprintf(fp, "ID:%d  Seq:%d  ", p->icmph->icmp_id,                     p->icmph->icmp_seq);            fwrite("ECHO REPLY\n", 10, 1, fp);            break;        case ICMP_DEST_UNREACH:            fwrite("DESTINATION UNREACHABLE: ", 25, 1, fp);            switch(p->icmph->icmp_code)            {                case ICMP_NET_UNREACH:                    fwrite("NET UNREACHABLE", 15, 1, fp);                    break;                case ICMP_HOST_UNREACH:                    fwrite("HOST UNREACHABLE", 16, 1, fp);                    break;                case ICMP_PROT_UNREACH:                    fwrite("PROTOCOL UNREACHABLE", 20, 1, fp);                    break;                case ICMP_PORT_UNREACH:                    fwrite("PORT UNREACHABLE", 16, 1, fp);                    break;                case ICMP_FRAG_NEEDED:                    fwrite("FRAGMENTATION NEEDED", 20, 1, fp);                    break;                case ICMP_SR_FAILED:                    fwrite("SOURCE ROUTE FAILED", 19, 1, fp);                    break;                case ICMP_NET_UNKNOWN:                    fwrite("NET UNKNOWN", 11, 1, fp);                    break;                case ICMP_HOST_UNKNOWN:                    fwrite("HOST UNKNOWN", 12, 1, fp);                    break;                case ICMP_HOST_ISOLATED:                    fwrite("HOST ISOLATED", 13, 1, fp);                    break;                case ICMP_NET_ANO:                    fwrite("NET ANO", 7, 1, fp);                    break;                case ICMP_HOST_ANO:                    fwrite("HOST ANO", 8, 1, fp);                    break;                case ICMP_NET_UNR_TOS:                    fwrite("NET UNREACHABLE TOS", 19, 1, fp);                    break;                case ICMP_HOST_UNR_TOS:                    fwrite("HOST UNREACHABLE TOS", 20, 1, fp);                    break;                case ICMP_PKT_FILTERED:                    fwrite("PACKET FILTERED", 15, 1, fp);                    break;                case ICMP_PREC_VIOLATION:                    fwrite("PREC VIOLATION", 14, 1, fp);                    break;                case ICMP_PREC_CUTOFF:                    fwrite("PREC CUTOFF", 12, 1, fp);                    break;                default:                    fwrite("UNKNOWN", 7, 1, fp);                    break;            }/*            {                Packet orig_p;                int orig_iph_size;                bzero((char *) &orig_p, sizeof(Packet));                orig_p.iph = p->orig_iph;                orig_p.tcph = p->orig_tcph;                orig_p.udph = p->orig_udph;                orig_p.sp = p->orig_sp;                orig_p.dp = p->orig_dp;                if(orig_p.iph != NULL)                {                    orig_iph_size = orig_p.iph->ip_hlen << 2;                    fprintf(fp, "\n** ORIGINAL DATAGRAM DUMP:\n");                    fprintf(fp, "** END OF DUMP");                }                else                {                    fprintf(fp, "\nORIGINAL DATAGRAM TRUNCATED");                }            }*/            break;        case ICMP_SOURCE_QUENCH:            fwrite("SOURCE QUENCH", 13, 1, fp);            break;        case ICMP_REDIRECT:            fwrite("REDIRECT", 8, 1, fp);            break;        case ICMP_ECHO:            fprintf(fp, "ID:%d   Seq:%d  ", p->icmph->icmp_id, p->icmph->icmp_seq);            fwrite("ECHO", 4, 1, fp);            break;        case ICMP_TIME_EXCEEDED:            fwrite("TTL EXCEEDED", 12, 1, fp);            break;        case ICMP_PARAMETERPROB:            fwrite("PARAMETER PROBLEM", 17, 1, fp);            break;        case ICMP_TIMESTAMP:            fwrite("TIMESTAMP REQUEST", 17, 1, fp);            break;        case ICMP_TIMESTAMPREPLY:            fwrite("TIMESTAMP REPLY", 15, 1, fp);            break;        case ICMP_INFO_REQUEST:            fwrite("INFO REQUEST", 12, 1, fp);            break;        case ICMP_INFO_REPLY:            fwrite("INFO REPLY", 10, 1, fp);            break;        case ICMP_ADDRESS:            fwrite("ADDRESS REQUEST", 15, 1, fp);            break;        case ICMP_ADDRESSREPLY:            fwrite("ADDRESS REPLY", 13, 1, fp);            break;        default:            fwrite("UNKNOWN", 7, 1, fp);            break;    }    putc('\n', fp);}void PrintIpOptions(FILE * fp, Packet * p){    int i;    int j;    u_long init_offset;    u_long print_offset;    init_offset = ftell(fp);    if(!p->ip_option_count || p->ip_option_count > 40)        return;    fprintf(fp, "IP Options (%d) => ", p->ip_option_count);    for(i = 0; i < (int) p->ip_option_count; i++)    {        print_offset = ftell(fp);        if((print_offset - init_offset) > 60)        {            fwrite("\nIP Options => ", 15, 1, fp);            init_offset = ftell(fp);        }                    switch(p->ip_options[i].code)        {            case IPOPT_RR:                fwrite("RR ", 3, 1, fp);                break;            case IPOPT_EOL:                fwrite("EOL ", 4, 1, fp);                break;            case IPOPT_NOP:                fwrite("NOP ", 4, 1, fp);                break;            case IPOPT_TS:                fwrite("TS ", 3, 1, fp);                break;            case IPOPT_SECURITY:                fwrite("SEC ", 4, 1, fp);                break;            case IPOPT_LSRR:            case IPOPT_LSRR_E:                fwrite("LSRR ", 5, 1, fp);                break;            case IPOPT_SATID:                fwrite("SID ", 4, 1, fp);                break;            case IPOPT_SSRR:                fwrite("SSRR ", 5, 1, fp);                break;            case IPOPT_RTRALT:                fwrite("RTRALT ", 7, 1, fp);                break;                default:                fprintf(fp, "Opt %d: ", p->ip_options[i].code);                if(p->ip_options[i].len)                {                    for(j = 0; j < (int)(p->ip_options[i].len - 1); j += 2)                    {                        fprintf(fp, "%02X%02X ", p->ip_options[i].data[j],                                 p->ip_options[i].data[j + 1]);                    }                }                break;        }    }    fwrite("\n", 1, 1, fp);}void PrintTcpOptions(FILE * fp, Packet * p){    int i;    int j;    u_char tmp[5];    u_long init_offset;    u_long print_offset;    init_offset = ftell(fp);    fprintf(fp, "TCP Options (%d) => ", p->tcp_option_count);    if(p->tcp_option_count > 40 || !p->tcp_option_count)        return;    for(i = 0; i < (int) p->tcp_option_count; i++)    {        print_offset = ftell(fp);        if((print_offset - init_offset) > 60)        {            fwrite("\nTCP Options => ", 16, 1, fp);            init_offset = ftell(fp);        }                    switch(p->tcp_options[i].code)        {            case TCPOPT_MAXSEG:                bzero((char *) tmp, 5);                fwrite("MSS: ", 5, 1, fp);                strncpy((char*)tmp, (char*) (p->tcp_options[i].data), 2);                fprintf(fp, "%u ", EXTRACT_16BITS(tmp));                break;            case TCPOPT_EOL:                fwrite("EOL ", 4, 1, fp);                break;            case TCPOPT_NOP:                fwrite("NOP ", 4, 1, fp);                break;            case TCPOPT_WSCALE:                fprintf(fp, "WS: %u ", p->tcp_options[i].data[0]);                break;            case TCPOPT_SACK:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 2);                fprintf(fp, "Sack: %u@", EXTRACT_16BITS(tmp));                bzero((char *) tmp, 5);                memcpy(tmp, (p->tcp_options[i].data) + 2, 2);                fprintf(fp, "%u ", EXTRACT_16BITS(tmp));                break;            case TCPOPT_SACKOK:                fwrite("SackOK ", 7, 1, fp);                break;            case TCPOPT_ECHO:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "Echo: %u ", EXTRACT_32BITS(tmp));                break;            case TCPOPT_ECHOREPLY:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "Echo Rep: %u ", EXTRACT_32BITS(tmp));                break;            case TCPOPT_TIMESTAMP:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "TS: %u ", EXTRACT_32BITS(tmp));                bzero((char *) tmp, 5);                memcpy(tmp, (p->tcp_options[i].data) + 4, 4);                fprintf(fp, "%u ", EXTRACT_32BITS(tmp));                break;            case TCPOPT_CC:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "CC %u ", EXTRACT_32BITS(tmp));                break;            case TCPOPT_CCNEW:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "CCNEW: %u ", EXTRACT_32BITS(tmp));                break;            case TCPOPT_CCECHO:                bzero((char *) tmp, 5);                memcpy(tmp, p->tcp_options[i].data, 4);                fprintf(fp, "CCECHO: %u ", EXTRACT_32BITS(tmp));                break;            default:                if(p->tcp_options[i].len > 2)                {                    fprintf(fp, "Opt %d (%d): ", p->tcp_options[i].code,                            (int) p->tcp_options[i].len);                    for(j = 0; j < (int) (p->tcp_options[i].len - 1); j += 2)                    {                        fprintf(fp, "%02X%02X ", p->tcp_options[i].data[j],                                 p->tcp_options[i].data[j + 1]);                    }                }                else                {                    fprintf(fp, "Opt %d ", p->tcp_options[i].code);                }                break;        }    }    fwrite("\n", 1, 1, fp);}FILE *OpenLogFile(char *filename){     FILE *tmp;       if((tmp = fopen(filename, "a+")) == NULL)    {        FatalError("ERROR => fopen(%s) failed: %s\n", filename,                    strerror(errno));    }     return tmp;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -