Changeset 49022 in vbox for trunk/src/VBox
- Timestamp:
- Oct 10, 2013 9:23:49 AM (11 years ago)
- Location:
- trunk/src/VBox/NetworkServices/NAT
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/portfwd.c
r49016 r49022 127 127 128 128 129 #ifndef RT_OS_WINDOWS 129 130 int 130 131 fwspec_set(struct fwspec *fwspec, int sdom, int stype, … … 199 200 return 0; 200 201 } 202 #else /* RT_OS_WINDOWS */ 203 /** 204 * Windows only provides inet_pton() since Vista, but XP already has 205 * WSAStringToAddressA() that does what we want (NB: its AddressString 206 * argument is not declared const). 207 */ 208 int 209 fwspec_set(struct fwspec *fwspec, int sdom, int stype, 210 const char *src_addr_str, uint16_t src_port, 211 const char *dst_addr_str, uint16_t dst_port) 212 { 213 int saf; 214 int socklen; 215 int status; 216 217 LWIP_ASSERT1(sdom == PF_INET || sdom == PF_INET6); 218 LWIP_ASSERT1(stype == SOCK_STREAM || stype == SOCK_DGRAM); 219 220 fwspec->sdom = sdom; 221 fwspec->stype = stype; 222 223 saf = (sdom == PF_INET) ? AF_INET : AF_INET6; 224 225 socklen = sizeof(fwspec->src); 226 fwspec->src.sa.sa_family = saf; /* see "Remarks" WSAStringToAddress */ 227 status = WSAStringToAddressA((char *)src_addr_str, saf, NULL, 228 &fwspec->src.sa, &socklen); 229 if (status == SOCKET_ERROR) { 230 int error = WSAGetLastError(); 231 return -1; 232 } 233 234 if (fwspec->src.sa.sa_family != saf) { 235 return -1; 236 } 237 238 fwspec->dst.sa.sa_family = saf; 239 socklen = sizeof(fwspec->dst); 240 status = WSAStringToAddressA((char *)dst_addr_str, saf, NULL, 241 &fwspec->dst.sa, &socklen); 242 if (status == SOCKET_ERROR) { 243 int error = WSAGetLastError(); 244 return -1; 245 } 246 if (fwspec->dst.sa.sa_family != saf) { 247 return -1; 248 } 249 250 if (sdom == PF_INET) { 251 fwspec->src.sin.sin_port = htons(src_port); 252 fwspec->dst.sin.sin_port = htons(dst_port); 253 } 254 else { /* PF_INET6 */ 255 fwspec->src.sin6.sin6_port = htons(src_port); 256 fwspec->dst.sin6.sin6_port = htons(dst_port); 257 } 258 259 return 0; 260 } 261 #endif /* RT_OS_WINDOWS */ 201 262 202 263 -
trunk/src/VBox/NetworkServices/NAT/winutils.h
r48956 r49022 36 36 # define inet_ntop(dom, pvaddr, pstrbuf, cbstrbuf) InetNtop((dom),(pvaddr),(pstrbuf),(cbstrbuf)) 37 37 38 /**39 * inet_pton(3) returns 1 on success (network address was successfully40 * converted). 0 is returned if src does not contain a character string41 * representing a valid network address in the specified address family.42 * If af does not contain a valid address family, -1 is returned and43 * errno is set to EAFNOSUPPORT(value 97).44 * WSA has value most close in our case45 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx#WSAEAFNOSUPPORT (10047)46 */47 DECLINLINE(int) inet_pton(int af_family, const char *str, void *dst)48 {49 AssertPtrReturn(str, 0);50 AssertPtrReturn(dst, 0);51 52 switch (af_family) {53 case AF_INET: {54 RTNETADDRIPV4 a4;55 int rc = RTNetStrToIPv4Addr(str, &a4);56 AssertRCReturn(rc, -1);57 memcpy(dst, &a4, sizeof(RTNETADDRIPV4));58 break;59 }60 case AF_INET6: {61 #if 062 RTNETADDRIPV6 a6;63 int rc = RTNetStrToIPv6Addr(str, &a6);64 AssertRCReturn(rc, -1);65 memcpy(dst, &a6, sizeof(RTNETADDRIPV6));66 #else67 /* XXX: RTNetStrToIPv6Addr isn't implemented yet. */68 WSASetLastError(WSAEAFNOSUPPORT);69 return -1;70 #endif71 break;72 }73 default:74 WSASetLastError(WSAEAFNOSUPPORT);75 AssertMsgFailedReturn(("Unsupported internet family"), -1);76 }77 return 1;78 }79 38 80 39 /**
Note:
See TracChangeset
for help on using the changeset viewer.