Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/inet_common.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/inet_common.c
r3232 r3621 33 33 } 34 34 /* If we expect this to be a hostname, try hostname database first */ 35 #ifdef DEBUG36 35 if (hostfirst) { 36 #ifdef DEBUG 37 37 bb_error_msg("gethostbyname(%s)", name); 38 } 39 #endif 40 if (hostfirst) { 38 #endif 41 39 hp = gethostbyname(name); 42 if (hp != NULL) {40 if (hp) { 43 41 memcpy(&s_in->sin_addr, hp->h_addr_list[0], 44 42 sizeof(struct in_addr)); … … 52 50 #endif 53 51 np = getnetbyname(name); 54 if (np != NULL) {52 if (np) { 55 53 s_in->sin_addr.s_addr = htonl(np->n_net); 56 54 return 1; … … 67 65 #endif 68 66 hp = gethostbyname(name); 69 if ( hp == NULL) {67 if (!hp) { 70 68 return -1; 71 69 } … … 75 73 76 74 77 /* numeric: & 0x8000: default instead of *,75 /* numeric: & 0x8000: "default" instead of "*", 78 76 * & 0x4000: host instead of net, 79 77 * & 0x0fff: don't resolve … … 84 82 struct addr { 85 83 struct addr *next; 86 struct sockaddr_in addr;87 inthost;84 uint32_t nip; 85 smallint is_host; 88 86 char name[1]; 89 87 }; … … 92 90 struct addr *pn; 93 91 char *name; 94 uint32_t ad, host_ad;95 int host = 0;92 uint32_t nip; 93 smallint is_host; 96 94 97 95 if (s_in->sin_family != AF_INET) { … … 103 101 return NULL; 104 102 } 105 ad = s_in->sin_addr.s_addr; 106 #ifdef DEBUG 107 bb_error_msg("rresolve: %08x, mask %08x, num %08x", (unsigned)ad, netmask, numeric); 108 #endif 109 if (ad == INADDR_ANY) { 110 if ((numeric & 0x0FFF) == 0) { 111 if (numeric & 0x8000) 112 return xstrdup("default"); 113 return xstrdup("*"); 114 } 115 } 103 nip = s_in->sin_addr.s_addr; 104 #ifdef DEBUG 105 bb_error_msg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric); 106 #endif 116 107 if (numeric & 0x0FFF) 117 return xstrdup(inet_ntoa(s_in->sin_addr)); 118 119 if ((ad & (~netmask)) != 0 || (numeric & 0x4000)) 120 host = 1; 108 return xmalloc_sockaddr2dotted_noport((void*)s_in); 109 if (nip == INADDR_ANY) { 110 if (numeric & 0x8000) 111 return xstrdup("default"); 112 return xstrdup("*"); 113 } 114 115 is_host = ((nip & (~netmask)) != 0 || (numeric & 0x4000)); 116 121 117 pn = cache; 122 118 while (pn) { 123 if (pn-> addr.sin_addr.s_addr == ad && pn->host ==host) {119 if (pn->nip == nip && pn->is_host == is_host) { 124 120 #ifdef DEBUG 125 121 bb_error_msg("rresolve: found %s %08x in cache", 126 (host ? "host" : "net"), (unsigned)ad);122 (is_host ? "host" : "net"), (unsigned)nip); 127 123 #endif 128 124 return xstrdup(pn->name); … … 131 127 } 132 128 133 host_ad = ntohl(ad);134 129 name = NULL; 135 if (host) { 136 struct hostent *ent; 137 #ifdef DEBUG 138 bb_error_msg("gethostbyaddr (%08x)", (unsigned)ad); 139 #endif 140 ent = gethostbyaddr((char *) &ad, 4, AF_INET); 141 if (ent) 142 name = xstrdup(ent->h_name); 130 if (is_host) { 131 #ifdef DEBUG 132 bb_error_msg("sockaddr2host_noport(%08x)", (unsigned)nip); 133 #endif 134 name = xmalloc_sockaddr2host_noport((void*)s_in); 143 135 } else if (ENABLE_FEATURE_ETC_NETWORKS) { 144 136 struct netent *np; 145 137 #ifdef DEBUG 146 bb_error_msg("getnetbyaddr (%08x)", (unsigned)host_ad);147 #endif 148 np = getnetbyaddr( host_ad, AF_INET);138 bb_error_msg("getnetbyaddr(%08x)", (unsigned)ntohl(nip)); 139 #endif 140 np = getnetbyaddr(ntohl(nip), AF_INET); 149 141 if (np) 150 142 name = xstrdup(np->n_name); 151 143 } 152 144 if (!name) 153 name = xstrdup(inet_ntoa(s_in->sin_addr)); 145 name = xmalloc_sockaddr2dotted_noport((void*)s_in); 146 154 147 pn = xmalloc(sizeof(*pn) + strlen(name)); /* no '+ 1', it's already accounted for */ 155 148 pn->next = cache; 156 pn-> addr = *s_in;157 pn-> host =host;149 pn->nip = nip; 150 pn->is_host = is_host; 158 151 strcpy(pn->name, name); 159 152 cache = pn; 153 160 154 return name; 161 155 } … … 176 170 } 177 171 memcpy(sin6, ai->ai_addr, sizeof(*sin6)); 178 if (ai) 179 freeaddrinfo(ai); 172 freeaddrinfo(ai); 180 173 return 0; 181 174 } … … 190 183 char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric) 191 184 { 192 char name[128];193 int s;194 195 185 if (sin6->sin6_family != AF_INET6) { 196 186 #ifdef DEBUG … … 202 192 } 203 193 if (numeric & 0x7FFF) { 204 inet_ntop(AF_INET6, &sin6->sin6_addr, name, sizeof(name)); 205 return xstrdup(name); 194 return xmalloc_sockaddr2dotted_noport((void*)sin6); 206 195 } 207 196 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { … … 211 200 } 212 201 213 s = getnameinfo((struct sockaddr *) sin6, sizeof(*sin6), 214 name, sizeof(name), 215 /*serv,servlen:*/ NULL, 0, 216 0); 217 if (s != 0) { 218 bb_error_msg("getnameinfo failed"); 219 return NULL; 220 } 221 return xstrdup(name); 202 return xmalloc_sockaddr2host_noport((void*)sin6); 222 203 } 223 204
Note:
See TracChangeset
for help on using the changeset viewer.