OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/notifier/base/nethelpers.h" |
| 6 |
| 7 namespace notifier { |
| 8 |
| 9 hostent* SafeGetHostByName(const char* hostname, hostent* host, |
| 10 char* buffer, size_t buffer_len, |
| 11 int* herrno) { |
| 12 hostent* result = NULL; |
| 13 #if WIN32 |
| 14 result = gethostbyname(hostname); |
| 15 if (!result) { |
| 16 *herrno = WSAGetLastError(); |
| 17 } |
| 18 #elif OS_LINUX |
| 19 gethostbyname_r(hostname, host, buffer, buffer_len, &result, herrno); |
| 20 #elif OSX |
| 21 result = getipnodebyname(hostname, AF_INET, AI_DEFAULT, herrno); |
| 22 #else |
| 23 #error "I don't know how to do gethostbyname safely on your system." |
| 24 #endif |
| 25 return result; |
| 26 } |
| 27 |
| 28 // This function should mirror the above function, and free any resources |
| 29 // allocated by the above. |
| 30 void FreeHostEnt(hostent* host) { |
| 31 #if WIN32 |
| 32 // No need to free anything, struct returned is static memory. |
| 33 #elif OS_LINUX |
| 34 // No need to free anything, we pass in a pointer to a struct. |
| 35 #elif OSX |
| 36 freehostent(host); |
| 37 #else |
| 38 #error "I don't know how to free a hostent on your system." |
| 39 #endif |
| 40 } |
| 41 |
| 42 } // namespace notifier |
OLD | NEW |