VirtualBox

Changeset 49315 in vbox for trunk


Ignore:
Timestamp:
Oct 29, 2013 12:21:04 AM (11 years ago)
Author:
vboxsync
Message:

fwspec_set: use getaddrinfo() version on Windows too

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/portfwd.c

    r49300 r49315  
    127127
    128128
    129 
    130 #ifndef RT_OS_WINDOWS
    131129int
    132130fwspec_set(struct fwspec *fwspec, int sdom, int stype,
     
    182180    return 0;
    183181}
    184 #else  /* RT_OS_WINDOWS */
    185 /**
    186  * Windows only provides inet_pton() since Vista, but XP already has
    187  * WSAStringToAddressA() that does what we want (NB: its AddressString
    188  * argument is not declared const).
    189  */
    190 int
    191 fwspec_set(struct fwspec *fwspec, int sdom, int stype,
    192            const char *src_addr_str, uint16_t src_port,
    193            const char *dst_addr_str, uint16_t dst_port)
    194 {
    195     int saf;
    196     int socklen;
    197     int status;
    198 
    199     LWIP_ASSERT1(sdom == PF_INET || sdom == PF_INET6);
    200     LWIP_ASSERT1(stype == SOCK_STREAM || stype == SOCK_DGRAM);
    201 
    202     fwspec->sdom = sdom;
    203     fwspec->stype = stype;
    204 
    205     saf = (sdom == PF_INET) ? AF_INET : AF_INET6;
    206 
    207     fwspec->src.sa.sa_family = saf;
    208     socklen = sizeof(fwspec->src);
    209     status = WSAStringToAddressA((char *)src_addr_str, saf, NULL,
    210                                   &fwspec->src.sa, &socklen);
    211     if (status == SOCKET_ERROR) {
    212         return -1;
    213     }
    214 
    215     fwspec->dst.sa.sa_family = saf;
    216     socklen = sizeof(fwspec->dst);
    217     status = WSAStringToAddressA((char *)dst_addr_str, saf, NULL,
    218                                 &fwspec->dst.sa, &socklen);
    219     if (status == SOCKET_ERROR) {
    220         return -1;
    221     }
    222 
    223     if (sdom == PF_INET) {
    224         fwspec->src.sin.sin_port = htons(src_port);
    225         fwspec->dst.sin.sin_port = htons(dst_port);
    226     }
    227     else { /* PF_INET6 */
    228         fwspec->src.sin6.sin6_port = htons(src_port);
    229         fwspec->dst.sin6.sin6_port = htons(dst_port);
    230     }
    231 
    232     return 0;
    233 }
    234 #endif /* RT_OS_WINDOWS */
    235182
    236183
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette