From 12356d5e2b9331bb04f13578ccd1727a39bb1f4e Mon Sep 17 00:00:00 2001
From: A-star-ayush <myselfthebest@yahoo.com>
Date: Tue, 21 Mar 2017 21:54:39 +0530
Subject: [PATCH] update ntp to used BNetworkAddressResolver
---
src/preferences/time/ntp.cpp | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/preferences/time/ntp.cpp b/src/preferences/time/ntp.cpp
index 167ef2c..c7968f6 100644
a
|
b
|
|
5 | 5 | */ |
6 | 6 | |
7 | 7 | #include "ntp.h" |
| 8 | #include <NetworkAddress.h> |
| 9 | #include <NetworkAddressResolver.h> |
8 | 10 | |
9 | 11 | #include <errno.h> |
10 | 12 | #include <netdb.h> |
… |
… |
status_t
|
114 | 116 | ntp_update_time(const char* hostname, const char** errorString, |
115 | 117 | int32* errorCode) |
116 | 118 | { |
117 | | hostent *server = gethostbyname(hostname); |
| 119 | BNetworkAddressResolver resolver(hostname, NTP_PORT); |
| 120 | BNetworkAddress address; |
| 121 | uint32 cookie = 0; |
| 122 | |
| 123 | if ( resolver.InitCheck() != B_OK || |
| 124 | resolver.GetNextAddress(&cookie, address) != B_OK) { |
118 | 125 | |
119 | | if (server == NULL) { |
120 | | |
121 | 126 | *errorString = B_TRANSLATE("Could not contact server"); |
122 | 127 | return B_ENTRY_NOT_FOUND; |
123 | 128 | } |
… |
… |
ntp_update_time(const char* hostname, const char** errorString,
|
144 | 149 | return B_ERROR; |
145 | 150 | } |
146 | 151 | |
147 | | struct sockaddr_in address; |
148 | | address.sin_family = AF_INET; |
149 | | address.sin_port = htons(NTP_PORT); |
150 | | address.sin_addr.s_addr = *(uint32 *)server->h_addr_list[0]; |
151 | | |
152 | | if (sendto(connection, (char *)&message, sizeof(ntp_data), |
153 | | 0, (struct sockaddr *)&address, sizeof(address)) < 0) { |
| 152 | if (sendto(connection, reinterpret_cast<char *>(&message), sizeof(ntp_data), |
| 153 | 0, &address.SockAddr(), address.Length()) < 0) { |
154 | 154 | *errorString = B_TRANSLATE("Sending request failed"); |
155 | 155 | *errorCode = errno; |
156 | 156 | close(connection); |
… |
… |
ntp_update_time(const char* hostname, const char** errorString,
|
176 | 176 | message.transmit_timestamp.SetTo(0); |
177 | 177 | |
178 | 178 | socklen_t addressSize = sizeof(address); |
179 | | if (recvfrom(connection, (char *)&message, sizeof(ntp_data), 0, |
180 | | (sockaddr *)&address, &addressSize) < (ssize_t)sizeof(ntp_data)) { |
| 179 | if (recvfrom(connection, reinterpret_cast<char *>(&message), sizeof(ntp_data), |
| 180 | 0, &address.SockAddr(), address.Length()) < (ssize_t)sizeof(ntp_data)) { |
181 | 181 | *errorString = B_TRANSLATE("Message receiving failed"); |
182 | 182 | *errorCode = errno; |
183 | 183 | close(connection); |