Deleted Added
full compact
20c20
< "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.21.2.3 2005/07/10 22:09:34 guy Exp $ (LBL)";
---
> "@(#) $Header: /tcpdump/master/libpcap/pcap-dag.c,v 1.21.2.7 2007/06/22 06:43:58 guy Exp $ (LBL)";
49,50d48
< #define MIN_DAG_SNAPLEN 12
< #define MAX_DAG_SNAPLEN 2040
53a52,63
> /*
> * A header containing additional MTP information.
> */
> #define MTP2_SENT_OFFSET 0 /* 1 byte */
> #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
> #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
> #define MTP2_HDR_LEN 4 /* length of the header */
>
> #define MTP2_ANNEX_A_NOT_USED 0
> #define MTP2_ANNEX_A_USED 1
> #define MTP2_ANNEX_A_USED_UNKNOWN 2
>
73,84d82
< /*
< * Swap byte ordering of unsigned long long timestamp on a big endian
< * machine.
< */
< #define SWAP_TS(ull) ((ull & 0xff00000000000000LL) >> 56) | \
< ((ull & 0x00ff000000000000LL) >> 40) | \
< ((ull & 0x0000ff0000000000LL) >> 24) | \
< ((ull & 0x000000ff00000000LL) >> 8) | \
< ((ull & 0x00000000ff000000LL) << 8) | \
< ((ull & 0x0000000000ff0000LL) << 24) | \
< ((ull & 0x000000000000ff00LL) << 40) | \
< ((ull & 0x00000000000000ffLL) << 56)
86d83
<
95a93,96
> #define MAX_DAG_PACKET 65536
>
> static unsigned char TempPkt[MAX_DAG_PACKET];
>
142,144d142
< #ifdef linux
< free(p->md.device);
< #endif
225c223
< p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, (void**)&(p->md.dag_mem_bottom));
---
> p->md.dag_mem_top = dag_advance_stream(p->fd, p->md.dag_stream, &(p->md.dag_mem_bottom));
285d282
< case TYPE_AAL5:
286a284,290
> #ifdef TYPE_AAL5
> case TYPE_AAL5:
> if (header->type == TYPE_AAL5) {
> packet_len = ntohs(header->wlen);
> caplen = rlen - dag_record_size;
> }
> #endif
302,305c306
< if (header->type == TYPE_AAL5) {
< packet_len = ntohs(header->wlen);
< caplen = rlen - dag_record_size;
< } else if(header->type == TYPE_ATM) {
---
> if (header->type == TYPE_ATM) {
328a330,332
> #ifdef TYPE_DSM_COLOR_ETH
> case TYPE_DSM_COLOR_ETH:
> #endif
340a345,347
> #ifdef TYPE_DSM_COLOR_HDLC_POS
> case TYPE_DSM_COLOR_HDLC_POS:
> #endif
351a359,361
> #ifdef TYPE_COLOR_MC_HDLC_POS
> case TYPE_COLOR_MC_HDLC_POS:
> #endif
359a370
> /* jump the MC_HDLC_HEADER */
360a372,383
> if (p->linktype == DLT_MTP2_WITH_PHDR) {
> /* Add the MTP2 Pseudo Header */
> caplen += MTP2_HDR_LEN;
> packet_len += MTP2_HDR_LEN;
>
> TempPkt[MTP2_SENT_OFFSET] = 0;
> TempPkt[MTP2_ANNEX_A_USED_OFFSET] = MTP2_ANNEX_A_USED_UNKNOWN;
> *(TempPkt+MTP2_LINK_NUMBER_OFFSET) = ((header->rec.mc_hdlc.mc_header>>16)&0x01);
> *(TempPkt+MTP2_LINK_NUMBER_OFFSET+1) = ((header->rec.mc_hdlc.mc_header>>24)&0xff);
> memcpy(TempPkt+MTP2_HDR_LEN, dp, caplen);
> dp = TempPkt;
> }
362a386,390
> default:
> /* Unhandled ERF type.
> * Ignore rather than generating error
> */
> continue;
379a408,422
> #ifdef TYPE_DSM_COLOR_HDLC_POS
> /* in this type the color value overwrites the lctr */
> case TYPE_DSM_COLOR_HDLC_POS:
> break;
> #endif
> #ifdef TYPE_DSM_COLOR_ETH
> /* in this type the color value overwrites the lctr */
> case TYPE_DSM_COLOR_ETH:
> break;
> #endif
> #ifdef TYPE_COLOR_MC_HDLC_POS
> case TYPE_COLOR_MC_HDLC_POS:
> break;
> #endif
>
397c440
< ts = SWAP_TS(header->ts);
---
> ts = SWAPLL(header->ts);
447a491,493
> * snaplen is now also ignored, until we get per-stream slen support. Set
> * slen with approprite DAG tool BEFORE pcap_open_live().
> *
458c504
< char * newDev;
---
> char * newDev = NULL;
481,482d526
< newDev = (char *)malloc(strlen(device) + 16);
<
483a528,532
> newDev = (char *)malloc(strlen(device) + 16);
> if (newDev == NULL) {
> snprintf(ebuf, PCAP_ERRBUF_SIZE, "Can't allocate string for device name: %s\n", pcap_strerror(errno));
> goto fail;
> }
497,500c546,553
< if (strstr(device, "/dev") == NULL) {
< newDev[0] = '\0';
< strcat(newDev, "/dev/");
< strcat(newDev,device);
---
> if (strncmp(device, "/dev/", 5) != 0) {
> newDev = (char *)malloc(strlen(device) + 5);
> if (newDev == NULL) {
> snprintf(ebuf, PCAP_ERRBUF_SIZE, "Can't allocate string for device name: %s\n", pcap_strerror(errno));
> goto fail;
> }
> strcpy(newDev, "/dev/");
> strcat(newDev, device);
502,503d554
< } else {
< device = strdup(device);
505,509d555
<
< if (device == NULL) {
< snprintf(ebuf, PCAP_ERRBUF_SIZE, "str_dup: %s\n", pcap_strerror(errno));
< goto fail;
< }
522c568
< goto fail;
---
> goto failclose;
531c577
< goto fail;
---
> goto faildetach;
549c595
< goto fail;
---
> goto faildetach;
555c601
< goto fail;
---
> goto failclose;
559a606,610
> /* XXX Not calling dag_configure() to set slen; this is unsafe in
> * multi-stream environments as the gpp config is global.
> * Once the firmware provides 'per-stream slen' this can be supported
> * again via the Config API without side-effects */
> #if 0
560a612,613
> /* This is a really bad idea, as different cards have different
> * valid slen ranges. Should fix in Config API. */
571c624
< goto fail;
---
> goto faildetach;
573c626,627
<
---
> #endif
>
577c631
< goto fail;
---
> goto faildetach;
582c636
< goto fail;
---
> goto failclose;
610c664
< goto fail;
---
> goto failstop;
620c674
< goto fail;
---
> goto failstop;
627c681
< goto fail;
---
> goto failstop;
635,641c689,691
< #ifdef linux
< handle->md.device = (char *)device;
< handle->md.timeout = to_ms;
< #else
< free((char *)device);
< device = NULL;
< #endif
---
> if (newDev != NULL) {
> free((char *)newDev);
> }
652c702,703
<
---
> handle->md.stat.ps_drop = 0;
> handle->md.stat.ps_recv = 0;
654a706,733
> #ifdef HAVE_DAG_STREAMS_API
> failstop:
> if (handle != NULL) {
> if (dag_stop_stream(handle->fd, handle->md.dag_stream) < 0)
> fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
> }
>
> faildetach:
> if (handle != NULL) {
> if (dag_detach_stream(handle->fd, handle->md.dag_stream) < 0)
> fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
> }
> #else
> failstop:
> if (handle != NULL) {
> if (dag_stop(p->fd) < 0)
> fprintf(stderr,"dag_stop: %s\n", strerror(errno));
> }
> #endif /* HAVE_DAG_STREAMS_API */
>
> failclose:
> if (handle != NULL) {
> if (dag_close(handle->fd) < 0)
> fprintf(stderr,"dag_close: %s\n", strerror(errno));
> }
> if (handle != NULL)
> delete_pcap_dag(handle);
>
809c888,889
< int daglinktype;
---
> int index=0;
> uint8_t types[255];
811c891,893
< if (p->dlt_list == NULL && (p->dlt_list = malloc(2*sizeof(*(p->dlt_list)))) == NULL) {
---
> memset(types, 0, 255);
>
> if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
815a898,908
> p->linktype = 0;
>
> #ifdef HAVE_DAG_GET_ERF_TYPES
> /* Get list of possible ERF types for this card */
> if (dag_get_erf_types(p->fd, types, 255) < 0) {
> snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
> return (-1);
> }
>
> while (types[index]) {
> #else
817c910
< daglinktype = dag_linktype(p->fd);
---
> types[index] = dag_linktype(p->fd);
819c912,914
< switch(daglinktype) {
---
> {
> #endif
> switch(types[index]) {
821,830c916,930
< case TYPE_HDLC_POS:
< case TYPE_COLOR_HDLC_POS:
< if (p->dlt_list != NULL) {
< p->dlt_count = 2;
< p->dlt_list[0] = DLT_CHDLC;
< p->dlt_list[1] = DLT_PPP_SERIAL;
< p->dlt_list[2] = DLT_FRELAY;
< }
< p->linktype = DLT_CHDLC;
< break;
---
> case TYPE_HDLC_POS:
> #ifdef TYPE_COLOR_HDLC_POS
> case TYPE_COLOR_HDLC_POS:
> #endif
> #ifdef TYPE_DSM_COLOR_HDLC_POS
> case TYPE_DSM_COLOR_HDLC_POS:
> #endif
> if (p->dlt_list != NULL) {
> p->dlt_list[index++] = DLT_CHDLC;
> p->dlt_list[index++] = DLT_PPP_SERIAL;
> p->dlt_list[index++] = DLT_FRELAY;
> }
> if(!p->linktype)
> p->linktype = DLT_CHDLC;
> break;
832,850c932,955
< case TYPE_ETH:
< case TYPE_COLOR_ETH:
< /*
< * This is (presumably) a real Ethernet capture; give it a
< * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
< * that an application can let you choose it, in case you're
< * capturing DOCSIS traffic that a Cisco Cable Modem
< * Termination System is putting out onto an Ethernet (it
< * doesn't put an Ethernet header onto the wire, it puts raw
< * DOCSIS frames out on the wire inside the low-level
< * Ethernet framing).
< */
< if (p->dlt_list != NULL) {
< p->dlt_count = 2;
< p->dlt_list[0] = DLT_EN10MB;
< p->dlt_list[1] = DLT_DOCSIS;
< }
< p->linktype = DLT_EN10MB;
< break;
---
> case TYPE_ETH:
> #ifdef TYPE_COLOR_ETH
> case TYPE_COLOR_ETH:
> #endif
> #ifdef TYPE_DSM_COLOR_ETH
> case TYPE_DSM_COLOR_ETH:
> #endif
> /*
> * This is (presumably) a real Ethernet capture; give it a
> * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
> * that an application can let you choose it, in case you're
> * capturing DOCSIS traffic that a Cisco Cable Modem
> * Termination System is putting out onto an Ethernet (it
> * doesn't put an Ethernet header onto the wire, it puts raw
> * DOCSIS frames out on the wire inside the low-level
> * Ethernet framing).
> */
> if (p->dlt_list != NULL) {
> p->dlt_list[index++] = DLT_EN10MB;
> p->dlt_list[index++] = DLT_DOCSIS;
> }
> if(!p->linktype)
> p->linktype = DLT_EN10MB;
> break;
852,862c957,973
< case TYPE_AAL5:
< case TYPE_ATM:
< case TYPE_MC_ATM:
< case TYPE_MC_AAL5:
< if (p->dlt_list != NULL) {
< p->dlt_count = 2;
< p->dlt_list[0] = DLT_ATM_RFC1483;
< p->dlt_list[1] = DLT_SUNATM;
< }
< p->linktype = DLT_ATM_RFC1483;
< break;
---
> case TYPE_ATM:
> #ifdef TYPE_AAL5
> case TYPE_AAL5:
> #endif
> #ifdef TYPE_MC_ATM
> case TYPE_MC_ATM:
> #endif
> #ifdef TYPE_MC_AAL5
> case TYPE_MC_AAL5:
> #endif
> if (p->dlt_list != NULL) {
> p->dlt_list[index++] = DLT_ATM_RFC1483;
> p->dlt_list[index++] = DLT_SUNATM;
> }
> if(!p->linktype)
> p->linktype = DLT_ATM_RFC1483;
> break;
864,873c975,990
< case TYPE_MC_HDLC:
< if (p->dlt_list != NULL) {
< p->dlt_count = 4;
< p->dlt_list[0] = DLT_CHDLC;
< p->dlt_list[1] = DLT_PPP_SERIAL;
< p->dlt_list[2] = DLT_FRELAY;
< p->dlt_list[3] = DLT_MTP2;
< }
< p->linktype = DLT_CHDLC;
< break;
---
> #ifdef TYPE_COLOR_MC_HDLC_POS
> case TYPE_COLOR_MC_HDLC_POS:
> #endif
> #ifdef TYPE_MC_HDLC
> case TYPE_MC_HDLC:
> if (p->dlt_list != NULL) {
> p->dlt_list[index++] = DLT_CHDLC;
> p->dlt_list[index++] = DLT_PPP_SERIAL;
> p->dlt_list[index++] = DLT_FRELAY;
> p->dlt_list[index++] = DLT_MTP2;
> p->dlt_list[index++] = DLT_MTP2_WITH_PHDR;
> }
> if(!p->linktype)
> p->linktype = DLT_CHDLC;
> break;
> #endif
875,877c992,995
< case TYPE_LEGACY:
< p->linktype = DLT_NULL;
< break;
---
> case TYPE_LEGACY:
> if(!p->linktype)
> p->linktype = DLT_NULL;
> break;
879,881c997,999
< default:
< snprintf(p->errbuf, sizeof(p->errbuf), "unknown DAG linktype %d\n", daglinktype);
< return (-1);
---
> default:
> snprintf(p->errbuf, sizeof(p->errbuf), "unknown DAG linktype %d", types[index]);
> return (-1);
882a1001
> } /* switch */
884a1004,1005
> p->dlt_count = index;
>