git-svn: trunk@1700
Tomasz Kojm authored on 2005/08/21 07:40:59... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Sun Aug 21 00:32:10 CEST 2005 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * shared/network.[ch]: new files (include r_gethostbyname by NJH) |
|
4 |
+ |
|
1 | 5 |
Wed Aug 17 15:53:33 CEST 2005 (acab) |
2 | 6 |
------------------------------------ |
3 | 7 |
* libclamav/spin.c: fixed bitmap shifting |
4 | 8 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,88 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2005 Nigel Horne <njh@bandsman.co.uk> |
|
2 |
+ * |
|
3 |
+ * This program is free software; you can redistribute it and/or modify |
|
4 |
+ * it under the terms of the GNU General Public License as published by |
|
5 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
6 |
+ * (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * This program is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+ * GNU General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public License |
|
14 |
+ * along with this program; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
16 |
+ * |
|
17 |
+ */ |
|
18 |
+ |
|
19 |
+#if HAVE_CONFIG_H |
|
20 |
+#include "clamav-config.h" |
|
21 |
+#endif |
|
22 |
+ |
|
23 |
+#include <stdio.h> |
|
24 |
+#include <sys/types.h> |
|
25 |
+#include <netdb.h> |
|
26 |
+ |
|
27 |
+#ifdef CL_THREAD_SAFE |
|
28 |
+#include <pthread.h> |
|
29 |
+#endif |
|
30 |
+ |
|
31 |
+/* |
|
32 |
+ * TODO: gethostbyname_r is non-standard so different operating |
|
33 |
+ * systems do it in different ways. Need more examples |
|
34 |
+ * Perhaps we could use res_search()? |
|
35 |
+ * |
|
36 |
+ * Returns 0 for success |
|
37 |
+ */ |
|
38 |
+int r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t len) |
|
39 |
+{ |
|
40 |
+#if defined(HAVE_GETHOSTBYNAME_R_6) |
|
41 |
+ /* e.g. Linux */ |
|
42 |
+ struct hostent *hp2; |
|
43 |
+ int ret = -1; |
|
44 |
+ |
|
45 |
+ if((hostname == NULL) || (hp == NULL)) |
|
46 |
+ return -1; |
|
47 |
+ if(gethostbyname_r(hostname, hp, buf, len, &hp2, &ret) < 0) |
|
48 |
+ return ret; |
|
49 |
+#elif defined(HAVE_GETHOSTBYNAME_R_5) |
|
50 |
+ /* e.g. BSD, Solaris, Cygwin */ |
|
51 |
+ int ret = -1; |
|
52 |
+ |
|
53 |
+ if((hostname == NULL) || (hp == NULL)) |
|
54 |
+ return -1; |
|
55 |
+ if(gethostbyname_r(hostname, hp, buf, len, &ret) == NULL) |
|
56 |
+ return ret; |
|
57 |
+#elif defined(HAVE_GETHOSTBYNAME_R_3) |
|
58 |
+ /* e.g. HP/UX, AIX */ |
|
59 |
+ if((hostname == NULL) || (hp == NULL)) |
|
60 |
+ return -1; |
|
61 |
+ if(gethostbyname_r(hostname, &hp, (struct hostent_data *)buf) < 0) |
|
62 |
+ return h_errno; |
|
63 |
+#else |
|
64 |
+ /* Single thread the code */ |
|
65 |
+ struct hostent *hp2; |
|
66 |
+#ifdef CL_THREAD_SAFE |
|
67 |
+ static pthread_mutex_t hostent_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
68 |
+#endif |
|
69 |
+ |
|
70 |
+ if((hostname == NULL) || (hp == NULL)) |
|
71 |
+ return -1; |
|
72 |
+#ifdef CL_THREAD_SAFE |
|
73 |
+ pthread_mutex_lock(&hostent_mutex); |
|
74 |
+#endif |
|
75 |
+ if((hp2 = gethostbyname(hostname)) == NULL) { |
|
76 |
+#ifdef CL_THREAD_SAFE |
|
77 |
+ pthread_mutex_unlock(&hostent_mutex); |
|
78 |
+#endif |
|
79 |
+ return h_errno; |
|
80 |
+ } |
|
81 |
+ memcpy(hp, hp2, sizeof(struct hostent)); |
|
82 |
+#ifdef CL_THREAD_SAFE |
|
83 |
+ pthread_mutex_unlock(&hostent_mutex); |
|
84 |
+#endif |
|
85 |
+ |
|
86 |
+ return 0; |
|
87 |
+} |
0 | 88 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
0 |
+/* |
|
1 |
+ * Copyright (C) 2005 Nigel Horne <njh@bandsman.co.uk> |
|
2 |
+ * |
|
3 |
+ * This program is free software; you can redistribute it and/or modify |
|
4 |
+ * it under the terms of the GNU General Public License as published by |
|
5 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
6 |
+ * (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * This program is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
+ * GNU General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public License |
|
14 |
+ * along with this program; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
16 |
+ * |
|
17 |
+ */ |
|
18 |
+ |
|
19 |
+#ifndef __NETWORK_H |
|
20 |
+#define __NETWORK_H |
|
21 |
+ |
|
22 |
+#include <sys/types.h> |
|
23 |
+#include <netdb.h> |
|
24 |
+ |
|
25 |
+int r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t len); |
|
26 |
+ |
|
27 |
+#endif |