Changeset 49197 in vbox for trunk/src/VBox/NetworkServices/NAT
- Timestamp:
- Oct 20, 2013 10:19:35 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 90080
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/portfwd.c
r49027 r49197 5 5 #ifndef RT_OS_WINDOWS 6 6 #include <arpa/inet.h> 7 #include <netdb.h> 7 8 #include <poll.h> 8 9 #else … … 133 134 const char *dst_addr_str, uint16_t dst_port) 134 135 { 136 struct addrinfo hints; 137 struct addrinfo *ai; 135 138 int status; 136 int saf;137 139 void *src_addr, *dst_addr; 138 140 … … 143 145 fwspec->stype = stype; 144 146 147 memset(&hints, 0, sizeof(hints)); 148 hints.ai_family = (sdom == PF_INET) ? AF_INET : AF_INET6; 149 hints.ai_socktype = stype; 150 hints.ai_flags = AI_NUMERICHOST; 151 152 status = getaddrinfo(src_addr_str, NULL, &hints, &ai); 153 if (status != 0) { 154 DPRINTF(("%s - %s\n", src_addr_str, gai_strerror(status))); 155 return -1; 156 } 157 LWIP_ASSERT1(ai != NULL); 158 LWIP_ASSERT1(ai->ai_addrlen <= sizeof(fwspec->src)); 159 memcpy(&fwspec->src, ai->ai_addr, ai->ai_addrlen); 160 freeaddrinfo(ai); 161 ai = NULL; 162 163 status = getaddrinfo(dst_addr_str, NULL, &hints, &ai); 164 if (status != 0) { 165 DPRINTF(("%s - %s\n", dst_addr_str, gai_strerror(status))); 166 return -1; 167 } 168 LWIP_ASSERT1(ai != NULL); 169 LWIP_ASSERT1(ai->ai_addrlen <= sizeof(fwspec->dst)); 170 memcpy(&fwspec->dst, ai->ai_addr, ai->ai_addrlen); 171 freeaddrinfo(ai); 172 ai = NULL; 173 145 174 if (sdom == PF_INET) { 146 struct sockaddr_in *src = &fwspec->src.sin; 147 struct sockaddr_in *dst = &fwspec->dst.sin; 148 149 saf = AF_INET; 150 151 src->sin_family = saf; 152 #if HAVE_SA_LEN 153 src->sin_len = sizeof(*src); 154 #endif 155 src->sin_port = htons(src_port); 156 src_addr = &src->sin_addr; 157 158 dst->sin_family = saf; 159 #if HAVE_SA_LEN 160 dst->sin_len = sizeof(*dst); 161 #endif 162 dst->sin_port = htons(dst_port); 163 dst_addr = &dst->sin_addr; 175 fwspec->src.sin.sin_port = htons(src_port); 176 fwspec->dst.sin.sin_port = htons(dst_port); 164 177 } 165 178 else { /* PF_INET6 */ 166 struct sockaddr_in6 *src = &fwspec->src.sin6; 167 struct sockaddr_in6 *dst = &fwspec->dst.sin6; 168 169 saf = AF_INET6; 170 171 src->sin6_family = saf; 172 #if HAVE_SA_LEN 173 src->sin6_len = sizeof(*src); 174 #endif 175 src->sin6_port = htons(src_port); 176 src_addr = &src->sin6_addr; 177 178 dst->sin6_family = saf; 179 #if HAVE_SA_LEN 180 dst->sin6_len = sizeof(*dst); 181 #endif 182 dst->sin6_port = htons(dst_port); 183 dst_addr = &dst->sin6_addr; 184 } 185 186 status = inet_pton(saf, src_addr_str, src_addr); 187 LWIP_ASSERT1(status >= 0); 188 if (status == 0) { 189 DPRINTF(("bad address: %s\n", src_addr_str)); 190 return -1; 191 } 192 193 status = inet_pton(saf, dst_addr_str, dst_addr); 194 LWIP_ASSERT1(status >= 0); 195 if (status == 0) { 196 DPRINTF(("bad address: %s\n", dst_addr_str)); 197 return -1; 179 fwspec->src.sin6.sin6_port = htons(src_port); 180 fwspec->dst.sin6.sin6_port = htons(dst_port); 198 181 } 199 182
Note:
See TracChangeset
for help on using the changeset viewer.