Changeset 9e2a109 for lib/format_wag.c
- Timestamp:
- 08/04/05 15:37:08 (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:
- ef55d05
- Parents:
- fe43699
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_wag.c
rfe43699 r9e2a109 30 30 31 31 #include "libtrace.h" 32 #include " format.h"32 #include "libtrace_int.h" 33 33 #include "wag.h" 34 34 … … 58 58 #define O_LARGEFILE 0 59 59 #endif 60 61 struct libtrace_format_data_t { 62 union { 63 /** Information about rtclients */ 64 struct { 65 char *hostname; 66 short port; 67 } rt; 68 char *path; /**< information for local sockets */ 69 } conn_info; 70 /** Information about the current state of the input device */ 71 union { 72 int fd; 73 #if HAVE_ZLIB 74 gzFile *file; 75 #else 76 FILE *file; 77 #endif 78 } input; 79 }; 80 60 81 static int wag_init_input(struct libtrace_t *libtrace) { 61 82 struct stat buf; … … 63 84 struct sockaddr_in remote; 64 85 struct sockaddr_un unix_sock; 65 if (!strncmp(libtrace->conn_info.path,"-",1)) { 86 libtrace->format_data = (struct libtrace_format_data_t *) 87 calloc(1,sizeof(struct libtrace_format_data_t)); 88 libtrace->format_data->conn_info.path = libtrace->uridata; 89 if (!strncmp(libtrace->format_data->conn_info.path,"-",1)) { 66 90 // STDIN 67 91 #if HAVE_ZLIB 68 libtrace-> input.file = gzdopen(STDIN, "r");92 libtrace->format_data->input.file = gzdopen(STDIN, "r"); 69 93 #else 70 libtrace-> input.file = stdin;94 libtrace->format_data->input.file = stdin; 71 95 #endif 72 96 73 97 } else { 74 if (stat(libtrace-> conn_info.path,&buf) == -1 ) {98 if (stat(libtrace->format_data->conn_info.path,&buf) == -1 ) { 75 99 perror("stat"); 76 100 return 0; … … 78 102 if (S_ISSOCK(buf.st_mode)) { 79 103 // SOCKET 80 if ((libtrace-> input.fd = socket(104 if ((libtrace->format_data->input.fd = socket( 81 105 AF_UNIX, SOCK_STREAM, 0)) == -1) { 82 106 perror("socket"); … … 87 111 snprintf(unix_sock.sun_path, 88 112 108,"%s" 89 ,libtrace-> conn_info.path);90 91 if (connect(libtrace-> input.fd,113 ,libtrace->format_data->conn_info.path); 114 115 if (connect(libtrace->format_data->input.fd, 92 116 (struct sockaddr *)&unix_sock, 93 117 sizeof(struct sockaddr)) == -1) { … … 101 125 // ourselves. However, this way is messy and 102 126 // we lose any error checking on "open" 103 libtrace-> input.file =127 libtrace->format_data->input.file = 104 128 gzdopen(open( 105 libtrace-> conn_info.path,129 libtrace->format_data->conn_info.path, 106 130 O_LARGEFILE), "r"); 107 131 #else 108 libtrace-> input.file =132 libtrace->format_data->input.file = 109 133 fdopen(open( 110 libtrace-> conn_info.path,134 libtrace->format_data->conn_info.path, 111 135 O_LARGEFILE), "r"); 112 136 #endif … … 118 142 static int wag_fin_input(struct libtrace_t *libtrace) { 119 143 #if HAVE_ZLIB 120 gzclose(libtrace-> input.file);144 gzclose(libtrace->format_data->input.file); 121 145 #else 122 fclose(libtrace-> input.file);146 fclose(libtrace->format_data->input.file); 123 147 #endif 124 148 } … … 137 161 switch(libtrace->sourcetype) { 138 162 case DEVICE: 139 if ((numbytes=read(libtrace-> input.fd,163 if ((numbytes=read(libtrace->format_data->input.fd, 140 164 buffer, 141 165 len)) == -1) { … … 146 170 default: 147 171 #if HAVE_ZLIB 148 if ((numbytes=gzread(libtrace-> input.file,172 if ((numbytes=gzread(libtrace->format_data->input.file, 149 173 buffer, 150 174 len)) == -1) { … … 154 178 #else 155 179 if ((numbytes=fread(buffer,len,1, 156 libtrace-> input.file)) == 0 ) {157 if(feof(libtrace-> input.file)) {180 libtrace->format_data->input.file)) == 0 ) { 181 if(feof(libtrace->format_data->input.file)) { 158 182 return 0; 159 183 } 160 if(ferror(libtrace-> input.file)) {184 if(ferror(libtrace->format_data->input.file)) { 161 185 perror("fread"); 162 186 return -1; … … 283 307 } 284 308 285 static struct format_t wag = {309 static struct libtrace_format_t wag = { 286 310 "wag", 287 311 "$Id$",
Note: See TracChangeset
for help on using the changeset viewer.