Changeset View
Changeset View
Standalone View
Standalone View
src/utils.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | 16 | Lesser General Public License for more details. | ||
17 | 17 | | |||
18 | You should have received a copy of the GNU Lesser General Public | 18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "utils.h" | 22 | #include "utils.h" | ||
23 | #include "time.h" | ||||
23 | 24 | | |||
24 | QHostAddress NetworkManager::ipv6AddressAsHostAddress(const QByteArray &address) | 25 | QHostAddress NetworkManager::ipv6AddressAsHostAddress(const QByteArray &address) | ||
25 | { | 26 | { | ||
26 | // Q_ASSERT(address.size() == 16); | 27 | // Q_ASSERT(address.size() == 16); | ||
27 | Q_IPV6ADDR tmp; | 28 | Q_IPV6ADDR tmp; | ||
28 | for (int i = 0; i < 16; ++i) { | 29 | for (int i = 0; i < 16; ++i) { | ||
29 | tmp[i] = address[i]; | 30 | tmp[i] = address[i]; | ||
30 | } | 31 | } | ||
▲ Show 20 Lines • Show All 485 Lines • ▼ Show 20 Line(s) | 477 | { | |||
516 | freqs.append(QPair<int, int>(187, 4935)); | 517 | freqs.append(QPair<int, int>(187, 4935)); | ||
517 | freqs.append(QPair<int, int>(188, 4940)); | 518 | freqs.append(QPair<int, int>(188, 4940)); | ||
518 | freqs.append(QPair<int, int>(189, 4945)); | 519 | freqs.append(QPair<int, int>(189, 4945)); | ||
519 | freqs.append(QPair<int, int>(192, 4960)); | 520 | freqs.append(QPair<int, int>(192, 4960)); | ||
520 | freqs.append(QPair<int, int>(196, 4980)); | 521 | freqs.append(QPair<int, int>(196, 4980)); | ||
521 | 522 | | |||
522 | return freqs; | 523 | return freqs; | ||
523 | } | 524 | } | ||
525 | | ||||
526 | QDateTime NetworkManager::clockBootTimeToDateTime(qlonglong clockBootime) { | ||||
527 | | ||||
528 | clockid_t clk_id = CLOCK_BOOTTIME; | ||||
529 | struct timespec tp; | ||||
530 | int r; | ||||
531 | | ||||
532 | // now is used as a point of reference | ||||
533 | // with the timespec that contains the number of msec since boot | ||||
534 | QDateTime now = QDateTime::currentDateTime(); | ||||
535 | r = clock_gettime (clk_id, &tp); | ||||
536 | if (r == -1 && errno == EINVAL) { | ||||
537 | clk_id = CLOCK_MONOTONIC; | ||||
538 | r = clock_gettime (clk_id, &tp); | ||||
539 | } | ||||
540 | | ||||
541 | // convert to msecs | ||||
542 | long now_msecs = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; | ||||
543 | | ||||
544 | // diff the msecs and construct a QDateTime based on the offset | ||||
545 | QDateTime res; | ||||
546 | if (clockBootime > now_msecs) { | ||||
547 | qlonglong offset = clockBootime - now_msecs; | ||||
548 | res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() + offset); | ||||
549 | } else { | ||||
550 | qlonglong offset = now_msecs - clockBootime; | ||||
551 | res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() - offset); | ||||
552 | } | ||||
553 | | ||||
554 | return res; | ||||
555 | } |