]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gsocket.cpp
f611abaea5531b9dc11fd7919dba709c47001c83
   1 /* ------------------------------------------------------------------------- 
   2  * Project:     wxSocketImpl (Generic Socket) 
   3  * Name:        src/msw/gsocket.cpp 
   4  * Copyright:   (c) Guilhem Lavaux 
   5  * Licence:     wxWindows Licence 
   6  * Author:      Guillermo Rodriguez Garcia <guille@iies.es> 
   7  * Purpose:     wxSocketImpl main MSW file 
   8  * Licence:     The wxWindows licence 
  10  * ------------------------------------------------------------------------- 
  13 // For compilers that support precompilation, includes "wx.h". 
  14 #include "wx/wxprec.h" 
  21    /* RPCNOTIFICATION_ROUTINE in rasasync.h (included from winsock.h), 
  22     * warning: conditional expression is constant. 
  24 #  pragma warning(disable:4115) 
  26     * warning: named type definition in parentheses. 
  28 #  pragma warning(disable:4127) 
  29    /* GAddress_UNIX_GetPath, 
  30     * warning: unreferenced formal parameter. 
  32 #  pragma warning(disable:4100) 
  35     /* windows.h results in tons of warnings at max warning level */ 
  37 #       pragma warning(push, 1) 
  42 #       pragma warning(disable:4514) 
  48 #if defined(__CYGWIN__) 
  49     //CYGWIN gives annoying warning about runtime stuff if we don't do this 
  50 #   define USE_SYS_TYPES_FD_SET 
  51 #   include <sys/types.h> 
  56 #include "wx/platform.h" 
  60 #include "wx/private/gsocket.h" 
  63 wxFORCE_LINK_MODULE(gsockmsw
) 
  67 #define isdigit(x) (x > 47 && x < 58) 
  69 #include "wx/msw/wince/net.h" 
  78 #include "wx/private/socket.h" 
  80 void wxSocketImplMSW::DoClose() 
  82     wxSocketManager::Get()-> 
  83         Uninstall_Callback(this, wxSOCKET_MAX_EVENT 
/* unused anyhow */); 
  89  *  Waits for an incoming client connection. Returns a pointer to 
  90  *  a wxSocketImpl object, or NULL if there was an error, in which case 
  91  *  the last error field will be updated for the calling wxSocketImpl. 
  93  *  Error codes (set in the calling wxSocketImpl) 
  94  *    wxSOCKET_INVSOCK    - the socket is not valid or not a server. 
  95  *    wxSOCKET_TIMEDOUT   - timeout, no incoming connections. 
  96  *    wxSOCKET_WOULDBLOCK - the call would block and the socket is nonblocking. 
  97  *    wxSOCKET_MEMERR     - couldn't allocate memory. 
  98  *    wxSOCKET_IOERR      - low-level error. 
 100 wxSocketImpl 
*wxSocketImplMSW::WaitConnection(wxSocketBase
& wxsocket
) 
 102   wxSocketImpl 
*connection
; 
 104   WX_SOCKLEN_T fromlen 
= sizeof(from
); 
 108   /* Reenable CONNECTION events */ 
 109   m_detected 
&= ~wxSOCKET_CONNECTION_FLAG
; 
 111   /* If the socket has already been created, we exit immediately */ 
 112   if (m_fd 
== INVALID_SOCKET 
|| !m_server
) 
 114     m_error 
= wxSOCKET_INVSOCK
; 
 118   /* Create a wxSocketImpl object for the new connection */ 
 119   connection 
= wxSocketImplMSW::Create(wxsocket
); 
 123     m_error 
= wxSOCKET_MEMERR
; 
 127   /* Wait for a connection (with timeout) */ 
 128   if (Input_Timeout() == wxSOCKET_TIMEDOUT
) 
 131     /* m_error set by Input_Timeout */ 
 135   connection
->m_fd 
= accept(m_fd
, (sockaddr
*)&from
, &fromlen
); 
 137   if (connection
->m_fd 
== INVALID_SOCKET
) 
 139     if (WSAGetLastError() == WSAEWOULDBLOCK
) 
 140       m_error 
