~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to shared/network.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: Nigel Horne
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 
 *  MA 02110-1301, USA.
20
 
 *
21
 
 */
22
 
 
23
 
#ifdef  _MSC_VER
24
 
#include <windows.h>
25
 
#include <winsock.h>
26
 
#endif
27
 
 
28
 
#if HAVE_CONFIG_H
29
 
#include "clamav-config.h"
30
 
#endif
31
 
 
32
 
#include <stdio.h>
33
 
 
34
 
#ifdef  HAVE_STRING_H
35
 
#include <string.h>
36
 
#endif
37
 
 
38
 
#ifdef HAVE_SYS_TYPES_H
39
 
#include <sys/types.h>
40
 
#endif
41
 
 
42
 
#ifndef C_WINDOWS
43
 
#include <netdb.h>
44
 
#endif
45
 
 
46
 
#ifdef CL_NOTHREADS
47
 
#undef CL_THREAD_SAFE
48
 
#endif
49
 
 
50
 
#ifdef  CL_THREAD_SAFE
51
 
#include <pthread.h>
52
 
#endif
53
 
 
54
 
#include "network.h"
55
 
 
56
 
/*
57
 
 * TODO: gethostbyname_r is non-standard so different operating
58
 
 * systems do it in different ways. Need more examples
59
 
 * Perhaps we could use res_search()?
60
 
 *
61
 
 * Returns 0 for success
62
 
 */
63
 
int r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t len)
64
 
{
65
 
        struct hostent *hp2;
66
 
        int ret = -1;
67
 
#if !defined(HAVE_GETHOSTBYNAME_R_6) && !defined(HAVE_GETHOSTBYNAME_R_5) && !defined(HAVE_GETHOSTBYNAME_R_3)
68
 
#ifdef  CL_THREAD_SAFE
69
 
        static pthread_mutex_t hostent_mutex = PTHREAD_MUTEX_INITIALIZER;
70
 
#endif
71
 
#endif
72
 
 
73
 
        if((hostname == NULL) || (hp == NULL))
74
 
                return -1;
75
 
        memset(hp, 0, sizeof(struct hostent));
76
 
#if     defined(HAVE_GETHOSTBYNAME_R_6)
77
 
        /* e.g. Linux */
78
 
        if(gethostbyname_r(hostname, hp, buf, len, &hp2, &ret) < 0)
79
 
                return ret;
80
 
#elif   defined(HAVE_GETHOSTBYNAME_R_5)
81
 
        /* e.g. BSD, Solaris, Cygwin */
82
 
        if(gethostbyname_r(hostname, hp, buf, len, &ret) == NULL)
83
 
                return ret;
84
 
#elif   defined(HAVE_GETHOSTBYNAME_R_3)
85
 
        /* e.g. HP/UX, AIX */
86
 
        if(gethostbyname_r(hostname, &hp, (struct hostent_data *)buf) < 0)
87
 
                return h_errno;
88
 
#else
89
 
        /* Single thread the code e.g. VS2005 */
90
 
#ifdef  CL_THREAD_SAFE
91
 
        pthread_mutex_lock(&hostent_mutex);
92
 
#endif
93
 
        if((hp2 = gethostbyname(hostname)) == NULL) {
94
 
#ifdef  CL_THREAD_SAFE
95
 
                pthread_mutex_unlock(&hostent_mutex);
96
 
#endif
97
 
                return h_errno;
98
 
        }
99
 
        memcpy(hp, hp2, sizeof(struct hostent));
100
 
#ifdef  CL_THREAD_SAFE
101
 
        pthread_mutex_unlock(&hostent_mutex);
102
 
#endif
103
 
 
104
 
#endif
105
 
        return 0;
106
 
}