return ret;
}
+struct print_info get_print_info(int type) {
+ struct print_info printinfo;
+
+ printinfo.ndo_type = 1;
+ printinfo.ndo = gndo;
+ printinfo.p.ndo_printer = lookup_ndo_printer(type);
+ if (printinfo.p.ndo_printer == NULL) {
+ printinfo.p.printer = lookup_printer(type);
+ printinfo.ndo_type = 0;
+ if (printinfo.p.printer == NULL) {
+ gndo->ndo_dltname = pcap_datalink_val_to_name(type);
+ if (gndo->ndo_dltname != NULL)
+ error("packet printing is not supported for link type %s: use -w",
+ gndo->ndo_dltname);
+ else
+ error("packet printing is not supported for link type %d: use -w", type);
+ }
+ }
+ return (printinfo);
+}
+
+char *get_next_file(FILE *VFile, char *ptr) {
+ char *ret;
+
+ ret = fgets(ptr, NAME_MAX, VFile);
+ if (!ret)
+ return NULL;
+
+ if (ptr[strlen(ptr) - 1] == '\n')
+ ptr[strlen(ptr) - 1] = '\0';
+
+ return ret;
+}
+
int
main(int argc, char **argv)
{
#endif /* WIN32 */
if (VFileName != NULL) {
if (VFileName[0] == '-' && VFileName[1] == '\0')
- VFile = fopen("/dev/stdin", "r");
+ VFile = stdin;
else
VFile = fopen(VFileName, "r");
if (VFile == NULL)
error("Unable to open file: %s\n", strerror(errno));
- ret = fgets(VFileLine, NAME_MAX, VFile);
+ ret = get_next_file(VFile, VFileLine);
if (!ret)
- error("Nothing in %s\n", VFile);
-
- if (VFileLine[strlen(VFileLine) - 1] == '\n')
- VFileLine[strlen(VFileLine) - 1] = '\0';
+ error("Nothing in %s\n", VFileName);
RFileName = VFileLine;
}
#endif
} else {
type = pcap_datalink(pd);
- printinfo.ndo_type = 1;
- printinfo.ndo = gndo;
- printinfo.p.ndo_printer = lookup_ndo_printer(type);
- if (printinfo.p.ndo_printer == NULL) {
- printinfo.p.printer = lookup_printer(type);
- printinfo.ndo_type = 0;
- if (printinfo.p.printer == NULL) {
- gndo->ndo_dltname = pcap_datalink_val_to_name(type);
- if (gndo->ndo_dltname != NULL)
- error("packet printing is not supported for link type %s: use -w",
- gndo->ndo_dltname);
- else
- error("packet printing is not supported for link type %d: use -w", type);
- }
- }
+ printinfo = get_print_info(type);
callback = print_packet;
pcap_userdata = (u_char *)&printinfo;
}
}
pcap_close(pd);
if (VFileName != NULL) {
- ret = fgets(VFileLine, NAME_MAX, VFile);
+ ret = get_next_file(VFile, VFileLine);
if (ret) {
- if (VFileLine[strlen(VFileLine) - 1] == '\n')
- VFileLine[strlen(VFileLine) - 1] = '\0';
RFileName = VFileLine;
pd = pcap_open_offline(RFileName, ebuf);
if (pd == NULL)
new_dlt = pcap_datalink(pd);
if (WFileName && new_dlt != dlt)
error("%s: new dlt does not match original", RFileName);
+ printinfo = get_print_info(new_dlt);
dlt_name = pcap_datalink_val_to_name(new_dlt);
if (dlt_name == NULL) {
fprintf(stderr, "reading from file %s, link-type %u\n",