= wxSOCKET_WOULDBLOCK
; 
 142       m_error 
= wxSOCKET_IOERR
; 
 148   /* Initialize all fields */ 
 149   connection
->m_server   
= false; 
 150   connection
->m_stream   
= true; 
 152   /* Setup the peer address field */ 
 153   connection
->m_peer 
= GAddress_new(); 
 154   if (!connection
->m_peer
) 
 157     m_error 
= wxSOCKET_MEMERR
; 
 160   err 
= _GAddress_translate_from(connection
->m_peer
, (sockaddr
*)&from
, fromlen
); 
 161   if (err 
!= wxSOCKET_NOERROR
) 
 163     GAddress_destroy(connection
->m_peer
); 
 169   ioctlsocket(connection
->m_fd
, FIONBIO
, (u_long FAR 
*) &arg
); 
 170   wxSocketManager::Get()->Install_Callback(connection
); 
 175 wxSocketError 
wxSocketImplMSW::DoHandleConnect(int ret
) 
 178     if (ret 
== SOCKET_ERROR
) 
 180         int err 
= WSAGetLastError(); 
 182         /* If connect failed with EWOULDBLOCK and the wxSocketImpl object 
 183          * is in blocking mode, we select() for the specified timeout 
 184          * checking for writability to see if the connection request 
 187         if ((err 
== WSAEWOULDBLOCK
) && (!m_non_blocking
)) 
 189             err 
= Connect_Timeout(); 
 191             if (err 
!= wxSOCKET_NOERROR
) 
 194                 /* m_error is set in Connect_Timeout */ 
 197             return (wxSocketError
) err
; 
 200         /* If connect failed with EWOULDBLOCK and the wxSocketImpl object 
 201          * is set to nonblocking, we set m_error to wxSOCKET_WOULDBLOCK 
 202          * (and return wxSOCKET_WOULDBLOCK) but we don't close the socket; 
 203          * this way if the connection completes, a wxSOCKET_CONNECTION 
 204          * event will be generated, if enabled. 
 206         if ((err 
== WSAEWOULDBLOCK
) && (m_non_blocking
)) 
 208             m_establishing 
= true; 
 209             m_error 
= wxSOCKET_WOULDBLOCK
; 
 210             return wxSOCKET_WOULDBLOCK
; 
 213         /* If connect failed with an error other than EWOULDBLOCK, 
 214          * then the call to Connect() has failed. 
 217         m_error 
= wxSOCKET_IOERR
; 
 218         return wxSOCKET_IOERR
; 
 221     return wxSOCKET_NOERROR
; 
 226 /* Like recv(), send(), ... */ 
 227 int wxSocketImplMSW::Read(char *buffer
, int size
) 
 231   /* Reenable INPUT events */ 
 232   m_detected 
&= ~wxSOCKET_INPUT_FLAG
; 
 234   if (m_fd 
== INVALID_SOCKET 
|| m_server
) 
 236     m_error 
= wxSOCKET_INVSOCK
; 
 240   /* If the socket is blocking, wait for data (with a timeout) */ 
 241   if (Input_Timeout() == wxSOCKET_TIMEDOUT
) 
 243     m_error 
= wxSOCKET_TIMEDOUT
; 
 249     ret 
= Recv_Stream(buffer
, size
); 
 251     ret 
= Recv_Dgram(buffer
, size
); 
 253   if (ret 
== SOCKET_ERROR
) 
 255     if (WSAGetLastError() != WSAEWOULDBLOCK
) 
 256       m_error 
= wxSOCKET_IOERR
; 
 258       m_error 
= wxSOCKET_WOULDBLOCK
; 
 265 int wxSocketImplMSW::Write(const char *buffer
, int size
) 
 269   if (m_fd 
== INVALID_SOCKET 
|| m_server
) 
 271     m_error 
= wxSOCKET_INVSOCK
; 
 275   /* If the socket is blocking, wait for writability (with a timeout) */ 
 276   if (Output_Timeout() == wxSOCKET_TIMEDOUT
) 
 281     ret 
= Send_Stream(buffer
, size
); 
 283     ret 
