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 "build/build_config.h" | |
6 #include "chrome/browser/sync/notifier/base/nethelpers.h" | |
7 | |
8 namespace notifier { | |
9 | |
10 hostent* SafeGetHostByName(const char* hostname, hostent* host, | |
11 char* buffer, size_t buffer_len, | |
12 int* herrno) { | |
13 hostent* result = NULL; | |
14 #if WIN32 | |
15 result = gethostbyname(hostname); | |
16 if (!result) { | |
17 *herrno = WSAGetLastError(); | |
18 } | |
19 #elif OS_LINUX | |
20 gethostbyname_r(hostname, host, buffer, buffer_len, &result, herrno); | |
21 #elif OS_MACOSX | |
22 result = getipnodebyname(hostname, AF_INET, AI_DEFAULT, herrno); | |
23 #else | |
24 #error "I don't know how to do gethostbyname safely on your system." | |
25 #endif | |
26 return result; | |
27 } | |
28 | |
29 // This function should mirror the above function, and free any resources | |
30 // allocated by the above. | |
31 void FreeHostEnt(hostent* host) { | |
32 #if WIN32 | |
33 // No need to free anything, struct returned is static memory. | |
34 #elif OS_LINUX | |
35 // No need to free anything, we pass in a pointer to a struct. | |
36 #elif OS_MACOSX | |
37 freehostent(host); | |
38 #else | |
39 #error "I don't know how to free a hostent on your system." | |
40 #endif | |
41 } | |
42 | |
43 } // namespace notifier | |
OLD | NEW |