(/home/sate/Testcases/c/cve/wireshark-1.2.0/text2pcap.c) |
| |
| 1104 | | | parse_options (int argc, char *argv[]) |
| 1105 | | | { |
| 1106 | | | int c; |
| 1107 | | | char *p; |
| 1108 | | | |
| 1109 | | | |
| 1110 | | | while ((c = getopt(argc, argv, "dhqe:i:l:m:o:u:s:S:t:T:")) != -1) { |
| 1111 | | | switch(c) { |
| 1112 | | | case '?': usage(); break; |
| 1113 | | | case 'h': usage(); break; |
Unreachable Control Flow
The highlighted code will not execute under any circumstances. |
|
| 1114 | | | case 'd': if (!quiet) debug++; break; |
| 1115 | | | case 'q': quiet = TRUE; debug = FALSE; break; |
| 1116 | | | case 'l': pcap_link_type = strtol(optarg, NULL, 0); break; |
| 1117 | | | case 'm': max_offset = strtol(optarg, NULL, 0); break; |
| 1118 | | | case 'o': |
| 1119 | | | if (optarg[0]!='h' && optarg[0] != 'o' && optarg[0] != 'd') { |
| 1120 | | | fprintf(stderr, "Bad argument for '-o': %s\n", optarg); |
| 1121 | | | usage(); |
| 1122 | | | } |
| 1123 | | | switch(optarg[0]) { |
| 1124 | | | case 'o': offset_base = 8; break; |
| 1125 | | | case 'h': offset_base = 16; break; |
| 1126 | | | case 'd': offset_base = 10; break; |
| 1127 | | | } |
| 1128 | | | break; |
| 1129 | | | case 'e': |
| 1130 | | | hdr_ethernet = TRUE; |
| 1131 | | | if (sscanf(optarg, "%lx", &hdr_ethernet_proto) < 1) { |
| 1132 | | | fprintf(stderr, "Bad argument for '-e': %s\n", optarg); |
| 1133 | | | usage(); |
| 1134 | | | } |
| 1135 | | | break; |
| 1136 | | | |
| 1137 | | | case 'i': |
| 1138 | | | hdr_ip = TRUE; |
| 1139 | | | hdr_ip_proto = strtol(optarg, &p, 10); |
| 1140 | | | if (p == optarg || *p != '\0' || hdr_ip_proto < 0 || |
| 1141 | | | hdr_ip_proto > 255) { |
| 1142 | | | fprintf(stderr, "Bad argument for '-i': %s\n", optarg); |
| 1143 | | | usage(); |
| 1144 | | | } |
| 1145 | | | hdr_ethernet = TRUE; |
| 1146 | | | hdr_ethernet_proto = 0x800; |
| 1147 | | | break; |
| 1148 | | | |
| 1149 | | | case 's': |
| 1150 | | | hdr_sctp = TRUE; |
| 1151 | | | hdr_sctp_src = strtol(optarg, &p, 10); |
| 1152 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1153 | | | fprintf(stderr, "Bad src port for '-%c'\n", c); |
| 1154 | | | usage(); |
| 1155 | | | } |
| 1156 | | | if (*p == '\0') { |
| 1157 | | | fprintf(stderr, "No dest port specified for '-%c'\n", c); |
| 1158 | | | usage(); |
| 1159 | | | } |
| 1160 | | | p++; |
| 1161 | | | optarg = p; |
| 1162 | | | hdr_sctp_dest = strtol(optarg, &p, 10); |
| 1163 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1164 | | | fprintf(stderr, "Bad dest port for '-s'\n"); |
| 1165 | | | usage(); |
| 1166 | | | } |
| 1167 | | | if (*p == '\0') { |
| 1168 | | | fprintf(stderr, "No tag specified for '-%c'\n", c); |
| 1169 | | | usage(); |
| 1170 | | | } |
| 1171 | | | p++; |
| 1172 | | | optarg = p; |
| 1173 | | | hdr_sctp_tag = strtol(optarg, &p, 10); |
| 1174 | | | if (p == optarg || *p != '\0') { |
| 1175 | | | fprintf(stderr, "Bad tag for '-%c'\n", c); |
| 1176 | | | usage(); |
| 1177 | | | } |
| 1178 | | | |
| 1179 | | | hdr_ip = TRUE; |
| 1180 | | | hdr_ip_proto = 132; |
| 1181 | | | hdr_ethernet = TRUE; |
| 1182 | | | hdr_ethernet_proto = 0x800; |
| 1183 | | | break; |
| 1184 | | | case 'S': |
| 1185 | | | hdr_sctp = TRUE; |
| 1186 | | | hdr_data_chunk = TRUE; |
| 1187 | | | hdr_sctp_src = strtol(optarg, &p, 10); |
| 1188 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1189 | | | fprintf(stderr, "Bad src port for '-%c'\n", c); |
| 1190 | | | usage(); |
| 1191 | | | } |
| 1192 | | | if (*p == '\0') { |
| 1193 | | | fprintf(stderr, "No dest port specified for '-%c'\n", c); |
| 1194 | | | usage(); |
| 1195 | | | } |
| 1196 | | | p++; |
| 1197 | | | optarg = p; |
| 1198 | | | hdr_sctp_dest = strtol(optarg, &p, 10); |
| 1199 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1200 | | | fprintf(stderr, "Bad dest port for '-s'\n"); |
| 1201 | | | usage(); |
| 1202 | | | } |
| 1203 | | | if (*p == '\0') { |
| 1204 | | | fprintf(stderr, "No ppi specified for '-%c'\n", c); |
| 1205 | | | usage(); |
| 1206 | | | } |
| 1207 | | | p++; |
| 1208 | | | optarg = p; |
| 1209 | | | hdr_data_chunk_ppid = strtoul(optarg, &p, 10); |
| 1210 | | | if (p == optarg || *p != '\0') { |
| 1211 | | | fprintf(stderr, "Bad ppi for '-%c'\n", c); |
| 1212 | | | usage(); |
| 1213 | | | } |
| 1214 | | | |
| 1215 | | | hdr_ip = TRUE; |
| 1216 | | | hdr_ip_proto = 132; |
| 1217 | | | hdr_ethernet = TRUE; |
| 1218 | | | hdr_ethernet_proto = 0x800; |
| 1219 | | | break; |
| 1220 | | | |
| 1221 | | | case 't': |
| 1222 | | | ts_fmt = optarg; |
| 1223 | | | break; |
| 1224 | | | |
| 1225 | | | case 'u': |
| 1226 | | | hdr_udp = TRUE; |
| 1227 | | | hdr_tcp = FALSE; |
| 1228 | | | hdr_src_port = strtol(optarg, &p, 10); |
| 1229 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1230 | | | fprintf(stderr, "Bad src port for '-u'\n"); |
| 1231 | | | usage(); |
| 1232 | | | } |
| 1233 | | | if (*p == '\0') { |
| 1234 | | | fprintf(stderr, "No dest port specified for '-u'\n"); |
| 1235 | | | usage(); |
| 1236 | | | } |
| 1237 | | | p++; |
| 1238 | | | optarg = p; |
| 1239 | | | hdr_dest_port = strtol(optarg, &p, 10); |
| 1240 | | | if (p == optarg || *p != '\0') { |
| 1241 | | | fprintf(stderr, "Bad dest port for '-u'\n"); |
| 1242 | | | usage(); |
| 1243 | | | } |
| 1244 | | | hdr_ip = TRUE; |
| 1245 | | | hdr_ip_proto = 17; |
| 1246 | | | hdr_ethernet = TRUE; |
| 1247 | | | hdr_ethernet_proto = 0x800; |
| 1248 | | | break; |
| 1249 | | | |
| 1250 | | | case 'T': |
| 1251 | | | hdr_tcp = TRUE; |
| 1252 | | | hdr_udp = FALSE; |
| 1253 | | | hdr_src_port = strtol(optarg, &p, 10); |
| 1254 | | | if (p == optarg || (*p != ',' && *p != '\0')) { |
| 1255 | | | fprintf(stderr, "Bad src port for '-T'\n"); |
| 1256 | | | usage(); |
| 1257 | | | } |
| 1258 | | | if (*p == '\0') { |
| 1259 | | | fprintf(stderr, "No dest port specified for '-u'\n"); |
| 1260 | | | usage(); |
| 1261 | | | } |
| 1262 | | | p++; |
| 1263 | | | optarg = p; |
| 1264 | | | hdr_dest_port = strtol(optarg, &p, 10); |
| 1265 | | | if (p == optarg || *p != '\0') { |
| 1266 | | | fprintf(stderr, "Bad dest port for '-T'\n"); |
| 1267 | | | usage(); |
| 1268 | | | } |
| 1269 | | | hdr_ip = TRUE; |
| 1270 | | | hdr_ip_proto = 6; |
| 1271 | | | hdr_ethernet = TRUE; |
| 1272 | | | hdr_ethernet_proto = 0x800; |
| 1273 | | | break; |
| 1274 | | | |
| 1275 | | | default: |
| 1276 | | | usage(); |
| 1277 | | | } |
| 1278 | | | } |
| 1279 | | | |
| 1280 | | | if (optind >= argc || argc-optind < 2) { |
| 1281 | | | fprintf(stderr, "Must specify input and output filename\n"); |
| 1282 | | | usage(); |
| 1283 | | | } |
| 1284 | | | |
| 1285 | | | if (strcmp(argv[optind], "-")) { |
| 1286 | | | input_filename = g_strdup(argv[optind]); |
| 1287 | | | input_file = ws_fopen(input_filename, "rb"); |
| 1288 | | | if (!input_file) { |
| 1289 | | | fprintf(stderr, "Cannot open file [%s] for reading: %s\n", |
| 1290 | | | input_filename, strerror(errno)); |
| 1291 | | | exit(-1); |
| 1292 | | | } |
| 1293 | | | } else { |
| 1294 | | | input_filename = "Standard input"; |
| 1295 | | | input_file = stdin; |
| 1296 | | | } |
| 1297 | | | |
| 1298 | | | if (strcmp(argv[optind+1], "-")) { |
| 1299 | | | output_filename = g_strdup(argv[optind+1]); |
| 1300 | | | output_file = ws_fopen(output_filename, "wb"); |
| 1301 | | | if (!output_file) { |
| 1302 | | | fprintf(stderr, "Cannot open file [%s] for writing: %s\n", |
| 1303 | | | output_filename, strerror(errno)); |
| 1304 | | | exit(-1); |
| 1305 | | | } |
| 1306 | | | } else { |
| 1307 | | | output_filename = "Standard output"; |
| 1308 | | | output_file = stdout; |
| 1309 | | | } |
| 1310 | | | |
| 1311 | | | |
| 1312 | | | if (pcap_link_type != 1 && hdr_ethernet) { |
| 1313 | | | fprintf(stderr, "Dummy (-e, -i, -u, -s, -S -T) cannot be specified with link type override (-l)\n"); |
| 1314 | | | exit(-1); |
| 1315 | | | } |
| 1316 | | | |
| 1317 | | | |
| 1318 | | | if (!input_file) { |
| 1319 | | | input_file = stdin; |
| 1320 | | | input_filename = "Standard input"; |
| 1321 | | | } |
| 1322 | | | if (!output_file) { |
| 1323 | | | output_file = stdout; |
| 1324 | | | output_filename = "Standard output"; |
| 1325 | | | } |
| 1326 | | | |
| 1327 | | | ts_sec = time(0); |
| 1328 | | | timecode_default = *localtime(&ts_sec); |
| 1329 | | | |
| 1330 | | | |
| 1331 | | | if (!quiet) { |
| 1332 | | | fprintf(stderr, "Input from: %s\n", input_filename); |
| 1333 | | | fprintf(stderr, "Output to: %s\n", output_filename); |
| 1334 | | | |
| 1335 | | | if (hdr_ethernet) fprintf(stderr, "Generate dummy Ethernet : Protocol: 0x%0lX\n", |
| 1336 | | | hdr_ethernet_proto); |
| 1337 | | | if (hdr_ip) fprintf(stderr, "Generate dummy IP : Protocol: %ld\n", |
| 1338 | | | hdr_ip_proto); |
| 1339 | | | if (hdr_udp) fprintf(stderr, "Generate dummy UDP : Source port: %ld. Dest port: %ld\n", |
| 1340 | | | hdr_src_port, hdr_dest_port); |
| 1341 | | | if (hdr_tcp) fprintf(stderr, "Generate dummy TCP : Source port: %ld. Dest port: %ld\n", |
| 1342 | | | hdr_src_port, hdr_dest_port); |
| 1343 | | | if (hdr_sctp) fprintf(stderr, "Generate dummy SCTP : Source port: %ld. Dest port: %ld. Tag: %ld\n", |
| 1344 | | | hdr_sctp_src, hdr_sctp_dest, hdr_sctp_tag); |
| 1345 | | | if (hdr_data_chunk) fprintf(stderr, "Generate dummy DATA chunk : TSN: %lu. SID: %d. SSN: %d. PPID: %lu\n", |
| 1346 | | | hdr_data_chunk_tsn, hdr_data_chunk_sid, hdr_data_chunk_ssn, hdr_data_chunk_ppid); |
| 1347 | | | } |
| 1348 | | | } |
| |