= Send_Dgram(buffer
, size
); 
 285   if (ret 
== SOCKET_ERROR
) 
 287     if (WSAGetLastError() != WSAEWOULDBLOCK
) 
 288       m_error 
= wxSOCKET_IOERR
; 
 290       m_error 
= wxSOCKET_WOULDBLOCK
; 
 292     /* Only reenable OUTPUT events after an error (just like WSAAsyncSelect 
 293      * does). Once the first OUTPUT event is received, users can assume 
 294      * that the socket is writable until a read operation fails. Only then 
 295      * will further OUTPUT events be posted. 
 297     m_detected 
&= ~wxSOCKET_OUTPUT_FLAG
; 
 307  *  For blocking sockets, wait until data is available or 
 308  *  until timeout ellapses. 
 310 wxSocketError 
wxSocketImplMSW::Input_Timeout() 
 317     FD_SET(m_fd
, &readfds
); 
 318     if (select(0, &readfds
, NULL
, NULL
, &m_timeout
) == 0) 
 320       m_error 
= wxSOCKET_TIMEDOUT
; 
 321       return wxSOCKET_TIMEDOUT
; 
 324   return wxSOCKET_NOERROR
; 
 328  *  For blocking sockets, wait until data can be sent without 
 329  *  blocking or until timeout ellapses. 
 331 wxSocketError 
wxSocketImplMSW::Output_Timeout() 
 338     FD_SET(m_fd
, &writefds
); 
 339     if (select(0, NULL
, &writefds
, NULL
, &m_timeout
) == 0) 
 341       m_error 
= wxSOCKET_TIMEDOUT
; 
 342       return wxSOCKET_TIMEDOUT
; 
 345   return wxSOCKET_NOERROR
; 
 349  *  For blocking sockets, wait until the connection is 
 350  *  established or fails, or until timeout ellapses. 
 352 wxSocketError 
wxSocketImplMSW::Connect_Timeout() 
 359   FD_SET(m_fd
, &writefds
); 
 360   FD_SET(m_fd
, &exceptfds
); 
 361   if (select(0, NULL
, &writefds
, &exceptfds
, &m_timeout
) == 0) 
 363     m_error 
= wxSOCKET_TIMEDOUT
; 
 364     return wxSOCKET_TIMEDOUT
; 
 366   if (!FD_ISSET(m_fd
, &writefds
)) 
 368     m_error 
= wxSOCKET_IOERR
; 
 369     return wxSOCKET_IOERR
; 
 372   return wxSOCKET_NOERROR
; 
 375 int wxSocketImplMSW::Recv_Stream(char *buffer
, int size
) 
 377   return recv(m_fd
, buffer
, size
, 0); 
 380 int wxSocketImplMSW::Recv_Dgram(char *buffer
, int size
) 
 383   WX_SOCKLEN_T fromlen 
= sizeof(from
); 
 387   ret 
= recvfrom(m_fd
, buffer
, size
, 0, (sockaddr
*)&from
, &fromlen
); 
 389   if (ret 
== SOCKET_ERROR
) 
 392   /* Translate a system address into a wxSocketImpl address */ 
 395     m_peer 
= GAddress_new(); 
 398       m_error 
= wxSOCKET_MEMERR
; 
 402   err 
= _GAddress_translate_from(m_peer
, (sockaddr
*)&from
, fromlen
); 
 403   if (err 
!= wxSOCKET_NOERROR
) 
 405     GAddress_destroy(m_peer
); 
 414 int wxSocketImplMSW::Send_Stream(const char *buffer
, int size
) 
 416   return send(m_fd
, buffer
, size
, 0); 
 419 int wxSocketImplMSW::Send_Dgram(const char *buffer
, int size
) 
 421   struct sockaddr 
*addr
; 
 427     m_error 
= wxSOCKET_INVADDR
; 
 431   err 
= _GAddress_translate_to(m_peer
, &addr
, &len
); 
 432   if (err 
!= wxSOCKET_NOERROR
) 
 438   ret 
