]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Merge remote-tracking branch 'upstream/master'
[tcpdump] / tcpdump.c
index 6103efa71c8d5bed702c42675992856585ef4506..c43ab8549548f620f2715f707027477ba540f1a5 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -589,6 +589,8 @@ static void
 MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars)
 {
         char *filename = malloc(NAME_MAX + 1);
+        if (filename == NULL)
+            error("Makefilename: malloc);
 
         /* Process with strftime if Gflag is set. */
         if (Gflag != 0) {
@@ -651,6 +653,19 @@ struct print_info get_print_info(int 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)
 {
@@ -1138,19 +1153,16 @@ 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;
                }
 
@@ -1519,10 +1531,8 @@ main(int argc, char **argv)
                }
                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)