Changeset 7ac9705
- Timestamp:
- 03/06/06 15:31:15 (16 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- e4e1635
- Parents:
- eeab9832
- Location:
- lib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pcap.c
reeab9832 r7ac9705 270 270 static int pcap_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 271 271 int pcapbytes = 0; 272 273 packet->type = RT_DATA_PCAP; 272 int linktype; 273 274 assert(libtrace->format_data); 275 linktype = pcap_datalink(DATA(libtrace)->input.pcap); 276 packet->type = pcap_dlt_to_rt(linktype); 274 277 275 278 pcapbytes = pcap_dispatch(INPUT.pcap, … … 318 321 int linktype = 0; 319 322 pcapptr = (struct pcap_pkthdr *)packet->header; 320 linktype = pcap_datalink(DATA(packet->trace)->input.pcap); 323 324 /* pcap doesn't store dlt in the framing header so we need 325 * rt to do it for us 326 */ 327 linktype = rt_to_pcap_dlt(packet->type); 328 /* 329 if (packet->trace->format_data == NULL) 330 linktype = rt_to_pcap_dlt(packet->type); 331 else 332 linktype = pcap_datalink(DATA(packet->trace)->input.pcap); 333 */ 321 334 return pcap_dlt_to_libtrace(linktype); 322 335 } … … 420 433 421 434 static int pcap_get_fd(const libtrace_t *trace) { 435 436 assert(trace->format_data); 422 437 return pcap_fileno(DATA(trace)->input.pcap); 423 438 } -
lib/format_rt.c
reeab9832 r7ac9705 128 128 if (connect(RT_INFO->input_fd, (struct sockaddr *)&remote, 129 129 sizeof(struct sockaddr)) == -1) { 130 perror("connect (inet)"); 131 return -1; 130 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 131 "Could not connect to host %s on port %d", 132 RT_INFO->hostname, RT_INFO->port); 133 return -1; 132 134 } 133 135 … … 135 137 136 138 if (recv(RT_INFO->input_fd, &connect_msg, sizeof(rt_header_t), 0) != sizeof(rt_header_t) ) { 137 printf("An error occured while connecting to %s\n", RT_INFO->hostname); 139 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 140 "Could not receive connection message from %s", 141 RT_INFO->hostname); 138 142 return -1; 139 143 } … … 148 152 } 149 153 reason = deny_hdr.reason; 150 printf("Connection attempt is denied by the server: %s\n", 151 rt_deny_reason(reason)); 154 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 155 "Connection attempt is denied: %s", 156 rt_deny_reason(reason)); 152 157 return -1; 153 158 case RT_HELLO: … … 157 162 sizeof(rt_hello_t), 0) 158 163 != sizeof(rt_hello_t)) { 159 printf("Failed to read hello options\n"); 160 return 0; 164 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 165 "Failed to receive RT_HELLO options"); 166 return -1; 161 167 } 162 168 reliability = hello_opts.reliable; … … 164 170 return 0; 165 171 default: 166 printf("Unexpected message type: %d\n", connect_msg.type); 172 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 173 "Unknown message type received: %d", 174 connect_msg.type); 167 175 return -1; 168 176 } 169 177 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 178 "Somehow you managed to reach this unreachable code"); 170 179 return -1; 171 180 } … … 276 285 static int rt_set_format(libtrace_t *libtrace, libtrace_packet_t *packet) 277 286 { 287 288 if (packet->type >= RT_DATA_PCAP) { 289 if (!RT_INFO->dummy_pcap) { 290 RT_INFO->dummy_pcap = trace_create_dead("pcap:-"); 291 } 292 packet->trace = RT_INFO->dummy_pcap; 293 return; 294 } 295 278 296 switch (packet->type) { 279 297 case RT_DATA_ERF: … … 282 300 } 283 301 packet->trace = RT_INFO->dummy_erf; 284 break;285 case RT_DATA_PCAP:286 if (!RT_INFO->dummy_pcap) {287 RT_INFO->dummy_pcap = trace_create_dead("pcap:-");288 }289 packet->trace = RT_INFO->dummy_pcap;290 302 break; 291 303 case RT_DATA_WAG: … … 395 407 packet->type = pkt_hdr.type; 396 408 pkt_size = pkt_hdr.length; 397 398 switch(packet->type) { 399 case RT_DATA_ERF: 400 case RT_DATA_PCAP: 401 case RT_DATA_WAG: 402 case RT_DATA_LEGACY_ETH: 403 case RT_DATA_LEGACY_POS: 404 case RT_DATA_LEGACY_ATM: 405 if (rt_read(libtrace, buffer, pkt_size) != pkt_size) { 406 printf("Error receiving packet\n"); 407 return -1; 408 } 409 410 if (rt_set_format(libtrace, packet) < 0) { 411 return -1; 409 packet->size = pkt_hdr.length; 410 411 if (packet->type >= RT_DATA_SIMPLE) { 412 if (rt_read(libtrace, buffer, pkt_size) != pkt_size) { 413 printf("Error receiving packet\n"); 414 return -1; 415 } 416 417 if (rt_set_format(libtrace, packet) < 0) { 418 return -1; 419 } 420 rt_set_payload(packet); 421 422 if (reliability > 0) { 423 424 if (rt_send_ack(libtrace, pkt_hdr.sequence) 425 == -1) 426 { 427 return -1; 412 428 } 413 rt_set_payload(packet); 414 415 if (reliability > 0) { 416 417 if (rt_send_ack(libtrace, pkt_hdr.sequence) 418 == -1) 419 { 420 return -1; 421 } 422 } 423 break; 424 case RT_STATUS: 425 case RT_DUCK: 426 if (rt_read(libtrace, buffer, pkt_size) != 427 pkt_size) { 428 printf("Error receiving status packet\n"); 429 return -1; 430 } 431 packet->header = 0; 432 packet->payload = buffer; 433 break; 434 case RT_END_DATA: 435 return 0; 436 case RT_PAUSE_ACK: 437 /* FIXME: Do something useful */ 438 break; 439 case RT_OPTION: 440 /* FIXME: Do something useful here as well */ 441 break; 442 default: 443 printf("Bad rt type for client receipt: %d\n", 429 } 430 } else { 431 switch(packet->type) { 432 case RT_STATUS: 433 case RT_DUCK: 434 if (rt_read(libtrace, buffer, pkt_size) != 435 pkt_size) { 436 printf("Error receiving status packet\n"); 437 return -1; 438 } 439 packet->header = 0; 440 packet->payload = buffer; 441 break; 442 case RT_END_DATA: 443 return 0; 444 case RT_PAUSE_ACK: 445 /* FIXME: Do something useful */ 446 break; 447 case RT_OPTION: 448 /* FIXME: Do something useful here as well */ 449 break; 450 default: 451 printf("Bad rt type for client receipt: %d\n", 444 452 pkt_hdr.type); 453 } 445 454 } 446 455 return trace_get_capture_length(packet)+trace_get_framing_length(packet); -
lib/libtrace.h
reeab9832 r7ac9705 112 112 size_t size; /**< trace_get_framing_length() 113 113 * +trace_get_capture_length() */ 114 uint 8_t type; /**< rt protocol type for the packet */114 uint32_t type; /**< rt protocol type for the packet */ 115 115 } libtrace_packet_t; 116 116 -
lib/libtrace_int.h
reeab9832 r7ac9705 317 317 libtrace_linktype_t pcap_dlt_to_libtrace(int dlt); 318 318 char libtrace_to_pcap_dlt(libtrace_linktype_t type); 319 enum rt_field_t pcap_dlt_to_rt(int dlt); 320 int rt_to_pcap_dlt(enum rt_field_t rt_type); 319 321 libtrace_linktype_t erf_type_to_libtrace(char erf); 320 322 char libtrace_to_erf_type(libtrace_linktype_t linktype); -
lib/linktypes.c
r643105b r7ac9705 2 2 #include <pcap.h> 3 3 #include "dagformat.h" 4 #include "rt_protocol.h" 5 #include <assert.h> 4 6 5 7 /* This file maps libtrace types to/from pcap DLT and erf types … … 46 48 } 47 49 50 enum rt_field_t pcap_dlt_to_rt(int dlt) 51 { 52 /* For pcap the rt type is just the dlt + a fixed value */ 53 return dlt + RT_DATA_PCAP; 54 } 55 56 int rt_to_pcap_dlt(enum rt_field_t rt_type) 57 { 58 assert(rt_type >= RT_DATA_PCAP); 59 return rt_type - RT_DATA_PCAP; 60 } 61 48 62 libtrace_linktype_t erf_type_to_libtrace(char erf) 49 63 { -
lib/rt_protocol.h
r5fb2251 r7ac9705 3 3 4 4 #include "libtrace.h" 5 #include <pcap.h> 5 6 6 7 #define CAPTURE_PORT 3434 … … 9 10 #define RT_MAX_HDR_SIZE 256 10 11 #define MAX_SEQUENCE 2147483647 12 13 #define RT_DATA_SIMPLE 1000 14 #define RT_DATA_PCAP 2000 11 15 12 16 /* Type field definitions */ … … 24 28 RT_OPTION =11, /* Option request */ 25 29 26 RT_DATA_ERF =12, /* Erf data packet */ 27 RT_DATA_PCAP =13, /* Pcap data packet */ 28 RT_DATA_WAG =14, /* Wag data packet */ 29 RT_DATA_LEGACY_ATM =15, /* Legacy ATM packet */ 30 RT_DATA_LEGACY_POS =16, /* Legacy POS packet */ 31 RT_DATA_LEGACY_ETH =17 /* Legacy ETH packet */ 30 RT_DATA_ERF =RT_DATA_SIMPLE + TRACE_FORMAT_ERF, 31 RT_DATA_WAG =RT_DATA_SIMPLE + TRACE_FORMAT_WAG, 32 RT_DATA_LEGACY_ATM =RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_ATM, 33 RT_DATA_LEGACY_POS =RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_POS, 34 RT_DATA_LEGACY_ETH =RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_ETH, 35 36 RT_DATA_PCAP_NULL =RT_DATA_PCAP + DLT_NULL, 37 RT_DATA_PCAP_EN10MB =RT_DATA_PCAP + DLT_EN10MB, 38 RT_DATA_PCAP_ATM_RFC1483 =RT_DATA_PCAP + DLT_ATM_RFC1483, 39 RT_DATA_PCAP_IEEE802_11 =RT_DATA_PCAP + DLT_IEEE802_11, 40 #ifdef DLT_LINUX_SLL 41 RT_DATA_PCAP_LINUX_SLL =RT_DATA_PCAP + DLT_LINUX_SLL, 42 #endif 43 #ifdef DLT_PFLOG 44 RT_DATA_PCAP_PFLOG =RT_DATA_PCAP + DLT_PFLOG, 45 #endif 46 32 47 }; 33 48 -
lib/trace.c
reeab9832 r7ac9705 379 379 return 0; 380 380 } 381 381 382 libtrace->format_data = NULL; 382 383 free(scan); 383 384 return libtrace;
Note: See TracChangeset
for help on using the changeset viewer.