= sendto(m_fd
, buffer
, size
, 0, addr
, len
); 
 440   /* Frees memory allocated by _GAddress_translate_to */ 
 447  * ------------------------------------------------------------------------- 
 449  * ------------------------------------------------------------------------- 
 452 /* CHECK_ADDRESS verifies that the current address family is either 
 453  * wxSOCKET_NOFAMILY or wxSOCKET_*family*, and if it is wxSOCKET_NOFAMILY, it 
 454  * initalizes it to be a wxSOCKET_*family*. In other cases, it returns 
 455  * an appropiate error code. 
 457  * CHECK_ADDRESS_RETVAL does the same but returning 'retval' on error. 
 459 #define CHECK_ADDRESS(address, family)                              \ 
 461   if (address->m_family == wxSOCKET_NOFAMILY)                          \ 
 462     if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \ 
 463       return address->m_error;                                      \ 
 464   if (address->m_family != wxSOCKET_##family)                          \ 
 466     address->m_error = wxSOCKET_INVADDR;                               \ 
 467     return wxSOCKET_INVADDR;                                           \ 
 471 #define CHECK_ADDRESS_RETVAL(address, family, retval)               \ 
 473   if (address->m_family == wxSOCKET_NOFAMILY)                          \ 
 474     if (_GAddress_Init_##family(address) != wxSOCKET_NOERROR)          \ 
 476   if (address->m_family != wxSOCKET_##family)                          \ 
 478     address->m_error = wxSOCKET_INVADDR;                               \ 
 484 GAddress 
*GAddress_new() 
 488   if ((address 
= (GAddress 
*) malloc(sizeof(GAddress
))) == NULL
) 
 491   address
->m_family 
= wxSOCKET_NOFAMILY
; 
 492   address
->m_addr   
= NULL
; 
 498 GAddress 
*GAddress_copy(GAddress 
*address
) 
 502   if ((addr2 
= (GAddress 
*) malloc(sizeof(GAddress
))) == NULL
) 
 505   memcpy(addr2
, address
, sizeof(GAddress
)); 
 509     addr2
->m_addr 
= (struct sockaddr 
*) malloc(addr2
->m_len
); 
 510     if (addr2
->m_addr 
== NULL
) 
 515     memcpy(addr2
->m_addr
, address
->m_addr
, addr2
->m_len
); 
 521 void GAddress_destroy(GAddress 
*address
) 
 524     free(address
->m_addr
); 
 529 void GAddress_SetFamily(GAddress 
*address
, GAddressType type
) 
 531   address
->m_family 
= type
; 
 534 GAddressType 
GAddress_GetFamily(GAddress 
*address
) 
 536   return address
->m_family
; 
 539 wxSocketError 
_GAddress_translate_from(GAddress 
*address
, 
 540                                       struct sockaddr 
*addr
, int len
) 
 542   address
->m_realfamily 
= addr
->sa_family
; 
 543   switch (addr
->sa_family
) 
 546       address
->m_family 
= wxSOCKET_INET
; 
 549       address
->m_family 
= wxSOCKET_UNIX
; 
 553       address
->m_family 
= wxSOCKET_INET6
; 
 558       address
->m_error 
= wxSOCKET_INVOP
; 
 559       return wxSOCKET_INVOP
; 
 564     free(address
->m_addr
); 
 566   address
->m_len 
= len
; 
 567   address
->m_addr 
= (struct sockaddr 
*) malloc(len
); 
 569   if (address
->m_addr 
== NULL
) 
 571     address
->m_error 
= wxSOCKET_MEMERR
; 
 572     return wxSOCKET_MEMERR
; 
 574   memcpy(address
->m_addr
, addr
, len
); 
 576   return wxSOCKET_NOERROR
; 
 579 wxSocketError 
_GAddress_translate_to(GAddress 
*address
, 
 580                                     struct sockaddr 
**addr
, int *len
) 
 582   if (!address
->m_addr
) 
 584     address
->m_error 
= wxSOCKET_INVADDR
; 
 585     return wxSOCKET_INVADDR
; 
 588   *len 
= address
->m_len
; 
 589   *addr 
= (struct sockaddr 
*) malloc(address
->m_len
); 
 592     address
->m_error 
= wxSOCKET_MEMERR
; 
 593     return wxSOCKET_MEMERR
; 
 596   memcpy(*addr
, address
->m_addr
, address
->m_len
); 
 597   return wxSOCKET_NOERROR
; 
 601  * ------------------------------------------------------------------------- 
 602  * Internet address family 
 603  * ------------------------------------------------------------------------- 
 606 wxSocketError 
_GAddress_Init_INET(GAddress 
*address
) 
 608   address
->m_len  
= sizeof(struct sockaddr_in
); 
 609   address
->m_addr 
= (struct sockaddr 
*) malloc(address
->m_len
); 
 610   if (address
->m_addr 
== NULL
) 
 612     address
->m_error 
= wxSOCKET_MEMERR
; 
 613     return wxSOCKET_MEMERR
; 
 616   address
->m_family 
= wxSOCKET_INET
; 
 617   address
->m_realfamily 
= AF_INET
; 
 618   ((struct sockaddr_in 
*)address
->m_addr
)->sin_family 
= AF_INET
; 
 619   ((struct sockaddr_in 
*)address
->m_addr
)->sin_addr
.s_addr 
= INADDR_ANY
; 
 621   return wxSOCKET_NOERROR
; 
 624 wxSocketError 
GAddress_INET_SetHostName(GAddress 
*address
, const char *hostname
) 
 627   struct in_addr 
*addr
; 
 629   CHECK_ADDRESS(address
, INET
); 
 631   addr 
= &(((struct sockaddr_in 
*)address
->m_addr
)->sin_addr
); 
 633   addr
->s_addr 
= inet_addr(hostname
); 
 635   /* If it is a numeric host name, convert it now */ 
 636   if (addr
->s_addr 
== INADDR_NONE
) 
 638     struct in_addr 
