--- util.c.org	Sat Feb  8 19:32:00 2003
+++ util.c	Sat Mar  1 17:36:54 2003
@@ -36,6 +36,10 @@
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
 #include <pcap.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -44,6 +48,8 @@
 
 #include "interface.h"
 
+static const char *local_date_format (const struct tm *tm);
+
 /*
  * Print out a filename (or other ascii string).
  * If ep is NULL, assume no truncation check is needed.
@@ -155,11 +161,10 @@
 		s = (tvp->tv_sec + thiszone) % 86400;
 		Time = (tvp->tv_sec + thiszone) - s;
 		tm  = gmtime (&Time);
-		(void)printf("%02d/%02d/%04d %02d:%02d:%02d.%06u ",
-			     tm->tm_mon+1, tm->tm_mday,
-			     tm->tm_year+1900,
-			     s / 3600, (s % 3600) / 60,
-			     s % 60, (unsigned)tvp->tv_usec);
+		printf ("%s ", local_date_format(tm));
+		printf ("%02d:%02d:%02d.%06u ",
+			    s / 3600, (s % 3600) / 60,
+			    s % 60, (unsigned)tvp->tv_usec);
 		break;
 	}
 }
@@ -476,4 +483,73 @@
 		printf("%c", ch);
 	else
 		printf("\\%03o", ch);
+}
+
+/*
+ * Try to return the date-format for the national locale.
+ * Most systems use "C" locale for date (and everything else). This isn't 
+ * suitable for national date representation.
+ */
+#if defined(HAVE_LOCALE) && defined(HAVE_STRFTIME)
+
+const char *old_locale = NULL;
+
+/* Not sure this is needed (system-wide or process only effect?)
+ */
+static void 
+restore_locale (void)
+{
+	if (old_locale)
+	{
+		setlocale (LC_TIME, old_locale);
+		free ((void*)old_locale);
+		old_locale = NULL;
+	}
+	else
+		setlocale (LC_TIME, ""); 
+}
+#endif
+
+static const char *
+local_date_format (const struct tm *tm)
+{
+	static char result[100];
+	static char default_fmt[] = "%02d/%02d/%04d";  /* MM/DD/YYYY */
+	static int  init = 0;
+	static int  locale_ok = 0;
+
+	if (!tm)
+		return ("Date fail");
+
+#if !defined(HAVE_LOCALE) || !defined(HAVE_STRFTIME)
+	sprintf (result, default_fmt, tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
+#else
+	if (!init)
+	{
+		struct tm tm_copy = *tm, *tm_now;
+		time_t now;
+		char   buf[100];
+		
+		old_locale = setlocale (LC_TIME, NULL);
+		if (old_locale)
+			old_locale = strdup (old_locale);
+		
+		setlocale (LC_TIME, "");  /* system default date/time locale */
+		time (&now);
+		tm_now = gmtime (&now);   /* for testing strftime() */
+		locale_ok = (tm_now && strftime(buf,sizeof(buf),"%x",tm_now) > 0);
+		atexit (restore_locale);
+		tm = &tm_copy;
+		init = 1;
+
+		/* locale_ok = 1; i.e. "%x" handles todays date. Might not handle
+		 * old capture dates. Check again below.
+		 */
+	}
+	if (locale_ok)
+		locale_ok = (strftime (result,sizeof(result),"%x",tm) > 0);
+	if (!locale_ok)
+		sprintf (result, default_fmt, tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
+#endif
+	return (result);	
 }
