Mon Oct 12 09:26:38 2015 UTC ()
Use clock_gettime as a more accurate time source.


(roy)
diff -r1.7 -r1.8 src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c

cvs diff -r1.7 -r1.8 src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c (expand / switch to unified diff)

--- src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c 2014/12/20 13:15:48 1.7
+++ src/external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c 2015/10/12 09:26:38 1.8
@@ -1401,35 +1401,41 @@ mDNSexport mDNSu32 mDNSPlatformRandomSee @@ -1401,35 +1401,41 @@ mDNSexport mDNSu32 mDNSPlatformRandomSee
1401 1401
1402mDNSexport mDNSs32 mDNSPlatformOneSecond = 1024; 1402mDNSexport mDNSs32 mDNSPlatformOneSecond = 1024;
1403 1403
1404mDNSexport mStatus mDNSPlatformTimeInit(void) 1404mDNSexport mStatus mDNSPlatformTimeInit(void)
1405 { 1405 {
1406 // No special setup is required on Posix -- we just use gettimeofday(); 1406 // No special setup is required on Posix -- we just use gettimeofday();
1407 // This is not really safe, because gettimeofday can go backwards if the user manually changes the date or time 1407 // This is not really safe, because gettimeofday can go backwards if the user manually changes the date or time
1408 // We should find a better way to do this 1408 // We should find a better way to do this
1409 return(mStatus_NoError); 1409 return(mStatus_NoError);
1410 } 1410 }
1411 1411
1412mDNSexport mDNSs32 mDNSPlatformRawTime() 1412mDNSexport mDNSs32 mDNSPlatformRawTime()
1413 { 1413 {
 1414#ifdef CLOCK_MONOTONIC
 1415 struct timespec tv;
 1416 clock_gettime(CLOCK_MONOTONIC, &tv);
 1417 return((tv.tv_sec << 10) | ((tv.tv_nsec / 1000) * 16 / 15625));
 1418#else
1414 struct timeval tv; 1419 struct timeval tv;
1415 gettimeofday(&tv, NULL); 1420 gettimeofday(&tv, NULL);
1416 // tv.tv_sec is seconds since 1st January 1970 (GMT, with no adjustment for daylight savings time) 1421 // tv.tv_sec is seconds since 1st January 1970 (GMT, with no adjustment for daylight savings time)
1417 // tv.tv_usec is microseconds since the start of this second (i.e. values 0 to 999999) 1422 // tv.tv_usec is microseconds since the start of this second (i.e. values 0 to 999999)
1418 // We use the lower 22 bits of tv.tv_sec for the top 22 bits of our result 1423 // We use the lower 22 bits of tv.tv_sec for the top 22 bits of our result
1419 // and we multiply tv.tv_usec by 16 / 15625 to get a value in the range 0-1023 to go in the bottom 10 bits. 1424 // and we multiply tv.tv_usec by 16 / 15625 to get a value in the range 0-1023 to go in the bottom 10 bits.
1420 // This gives us a proper modular (cyclic) counter that has a resolution of roughly 1ms (actually 1/1024 second) 1425 // This gives us a proper modular (cyclic) counter that has a resolution of roughly 1ms (actually 1/1024 second)
1421 // and correctly cycles every 2^22 seconds (4194304 seconds = approx 48 days). 1426 // and correctly cycles every 2^22 seconds (4194304 seconds = approx 48 days).
1422 return((tv.tv_sec << 10) | (tv.tv_usec * 16 / 15625)); 1427 return((tv.tv_sec << 10) | (tv.tv_usec * 16 / 15625));
 1428#endif
1423 } 1429 }
1424 1430
1425mDNSexport mDNSs32 mDNSPlatformUTC(void) 1431mDNSexport mDNSs32 mDNSPlatformUTC(void)
1426 { 1432 {
1427 return time(NULL); 1433 return time(NULL);
1428 } 1434 }
1429 1435
1430mDNSexport void mDNSPlatformSendWakeupPacket(mDNS *const m, mDNSInterfaceID InterfaceID, char *EthAddr, char *IPAddr, int iteration) 1436mDNSexport void mDNSPlatformSendWakeupPacket(mDNS *const m, mDNSInterfaceID InterfaceID, char *EthAddr, char *IPAddr, int iteration)
1431 { 1437 {
1432 (void) m; 1438 (void) m;
1433 (void) InterfaceID; 1439 (void) InterfaceID;
1434 (void) EthAddr; 1440 (void) EthAddr;
1435 (void) IPAddr; 1441 (void) IPAddr;