*array_addr
; 
 640     /* It is a real name, we solve it */ 
 641     if ((he 
= gethostbyname(hostname
)) == NULL
) 
 643       /* addr->s_addr = INADDR_NONE just done by inet_addr() above */ 
 644       address
->m_error 
= wxSOCKET_NOHOST
; 
 645       return wxSOCKET_NOHOST
; 
 647     array_addr 
= (struct in_addr 
*) *(he
->h_addr_list
); 
 648     addr
->s_addr 
= array_addr
[0].s_addr
; 
 650   return wxSOCKET_NOERROR
; 
 653 wxSocketError 
GAddress_INET_SetBroadcastAddress(GAddress 
*address
) 
 655   return GAddress_INET_SetHostAddress(address
, INADDR_BROADCAST
); 
 658 wxSocketError 
GAddress_INET_SetAnyAddress(GAddress 
*address
) 
 660   return GAddress_INET_SetHostAddress(address
, INADDR_ANY
); 
 663 wxSocketError 
GAddress_INET_SetHostAddress(GAddress 
*address
, 
 664                                           unsigned long hostaddr
) 
 666   struct in_addr 
*addr
; 
 668   CHECK_ADDRESS(address
, INET
); 
 670   addr 
= &(((struct sockaddr_in 
*)address
->m_addr
)->sin_addr
); 
 671   addr
->s_addr 
= htonl(hostaddr
); 
 673   return wxSOCKET_NOERROR
; 
 676 wxSocketError 
GAddress_INET_SetPortName(GAddress 
*address
, const char *port
, 
 677                                        const char *protocol
) 
 680   struct sockaddr_in 
*addr
; 
 682   CHECK_ADDRESS(address
, INET
); 
 686     address
->m_error 
= wxSOCKET_INVPORT
; 
 687     return wxSOCKET_INVPORT
; 
 690   se 
= getservbyname(port
, protocol
); 
 693     if (isdigit(port
[0])) 
 697       port_int 
= atoi(port
); 
 698       addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 699       addr
->sin_port 
= htons((u_short
) port_int
); 
 700       return wxSOCKET_NOERROR
; 
 703     address
->m_error 
= wxSOCKET_INVPORT
; 
 704     return wxSOCKET_INVPORT
; 
 707   addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 708   addr
->sin_port 
= se
->s_port
; 
 710   return wxSOCKET_NOERROR
; 
 713 wxSocketError 
GAddress_INET_SetPort(GAddress 
*address
, unsigned short port
) 
 715   struct sockaddr_in 
