Skip to content

Commit f8f1735

Browse files
committed
Add output format advice
1 parent 25f81d9 commit f8f1735

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/binary-read.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ int binary_read_header(struct reader *r, FILE *f)
2929
skip_align(f, sizeof(h));
3030

3131
if(h.magic != FILE_MAGIC) {
32+
log_error("File header not found or incorrect.");
3233
if(h.magic == bswap(FILE_MAGIC))
33-
log_error("This file was created on a system of differing endianness, reading it is not (yet) supported.");
34+
log_raw("This file was created on a system of differing endianness, reading it is not (yet) supported.");
3435
return -1;
3536
}
3637
if(h.version != 1) {

src/main.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
static int read_targets_from_file(const char *filename, int stream_targets);
2020
static void usage(void);
2121
static inline bool is_all_ff(const uint8_t *buf, int len);
22+
static inline char *find_dot(char *str);
2223

2324
enum operating_mode {
2425
M_SCAN, M_PRINT_HOSTS,
@@ -75,7 +76,7 @@ int main(int argc, char *argv[])
7576
ip_type = IP_TYPE_TCP;
7677
interface = NULL; // automatically picked
7778
outfile = stdout;
78-
outdef = &output_list;
79+
outdef = NULL;
7980

8081
srand(time(NULL) ^ getpid());
8182
memset(source_mac, 0xff, 6);
@@ -208,6 +209,18 @@ int main(int argc, char *argv[])
208209
perror("open output file");
209210
return 1;
210211
}
212+
char *dot = find_dot(optarg);
213+
if(!outdef && dot) {
214+
const char *suggest = NULL;
215+
if(!strcmp(dot+1, "bin"))
216+
suggest = "binary";
217+
else if(!strcmp(dot+1, "json"))
218+
suggest = "json";
219+
if(suggest) {
220+
log_warning("It looks like you might want a different "
221+
"output format, try --output-format %s.", suggest);
222+
}
223+
}
211224
outfile = f;
212225
break;
213226
}
@@ -226,6 +239,9 @@ int main(int argc, char *argv[])
226239
}
227240
}
228241

242+
if(!outdef)
243+
outdef = &output_list;
244+
229245
int max_args = 1;
230246
if(mode == M_READSCAN) {
231247
max_args = 0;
@@ -553,3 +569,15 @@ static inline bool is_all_ff(const uint8_t *buf, int len)
553569
}
554570
return true;
555571
}
572+
573+
static inline char *find_dot(char *str)
574+
{
575+
char *p = str + strlen(str);
576+
do {
577+
if(*p == '/')
578+
break;
579+
if(*p == '.')
580+
return p;
581+
} while((p--) > str);
582+
return NULL;
583+
}

0 commit comments

Comments
 (0)