build: update default CXXFLAGS.

* Add -std=c++03 and -pedantic, and fix the resulting warnings. The
  long-long-int warning is explicitly suppressed because it's not
  trivial to workaround in a platform-independent and ISO-conformant
  way without using C++11.

* Initial support for building with -std=c++11 (experimental).

* Prefer -Og optimization level in debug builds if supported by the
  compiler.

Change-Id: I744a25c8b52842dc3ea3a733d6ab2fa66171e6f8
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index 7669e72..7815eae 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -94,12 +94,12 @@
 protected:
   shared_ptr<typename protocol::socket> m_socket;
   uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE];
-
   bool m_hasBeenUsedRecently;
 
   NFD_LOG_INCLASS_DECLARE();
 };
 
+
 template <class T>
 inline
 DatagramFace<T>::DatagramFace(const FaceUri& remoteUri, const FaceUri& localUri,
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 02cc041..fb278d3 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -38,7 +38,7 @@
 
 namespace nfd {
 
-NFD_LOG_INIT("EthernetFace")
+NFD_LOG_INIT("EthernetFace");
 
 EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
                            const shared_ptr<NetworkInterfaceInfo>& interface,
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 894f769..6809e6c 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -32,7 +32,7 @@
 
 namespace nfd {
 
-NFD_LOG_INIT("EthernetFactory")
+NFD_LOG_INIT("EthernetFactory");
 
 shared_ptr<EthernetFace>
 EthernetFactory::createMulticastFace(const shared_ptr<NetworkInterfaceInfo> &interface,
diff --git a/daemon/face/ethernet.cpp b/daemon/face/ethernet.cpp
index ee30aca..1aeaca6 100644
--- a/daemon/face/ethernet.cpp
+++ b/daemon/face/ethernet.cpp
@@ -42,22 +42,34 @@
 Address
 Address::fromString(const std::string& str)
 {
+  unsigned short temp[ADDR_LEN];
+  char sep[5][2]; // 5 * (1 separator char + 1 null terminator)
+  int n = 0; // num of chars read from the input string
+
+  // ISO C++98 does not support the 'hh' type modifier
+  /// \todo use SCNx8 (cinttypes) when we enable C++11
+  int ret = ::sscanf(str.c_str(), "%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%1[:-]%2hx%n",
+                     &temp[0], &sep[0][0], &temp[1], &sep[1][0], &temp[2], &sep[2][0],
+                     &temp[3], &sep[3][0], &temp[4], &sep[4][0], &temp[5], &n);
+
+  if (ret < 11 || static_cast<size_t>(n) != str.length())
+    return Address();
+
   Address a;
-  int n, ret;
+  for (size_t i = 0; i < ADDR_LEN; ++i)
+    {
+      // check that all separators are actually the same char (: or -)
+      if (i < 5 && sep[i][0] != sep[0][0])
+        return Address();
 
-  // colon-separated
-  ret = ::sscanf(str.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%n",
-                 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &n);
-  if (ret >= 6 && str.c_str()[n] == '\0')
-    return a;
+      // check that each value fits into a uint8_t
+      if (temp[i] > 0xFF)
+        return Address();
 
-  // dash-separated
-  ret = ::sscanf(str.c_str(), "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx%n",
-                 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &n);
-  if (ret >= 6 && str.c_str()[n] == '\0')
-    return a;
+      a[i] = static_cast<uint8_t>(temp[i]);
+    }
 
-  return Address();
+  return a;
 }
 
 std::ostream&
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index d4d198f..d0d42db 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -27,8 +27,6 @@
 
 namespace nfd {
 
-NFD_LOG_INIT("Face")
-
 static inline void
 increaseCounter(FaceCounter& counter)
 {