*addr
; 
 717   CHECK_ADDRESS(address
, INET
); 
 719   addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 720   addr
->sin_port 
= htons(port
); 
 722   return wxSOCKET_NOERROR
; 
 725 wxSocketError 
GAddress_INET_GetHostName(GAddress 
*address
, char *hostname
, size_t sbuf
) 
 729   struct sockaddr_in 
*addr
; 
 731   CHECK_ADDRESS(address
, INET
); 
 733   addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 734   addr_buf 
= (char *)&(addr
->sin_addr
); 
 736   he 
= gethostbyaddr(addr_buf
, sizeof(addr
->sin_addr
), AF_INET
); 
 739     address
->m_error 
= wxSOCKET_NOHOST
; 
 740     return wxSOCKET_NOHOST
; 
 743   strncpy(hostname
, he
->h_name
, sbuf
); 
 745   return wxSOCKET_NOERROR
; 
 748 unsigned long GAddress_INET_GetHostAddress(GAddress 
*address
) 
 750   struct sockaddr_in 
*addr
; 
 752   CHECK_ADDRESS_RETVAL(address
, INET
, 0); 
 754   addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 756   return ntohl(addr
->sin_addr
.s_addr
); 
 759 unsigned short GAddress_INET_GetPort(GAddress 
*address
) 
 761   struct sockaddr_in 
*addr
; 
 763   CHECK_ADDRESS_RETVAL(address
, INET
, 0); 
 765   addr 
= (struct sockaddr_in 
*)address
->m_addr
; 
 766   return ntohs(addr
->sin_port
); 
 772  * ------------------------------------------------------------------------- 
 773  * Internet IPv6 address family 
 774  * ------------------------------------------------------------------------- 
 776 #include "ws2tcpip.h" 
 779     #pragma comment(lib,"ws2_32") 
 780 #endif // __VISUALC__ 
 782 wxSocketError 
_GAddress_Init_INET6(GAddress 
*address
) 
 784   struct in6_addr any_address 
= IN6ADDR_ANY_INIT
; 
 785   address
->m_len  
= sizeof(struct sockaddr_in6
); 
 786   address
->m_addr 
= (struct sockaddr 
*) malloc(address
->m_len
); 
 787   if (address
->m_addr 
== NULL
) 
 789     address
->m_error 
= wxSOCKET_MEMERR
; 
 790     return wxSOCKET_MEMERR
; 
 792   memset(address
->m_addr
,0,address
->m_len
); 
 794   address
->m_family 
= wxSOCKET_INET6
; 
 795   address
->m_realfamily 
= AF_INET6
; 
 796   ((struct sockaddr_in6 
*)address
->m_addr
)->sin6_family 
= AF_INET6
; 
 797   ((struct sockaddr_in6 
*)address
->m_addr
)->sin6_addr 
= any_address
; 
 799   return wxSOCKET_NOERROR
; 
 802 wxSocketError 
GAddress_INET6_SetHostName(GAddress 
*address
, const char *hostname
) 
 804   CHECK_ADDRESS(address
, INET6
); 
 807   memset( & hints
, 0, sizeof( hints 
) ); 
 808   hints
.ai_family 
= AF_INET6
; 
 810   if ( getaddrinfo( hostname
, "0", & hints
, & info 
) || ! info 
) 
 812     address
->m_error 
= wxSOCKET_NOHOST
; 
 813     return wxSOCKET_NOHOST
; 
 816   memcpy( address
->m_addr
, info
->ai_addr
, info
->ai_addrlen 
); 
 817   freeaddrinfo( info 
); 
 818   return wxSOCKET_NOERROR
; 
 821 wxSocketError 
GAddress_INET6_SetAnyAddress(GAddress 
*address
) 
 823   CHECK_ADDRESS(address
, INET6
); 
 825   struct in6_addr addr
; 
 826   memset( & addr
, 0, sizeof( addr 
) ); 
 827   return GAddress_INET6_SetHostAddress(address
, addr
); 
 829 wxSocketError 
GAddress_INET6_SetHostAddress(GAddress 
*address
, 
 830                                           struct in6_addr hostaddr
) 
 832   CHECK_ADDRESS(address
, INET6
); 
 834   ((struct sockaddr_in6 
*)address
->m_addr
)->sin6_addr 
= hostaddr
; 
 836   return wxSOCKET_NOERROR
