- Timestamp:
- Jun 23, 2014, 1:02:33 PM (11 years ago)
- Branches:
- master
- Children:
- 96a2e31
- Parents:
- 120eedd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dns.c
r120eedd re68221b 35 35 void dns_done_host(struct asr_result *, void *); 36 36 void dns_done_reverse(struct asr_result *, void *); 37 int cmp_addr(struct sockaddr *, struct sockaddr *); 37 38 38 39 extern int dodns; … … 42 43 { 43 44 struct icb_session *is = arg; 45 struct addrinfo *res; 46 int found = 0; 44 47 45 if (ar->ar_addrinfo)46 freeaddrinfo(ar->ar_addrinfo);47 48 /* just check that there's no error */49 48 if (ar->ar_gai_errno == 0) { 50 49 if (strncmp(is->hostname, "localhost", 51 50 sizeof "localhost" - 1) == 0) 52 51 strlcpy(is->host, "unknown", ICB_MAXHOSTLEN); 53 else if (strlen(is->hostname) < ICB_MAXHOSTLEN) 54 strlcpy(is->host, is->hostname, ICB_MAXHOSTLEN); 52 else if (strlen(is->hostname) < ICB_MAXHOSTLEN) { 53 for (res = ar->ar_addrinfo; res; res = res->ai_next) { 54 if (cmp_addr(res->ai_addr, (struct sockaddr *) 55 &is->ss) == 0) { 56 strlcpy(is->host, is->hostname, 57 ICB_MAXHOSTLEN); 58 found = 1; 59 break; 60 } 61 } 62 if (!found) 63 icbd_log(is, LOG_WARNING, "hostname %s does " 64 "not resolve back to connecting ip %s", 65 is->hostname, is->host); 66 } 55 67 } else 56 68 icbd_log(is, LOG_WARNING, "dns resolution failed: %s", 57 69 gai_strerror(ar->ar_gai_errno)); 70 71 if (ar->ar_addrinfo) 72 freeaddrinfo(ar->ar_addrinfo); 58 73 59 74 if (ISSETF(is->flags, ICB_SF_PENDINGDROP)) { … … 92 107 } 93 108 109 int 110 cmp_addr(struct sockaddr *a, struct sockaddr *b) 111 { 112 if (a->sa_family != b->sa_family) 113 return (a->sa_family - b->sa_family); 114 115 if (a->sa_family == AF_INET) 116 return (((struct sockaddr_in *)a)->sin_addr.s_addr - 117 ((struct sockaddr_in *)b)->sin_addr.s_addr); 118 119 if (a->sa_family == AF_INET6) 120 return (memcmp(&((struct sockaddr_in6 *)a)->sin6_addr, 121 &((struct sockaddr_in6 *)b)->sin6_addr, 122 sizeof (struct in6_addr))); 123 124 return -1; 125 126 } 127 94 128 void 95 dns_resolve(struct icb_session *is , struct sockaddr *sa)129 dns_resolve(struct icb_session *is) 96 130 { 97 131 struct asr_query *as; … … 105 139 icbd_log(is, LOG_DEBUG, "resolving: %s", is->host); 106 140 107 as = getnameinfo_async(sa, sa->sa_len, is->hostname, 141 as = getnameinfo_async((struct sockaddr *)&is->ss, 142 ((struct sockaddr *)&is->ss)->sa_len, is->hostname, 108 143 sizeof is->hostname, NULL, 0, NI_NOFQDN, NULL); 109 144 event_asr_run(as, dns_done_reverse, is);
Note:
See TracChangeset
for help on using the changeset viewer.