~ubuntu-branches/ubuntu/trusty/syslog-ng/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/misc.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2013-05-26 09:06:21 UTC
  • mfrom: (1.3.11)
  • Revision ID: package-import@ubuntu.com-20130526090621-8z2s0oi21eoljb9x
Tags: 3.3.9-1
* New upstream release.
* Include missed ivykis header (closes: #708793).

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
static gchar local_hostname_fqdn[256];
47
47
static gchar local_hostname_short[256];
 
48
G_LOCK_DEFINE_STATIC(resolv_lock);
48
49
 
49
50
GString *
50
51
g_string_assign_len(GString *s, const gchar *val, gint len)
73
74
  if (strchr(local_hostname_fqdn, '.') == NULL)
74
75
    {
75
76
      /* not fully qualified, resolve it using DNS or /etc/hosts */
 
77
      G_LOCK(resolv_lock);
76
78
      struct hostent *result = gethostbyname(local_hostname_fqdn);
77
79
      if (result)
78
80
        {
79
81
          strncpy(local_hostname_fqdn, result->h_name, sizeof(local_hostname_fqdn) - 1);
80
82
          local_hostname_fqdn[sizeof(local_hostname_fqdn) - 1] = '\0';
81
83
        }
 
84
      G_UNLOCK(resolv_lock);
82
85
    }
83
86
  /* NOTE: they are the same size, they'll fit */
84
87
  strcpy(local_hostname_short, local_hostname_fqdn);
147
150
#else
148
151
      struct hostent *he;
149
152
      
 
153
      G_LOCK(resolv_lock);
150
154
      he = gethostbyname(name);
151
155
      if (he)
152
156
        {
159
163
              g_assert_not_reached();
160
164
              break;
161
165
            }
162
 
          
 
166
          G_UNLOCK(resolv_lock);
163
167
        }
164
168
      else
165
169
        {
 
170
          G_UNLOCK(resolv_lock);
166
171
          msg_error("Error resolving hostname", evt_tag_str("host", name), NULL);
167
172
          return FALSE;
168
173
        }
187
192
         )
188
193
        {
189
194
          void *addr;
190
 
          socklen_t addr_len;
 
195
          socklen_t addr_len G_GNUC_UNUSED;
191
196
          
192
197
          if (saddr->sa.sa_family == AF_INET)
193
198
            {
207
212
            {
208
213
              if ((!use_dns_cache || !dns_cache_lookup(saddr->sa.sa_family, addr, (const gchar **) &hname, &positive)) && usedns != 2)
209
214
                {
 
215
#ifdef HAVE_GETNAMEINFO
 
216
                  if (getnameinfo(&saddr->sa, saddr->salen, buf, sizeof(buf), NULL, 0, 0) == 0)
 
217
                    hname = buf;
 
218
#else
210
219
                  struct hostent *hp;
211
 
                      
 
220
 
 
221
                  G_LOCK(resolv_lock);
212
222
                  hp = gethostbyaddr(addr, addr_len, saddr->sa.sa_family);
 
223
                  G_UNLOCK(resolv_lock);
213
224
                  hname = (hp && hp->h_name) ? hp->h_name : NULL;
 
225
#endif
214
226
 
215
227
                  if (hname)
216
228
                    positive = TRUE;