; 
 839 wxSocketError 
GAddress_INET6_SetPortName(GAddress 
*address
, const char *port
, 
 840                                        const char *protocol
) 
 843   struct sockaddr_in6 
*addr
; 
 845   CHECK_ADDRESS(address
, INET6
); 
 849     address
->m_error 
= wxSOCKET_INVPORT
; 
 850     return wxSOCKET_INVPORT
; 
 853   se 
= getservbyname(port
, protocol
); 
 856     if (isdigit((unsigned char) port
[0])) 
 860       port_int 
= atoi(port
); 
 861       addr 
= (struct sockaddr_in6 
*)address
->m_addr
; 
 862       addr
->sin6_port 
= htons((u_short
) port_int
); 
 863       return wxSOCKET_NOERROR
; 
 866     address
->m_error 
= wxSOCKET_INVPORT
; 
 867     return wxSOCKET_INVPORT
; 
 870   addr 
= (struct sockaddr_in6 
*)address
->m_addr
; 
 871   addr
->sin6_port 
= se
->s_port
; 
 873   return wxSOCKET_NOERROR
; 
 876 wxSocketError 
GAddress_INET6_SetPort(GAddress 
*address
, unsigned short port
) 
 878   struct sockaddr_in6 
*addr
; 
 880   CHECK_ADDRESS(address
, INET6
); 
 882   addr 
= (struct sockaddr_in6 
*)address
->m_addr
; 
 883   addr
->sin6_port 
= htons(port
); 
 885   return wxSOCKET_NOERROR
; 
 888 wxSocketError 
GAddress_INET6_GetHostName(GAddress 
*address
, char *hostname
, size_t sbuf
) 
 892   struct sockaddr_in6 
*addr
; 
 894   CHECK_ADDRESS(address
, INET6
); 
 896   addr 
= (struct sockaddr_in6 
*)address
->m_addr
; 
 897   addr_buf 
= (char *)&(addr
->sin6_addr
); 
 899   he 
= gethostbyaddr(addr_buf
, sizeof(addr
->sin6_addr
), AF_INET6
); 
 902     address
->m_error 
= wxSOCKET_NOHOST
; 
 903     return wxSOCKET_NOHOST
; 
 906   strncpy(hostname
, he
->h_name
, sbuf
); 
 908   return wxSOCKET_NOERROR
; 
 911 wxSocketError 
GAddress_INET6_GetHostAddress(GAddress 
*address
,struct in6_addr 
*hostaddr
) 
 913   CHECK_ADDRESS_RETVAL(address
, INET6
, wxSOCKET_INVADDR
); 
 914   *hostaddr 
= ( (struct sockaddr_in6 
*)address
->m_addr 
)->sin6_addr
; 
 915   return wxSOCKET_NOERROR
; 
 918 unsigned short GAddress_INET6_GetPort(GAddress 
*address
) 
 920   CHECK_ADDRESS_RETVAL(address
, INET6
, 0); 
 922   return ntohs( ((struct sockaddr_in6 
*)address
->m_addr
)->sin6_port 
); 
 928  * ------------------------------------------------------------------------- 
 929  * Unix address family 
 930  * ------------------------------------------------------------------------- 
 933 wxSocketError 
_GAddress_Init_UNIX(GAddress 
*address
) 
 935   address
->m_error 
= wxSOCKET_INVADDR
; 
 936   return wxSOCKET_INVADDR
; 
 939 wxSocketError 
GAddress_UNIX_SetPath(GAddress 
*address
, const char *WXUNUSED(path
)) 
 941   address
->m_error 
= wxSOCKET_INVADDR
; 
 942   return wxSOCKET_INVADDR
; 
 945 wxSocketError 
GAddress_UNIX_GetPath(GAddress 
*address
, char *WXUNUSED(path
), size_t WXUNUSED(sbuf
)) 
 947   address
->m_error 
= wxSOCKET_INVADDR
; 
 948   return wxSOCKET_INVADDR
; 
 951 #endif  // wxUSE_SOCKETS