1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
26 #include <osl/socket.h>
27 #include <osl/thread.h>
28 #include <osl/diagnose.h>
29 #include <rtl/alloc.h>
30 #include <rtl/byteseq.h>
31 #include <sal/log.hxx>
32 #include <o3tl/char16_t2wchar_t.hxx>
33 #include <o3tl/safeint.hxx>
34 #include <comphelper/windowserrorstring.hxx>
36 #include "sockimpl.hxx"
39 oslSocketAddr is a pointer to a Berkeley struct sockaddr.
40 I refrained from using sockaddr_in because of possible further
41 extensions of this socket-interface (IP-NG?).
42 The intention was to hide all Berkeley data-structures from
43 direct access past the osl-interface.
45 The current implementation is internet (IP) centered. All
46 the constructor-functions (osl_create...) take parameters
47 that will probably make sense only in the IP-environment
48 (e.g. because of using the dotted-Addr-format).
50 If the interface will be extended to host other protocol-
51 families, I expect no externally visible changes in the
52 existing functions. You'll probably need only new
53 constructor-functions who take the different Addr
54 formats into consideration (maybe a long dotted Addr
59 _Note_ that I rely on the fact that oslSocketAddr and struct sockaddr
60 are the same! I don't like it very much but see no other easy way to
61 conceal the struct sockaddr from the eyes of the user.
64 #define OSL_INVALID_SOCKET INVALID_SOCKET /* WIN32 */
65 #define OSL_SOCKET_ERROR SOCKET_ERROR /* WIN32 */
67 static DWORD FamilyMap
[]= {
68 AF_INET
, /* osl_Socket_FamilyInet */
69 AF_IPX
, /* osl_Socket_FamilyIpx */
70 0 /* osl_Socket_FamilyInvalid */
73 static oslAddrFamily
osl_AddrFamilyFromNative(DWORD nativeType
)
75 oslAddrFamily i
= oslAddrFamily(0);
76 while(i
!= osl_Socket_FamilyInvalid
)
78 if(FamilyMap
[i
] == nativeType
)
80 i
= static_cast<oslAddrFamily
>( static_cast<int>(i
) + 1);
85 #define FAMILY_FROM_NATIVE(y) osl_AddrFamilyFromNative(y)
86 #define FAMILY_TO_NATIVE(x) static_cast<short>(FamilyMap[x])
88 static DWORD ProtocolMap
[]= {
89 0, /* osl_Socket_FamilyInet */
90 NSPROTO_IPX
, /* osl_Socket_FamilyIpx */
91 NSPROTO_SPX
, /* osl_Socket_ProtocolSpx */
92 NSPROTO_SPXII
, /* osl_Socket_ProtocolSpx_ii */
93 0 /* osl_Socket_ProtocolInvalid */
96 #define PROTOCOL_TO_NATIVE(x) ProtocolMap[x]
98 static DWORD TypeMap
[]= {
99 SOCK_STREAM
, /* osl_Socket_TypeStream */
100 SOCK_DGRAM
, /* osl_Socket_TypeDgram */
101 SOCK_RAW
, /* osl_Socket_TypeRaw */
102 SOCK_RDM
, /* osl_Socket_TypeRdm */
103 SOCK_SEQPACKET
, /* osl_Socket_TypeSeqPacket */
104 0 /* osl_Socket_TypeInvalid */
107 static oslSocketType
osl_SocketTypeFromNative(DWORD nativeType
)
109 oslSocketType i
= oslSocketType(0);
110 while(i
!= osl_Socket_TypeInvalid
)
112 if(TypeMap
[i
] == nativeType
)
114 i
= static_cast<oslSocketType
>(static_cast<int>(i
)+1);
119 #define TYPE_TO_NATIVE(x) TypeMap[x]
120 #define TYPE_FROM_NATIVE(y) osl_SocketTypeFromNative(y)
122 static DWORD OptionMap
[]= {
123 SO_DEBUG
, /* osl_Socket_OptionDebug */
124 SO_ACCEPTCONN
, /* osl_Socket_OptionAcceptConn */
125 SO_REUSEADDR
, /* osl_Socket_OptionReuseAddr */
126 SO_KEEPALIVE
, /* osl_Socket_OptionKeepAlive */
127 SO_DONTROUTE
, /* osl_Socket_OptionDontRoute */
128 SO_BROADCAST
, /* osl_Socket_OptionBroadcast */
129 SO_USELOOPBACK
, /* osl_Socket_OptionUseLoopback */
130 SO_LINGER
, /* osl_Socket_OptionLinger */
131 SO_OOBINLINE
, /* osl_Socket_OptionOOBinLine */
132 SO_SNDBUF
, /* osl_Socket_OptionSndBuf */
133 SO_RCVBUF
, /* osl_Socket_OptionRcvBuf */
134 SO_SNDLOWAT
, /* osl_Socket_OptionSndLowat */
135 SO_RCVLOWAT
, /* osl_Socket_OptionRcvLowat */
136 SO_SNDTIMEO
, /* osl_Socket_OptionSndTimeo */
137 SO_RCVTIMEO
, /* osl_Socket_OptionRcvTimeo */
138 SO_ERROR
, /* osl_Socket_OptionError */
139 SO_TYPE
, /* osl_Socket_OptionType */
140 TCP_NODELAY
, /* osl_Socket_OptionTcpNoDelay */
141 0 /* osl_Socket_OptionInvalid */
144 #define OPTION_TO_NATIVE(x) OptionMap[x]
146 static DWORD OptionLevelMap
[]= {
147 SOL_SOCKET
, /* osl_Socket_LevelSocket */
148 IPPROTO_TCP
, /* osl_Socket_LevelTcp */
149 0 /* osl_invalid_SocketLevel */
152 #define OPTION_LEVEL_TO_NATIVE(x) OptionLevelMap[x]
154 static DWORD SocketMsgFlagMap
[]= {
155 0, /* osl_Socket_MsgNormal */
156 MSG_OOB
, /* osl_Socket_MsgOOB */
157 MSG_PEEK
, /* osl_Socket_MsgPeek */
158 MSG_DONTROUTE
, /* osl_Socket_MsgDontRoute */
159 MSG_MAXIOVLEN
/* osl_Socket_MsgMaxIOVLen */
162 #define MSG_FLAG_TO_NATIVE(x) SocketMsgFlagMap[x]
164 static DWORD SocketDirection
[]= {
165 SD_RECEIVE
, /* osl_Socket_DirRead */
166 SD_SEND
, /* osl_Socket_DirWrite */
167 SD_BOTH
/* osl_Socket_DirReadwrite */
170 #define DIRECTION_TO_NATIVE(x) SocketDirection[x]
172 static int SocketError
[]= {
174 WSAENOTSOCK
, /* Socket operation on non-socket */
175 WSAEDESTADDRREQ
, /* Destination address required */
176 WSAEMSGSIZE
, /* Message too long */
177 WSAEPROTOTYPE
, /* Protocol wrong type for socket */
178 WSAENOPROTOOPT
, /* Protocol not available */
179 WSAEPROTONOSUPPORT
, /* Protocol not supported */
180 WSAESOCKTNOSUPPORT
, /* Socket type not supported */
181 WSAEOPNOTSUPP
, /* Operation not supported on socket */
182 WSAEPFNOSUPPORT
, /* Protocol family not supported */
183 WSAEAFNOSUPPORT
, /* Address family not supported by protocol family */
184 WSAEADDRINUSE
, /* Address already in use */
185 WSAEADDRNOTAVAIL
, /* Can't assign requested address */
186 WSAENETDOWN
, /* Network is down */
187 WSAENETUNREACH
, /* Network is unreachable */
188 WSAENETRESET
, /* Network dropped connection because of reset */
189 WSAECONNABORTED
, /* Software caused connection abort */
190 WSAECONNRESET
, /* Connection reset by peer */
191 WSAENOBUFS
, /* No buffer space available */
192 WSAEISCONN
, /* Socket is already connected */
193 WSAENOTCONN
, /* Socket is not connected */
194 WSAESHUTDOWN
, /* Can't send after socket shutdown */
195 WSAETOOMANYREFS
, /* Too many references: can't splice */
196 WSAETIMEDOUT
, /* Connection timed out */
197 WSAECONNREFUSED
, /* Connection refused */
198 WSAEHOSTDOWN
, /* Host is down */
199 WSAEHOSTUNREACH
, /* No route to host */
200 WSAEWOULDBLOCK
, /* call would block on non-blocking socket */
201 WSAEALREADY
, /* operation already in progress */
202 WSAEINPROGRESS
/* operation now in progress */
205 static oslSocketError
osl_SocketErrorFromNative(int nativeType
)
207 oslSocketError i
= oslSocketError(0);
209 while(i
!= osl_Socket_E_InvalidError
)
211 if(SocketError
[i
] == nativeType
)
214 i
= static_cast<oslSocketError
>( static_cast<int>(i
) + 1);
219 #define ERROR_FROM_NATIVE(y) osl_SocketErrorFromNative(y)
221 #if OSL_DEBUG_LEVEL > 0
222 static sal_uInt32 g_nSocketAddr
= 0;
230 SAL_WARN_IF( g_nSocketAddr
, "sal.osl", "sal_socket: " << g_nSocketAddr
<< " socket address instances leak" );
236 static LeakWarning socketWarning
;
239 static oslSocket
createSocketImpl(SOCKET Socket
)
241 oslSocket pSockImpl
= static_cast<oslSocket
>(rtl_allocateZeroMemory( sizeof(struct oslSocketImpl
)));
242 pSockImpl
->m_Socket
= Socket
;
243 pSockImpl
->m_nRefCount
= 1;
247 static void destroySocketImpl(oslSocketImpl
*pImpl
)
255 static oslSocketAddr
createSocketAddr( )
257 oslSocketAddr pAddr
= static_cast<oslSocketAddr
>(rtl_allocateZeroMemory( sizeof( struct oslSocketAddrImpl
)));
258 pAddr
->m_nRefCount
= 1;
259 #if OSL_DEBUG_LEVEL > 0
265 static oslSocketAddr
createSocketAddrWithFamily(
266 oslAddrFamily family
, sal_Int32 port
, sal_uInt32 nAddr
)
268 OSL_ASSERT( family
== osl_Socket_FamilyInet
);
270 oslSocketAddr pAddr
= createSocketAddr();
273 case osl_Socket_FamilyInet
:
275 struct sockaddr_in
* pInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
277 pInetAddr
->sin_family
= FAMILY_TO_NATIVE(osl_Socket_FamilyInet
);
278 pInetAddr
->sin_addr
.s_addr
= nAddr
;
279 pInetAddr
->sin_port
= static_cast<sal_uInt16
>(port
&0xffff);
283 pAddr
->m_sockaddr
.sa_family
= FAMILY_TO_NATIVE(family
);
288 static oslSocketAddr
createSocketAddFromSystem( struct sockaddr
*pSystemSockAddr
)
290 oslSocketAddr pAddr
= createSocketAddr();
291 memcpy( &(pAddr
->m_sockaddr
), pSystemSockAddr
, sizeof( sockaddr
) );
295 static void destroySocketAddr( oslSocketAddr addr
)
297 #if OSL_DEBUG_LEVEL > 0
303 oslSocketAddr SAL_CALL
osl_createEmptySocketAddr(oslAddrFamily Family
)
305 oslSocketAddr pAddr
= nullptr;
307 /* is it an internet-Addr? */
308 if (Family
== osl_Socket_FamilyInet
)
309 pAddr
= createSocketAddrWithFamily(Family
, 0 , htonl(INADDR_ANY
) );
311 pAddr
= createSocketAddrWithFamily( Family
, 0 , 0 );
316 /** @deprecated, to be removed */
317 oslSocketAddr SAL_CALL
osl_copySocketAddr(oslSocketAddr Addr
)
319 oslSocketAddr pCopy
= nullptr;
322 pCopy
= createSocketAddr();
325 memcpy(&(pCopy
->m_sockaddr
),&(Addr
->m_sockaddr
), sizeof(struct sockaddr
));
330 sal_Bool SAL_CALL
osl_isEqualSocketAddr(oslSocketAddr Addr1
, oslSocketAddr Addr2
)
334 struct sockaddr
* pAddr1
= &(Addr1
->m_sockaddr
);
335 struct sockaddr
* pAddr2
= &(Addr2
->m_sockaddr
);
340 if (pAddr1
->sa_family
== pAddr2
->sa_family
)
342 switch (pAddr1
->sa_family
)
346 struct sockaddr_in
* pInetAddr1
= reinterpret_cast<struct sockaddr_in
*>(pAddr1
);
347 struct sockaddr_in
* pInetAddr2
= reinterpret_cast<struct sockaddr_in
*>(pAddr2
);
349 if ((pInetAddr1
->sin_family
== pInetAddr2
->sin_family
) &&
350 (pInetAddr1
->sin_addr
.s_addr
== pInetAddr2
->sin_addr
.s_addr
) &&
351 (pInetAddr1
->sin_port
== pInetAddr2
->sin_port
))
358 return (memcmp(pAddr1
, pAddr2
, sizeof(struct sockaddr
)) == 0);
366 oslSocketAddr SAL_CALL
osl_createInetBroadcastAddr (
367 rtl_uString
*strDottedAddr
,
370 sal_uInt32 nAddr
= OSL_INADDR_NONE
;
372 if (strDottedAddr
&& strDottedAddr
->length
)
375 INT ret
= InetPtonW(AF_INET
, o3tl::toW(strDottedAddr
->buffer
), & addr
);
378 nAddr
= addr
.S_un
.S_addr
;
382 if (nAddr
!= OSL_INADDR_NONE
)
384 /* Limited broadcast */
385 nAddr
= ntohl(nAddr
);
386 if (IN_CLASSA(nAddr
))
388 nAddr
&= IN_CLASSA_NET
;
389 nAddr
|= IN_CLASSA_HOST
;
391 else if (IN_CLASSB(nAddr
))
393 nAddr
&= IN_CLASSB_NET
;
394 nAddr
|= IN_CLASSB_HOST
;
396 else if (IN_CLASSC(nAddr
))
398 nAddr
&= IN_CLASSC_NET
;
399 nAddr
|= IN_CLASSC_HOST
;
403 /* No broadcast in class D */
406 nAddr
= htonl(nAddr
);
409 oslSocketAddr pAddr
=
410 createSocketAddrWithFamily( osl_Socket_FamilyInet
, htons( static_cast<sal_uInt16
>(Port
)), nAddr
);
414 oslSocketAddr SAL_CALL
osl_createInetSocketAddr (
415 rtl_uString
*strDottedAddr
,
421 INT ret
= InetPtonW(AF_INET
, o3tl::toW(strDottedAddr
->buffer
), & addr
);
422 Addr
= ret
== 1 ? addr
.S_un
.S_addr
: OSL_INADDR_NONE
;
424 oslSocketAddr pAddr
= nullptr;
425 if(Addr
!= OSL_INADDR_NONE
)
427 pAddr
= createSocketAddrWithFamily( osl_Socket_FamilyInet
, htons( static_cast<sal_uInt16
>(Port
)), Addr
);
432 oslSocketResult SAL_CALL
osl_setAddrOfSocketAddr( oslSocketAddr pAddr
, sal_Sequence
*pByteSeq
)
435 OSL_ASSERT( pByteSeq
);
437 oslSocketResult res
= osl_Socket_Error
;
438 if( pAddr
&& pByteSeq
)
440 OSL_ASSERT( pAddr
->m_sockaddr
.sa_family
== FAMILY_TO_NATIVE( osl_Socket_FamilyInet
) );
441 OSL_ASSERT( pByteSeq
->nElements
== 4 );
442 struct sockaddr_in
* pSystemInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
443 memcpy( &(pSystemInetAddr
->sin_addr
) , pByteSeq
->elements
, 4 );
449 /** Returns the addr field in the struct sockaddr. ppByteSeq is in network byteorder. *ppByteSeq may
450 either be 0 or contain a constructed sal_Sequence.
452 oslSocketResult SAL_CALL
osl_getAddrOfSocketAddr( oslSocketAddr pAddr
, sal_Sequence
**ppByteSeq
)
455 OSL_ASSERT( ppByteSeq
);
457 oslSocketResult res
= osl_Socket_Error
;
458 if( pAddr
&& ppByteSeq
)
460 struct sockaddr_in
* pSystemInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
461 rtl_byte_sequence_constructFromArray( ppByteSeq
, reinterpret_cast<sal_Int8
*>(&pSystemInetAddr
->sin_addr
),4);
467 struct oslHostAddrImpl
{
468 rtl_uString
*pHostName
;
469 oslSocketAddr pSockAddr
;
472 oslHostAddr SAL_CALL
osl_createHostAddr (
473 rtl_uString
*strHostname
,
474 const oslSocketAddr pSocketAddr
)
477 rtl_uString
*cn
= nullptr;
479 if ((strHostname
== nullptr) || (strHostname
->length
== 0) || (pSocketAddr
== nullptr))
482 rtl_uString_newFromString( &cn
, strHostname
);
484 pAddr
= static_cast<oslHostAddr
>(malloc (sizeof (struct oslHostAddrImpl
)));
486 if (pAddr
== nullptr)
488 rtl_uString_release(cn
);
492 pAddr
->pHostName
= cn
;
493 pAddr
->pSockAddr
= osl_copySocketAddr( pSocketAddr
);
498 oslHostAddr SAL_CALL
osl_createHostAddrByName(rtl_uString
*strHostname
)
500 if ((strHostname
== nullptr) || (strHostname
->length
== 0))
503 PADDRINFOW pAddrInfo
= nullptr;
504 int ret
= GetAddrInfoW(
505 o3tl::toW(strHostname
->buffer
), nullptr, nullptr, & pAddrInfo
);
508 SAL_INFO("sal.osl", "GetAddrInfoW failed: " << WSAGetLastError());
512 oslHostAddr pRet
= nullptr;
513 for (PADDRINFOW pIter
= pAddrInfo
; pIter
; pIter
= pIter
->ai_next
)
515 if (AF_INET
== pIter
->ai_family
)
517 pRet
= static_cast<oslHostAddr
>(
518 rtl_allocateZeroMemory(sizeof(struct oslHostAddrImpl
)));
519 if (pIter
->ai_canonname
== nullptr) {
520 rtl_uString_new(&pRet
->pHostName
);
522 rtl_uString_newFromStr(&pRet
->pHostName
, o3tl::toU(pIter
->ai_canonname
));
524 pRet
->pSockAddr
= createSocketAddr();
525 memcpy(& pRet
->pSockAddr
->m_sockaddr
,
526 pIter
->ai_addr
, pIter
->ai_addrlen
);
527 break; // ignore other results
530 FreeAddrInfoW(pAddrInfo
);
534 oslHostAddr SAL_CALL
osl_createHostAddrByAddr(const oslSocketAddr pAddr
)
536 if (pAddr
== nullptr)
539 if (pAddr
->m_sockaddr
.sa_family
!= FAMILY_TO_NATIVE(osl_Socket_FamilyInet
))
542 const struct sockaddr_in
*sin
= reinterpret_cast<const struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
544 if (sin
->sin_addr
.s_addr
== htonl(INADDR_ANY
))
547 WCHAR buf
[NI_MAXHOST
];
548 int ret
= GetNameInfoW(
549 & pAddr
->m_sockaddr
, sizeof(struct sockaddr
),
554 SAL_INFO("sal.osl", "GetNameInfoW failed: " << WSAGetLastError());
558 oslHostAddr pRet
= static_cast<oslHostAddr
>(
559 rtl_allocateZeroMemory(sizeof(struct oslHostAddrImpl
)));
560 rtl_uString_newFromStr(&pRet
->pHostName
, o3tl::toU(buf
));
561 pRet
->pSockAddr
= createSocketAddr();
562 memcpy(& pRet
->pSockAddr
->m_sockaddr
,
563 & pAddr
->m_sockaddr
, sizeof(struct sockaddr
));
567 oslHostAddr SAL_CALL
osl_copyHostAddr(const oslHostAddr Addr
)
569 oslHostAddr pAddr
= Addr
;
572 return osl_createHostAddr (pAddr
->pHostName
, pAddr
->pSockAddr
);
577 void SAL_CALL
osl_getHostnameOfHostAddr(
578 const oslHostAddr pAddr
, rtl_uString
**strHostname
)
581 rtl_uString_assign (strHostname
, pAddr
->pHostName
);
583 rtl_uString_new (strHostname
);
586 oslSocketAddr SAL_CALL
osl_getSocketAddrOfHostAddr(const oslHostAddr pAddr
)
589 return pAddr
->pSockAddr
;
594 void SAL_CALL
osl_destroyHostAddr(oslHostAddr pAddr
)
598 if (pAddr
->pHostName
)
599 rtl_uString_release (pAddr
->pHostName
);
600 if (pAddr
->pSockAddr
)
601 osl_destroySocketAddr( pAddr
->pSockAddr
);
607 oslSocketResult SAL_CALL
osl_getLocalHostname (rtl_uString
**strLocalHostname
)
609 static auto const init
= []() -> std::pair
<oslSocketResult
, OUString
> {
610 sal_Unicode LocalHostname
[256] = {0};
613 if (gethostname(Host
, sizeof(Host
)) == 0)
616 if (rtl_convertStringToUString(
617 &u
.pData
, Host
, strlen(Host
), osl_getThreadTextEncoding(),
618 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
619 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
620 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
))
621 && o3tl::make_unsigned(u
.getLength()) < SAL_N_ELEMENTS(LocalHostname
))
623 memcpy(LocalHostname
, u
.getStr(), (u
.getLength() + 1) * sizeof (sal_Unicode
));
627 if (rtl_ustr_getLength(LocalHostname
) > 0)
629 return {osl_Socket_Ok
, OUString(LocalHostname
)};
632 return {osl_Socket_Error
, OUString()};
635 rtl_uString_assign (strLocalHostname
, init
.second
.pData
);
640 oslSocketAddr SAL_CALL
osl_resolveHostname(rtl_uString
* strHostname
)
642 oslHostAddr pAddr
= osl_createHostAddrByName (strHostname
);
645 oslSocketAddr SockAddr
= osl_copySocketAddr( pAddr
->pSockAddr
);
646 osl_destroyHostAddr(pAddr
);
652 sal_Int32 SAL_CALL
osl_getServicePort (
653 rtl_uString
* strServicename
,
654 rtl_uString
* strProtocol
)
658 rtl_String
*str_Servicename
=nullptr;
659 rtl_String
*str_Protocol
=nullptr;
663 rtl_uString_getStr(strServicename
),
664 rtl_uString_getLength(strServicename
),
665 RTL_TEXTENCODING_UTF8
, OUSTRING_TO_OSTRING_CVTFLAGS
);
668 rtl_uString_getStr(strProtocol
),
669 rtl_uString_getLength(strProtocol
),
670 RTL_TEXTENCODING_UTF8
, OUSTRING_TO_OSTRING_CVTFLAGS
);
673 rtl_string_getStr(str_Servicename
),
674 rtl_string_getStr(str_Protocol
));
676 rtl_string_release( str_Servicename
);
677 rtl_string_release( str_Protocol
);
680 return ntohs(ps
->s_port
);
682 return OSL_INVALID_PORT
;
685 void SAL_CALL
osl_destroySocketAddr(oslSocketAddr pAddr
)
687 destroySocketAddr( pAddr
);
690 oslAddrFamily SAL_CALL
osl_getFamilyOfSocketAddr(oslSocketAddr pAddr
)
693 return FAMILY_FROM_NATIVE(pAddr
->m_sockaddr
.sa_family
);
695 return osl_Socket_FamilyInvalid
;
698 sal_Int32 SAL_CALL
osl_getInetPortOfSocketAddr(oslSocketAddr pAddr
)
702 struct sockaddr_in
* pSystemInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
704 if (pSystemInetAddr
->sin_family
== FAMILY_TO_NATIVE(osl_Socket_FamilyInet
))
705 return ntohs(pSystemInetAddr
->sin_port
);
707 return OSL_INVALID_PORT
;
710 sal_Bool SAL_CALL
osl_setInetPortOfSocketAddr (
714 if (pAddr
== nullptr)
717 struct sockaddr_in
* pSystemInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
719 if (pSystemInetAddr
->sin_family
!= FAMILY_TO_NATIVE(osl_Socket_FamilyInet
))
722 pSystemInetAddr
->sin_port
= htons(static_cast<short>(Port
));
726 oslSocketResult SAL_CALL
osl_getHostnameOfSocketAddr (
728 rtl_uString
**strHostName
)
730 oslHostAddr pAddr
= osl_createHostAddrByAddr (Addr
);
734 rtl_uString_newFromString(strHostName
, pAddr
->pHostName
);
736 osl_destroyHostAddr(pAddr
);
738 return osl_Socket_Ok
;
741 return osl_Socket_Error
;
744 oslSocketResult SAL_CALL
osl_getDottedInetAddrOfSocketAddr (
746 rtl_uString
**strDottedInetAddr
)
748 if (pAddr
== nullptr)
749 return osl_Socket_Error
;
751 struct sockaddr_in
*pSystemInetAddr
= reinterpret_cast<struct sockaddr_in
*>(&pAddr
->m_sockaddr
);
752 if (pSystemInetAddr
->sin_family
!= FAMILY_TO_NATIVE(osl_Socket_FamilyInet
))
753 return osl_Socket_Error
;
755 *strDottedInetAddr
= nullptr;
756 WCHAR buf
[16]; // 16 for IPV4, 46 for IPV6
757 PCWSTR ret
= InetNtopW(
758 AF_INET
, & pSystemInetAddr
->sin_addr
,
759 buf
, SAL_N_ELEMENTS(buf
));
762 SAL_INFO("sal.osl", "InetNtopW failed: " << WSAGetLastError());
763 return osl_Socket_Error
;
765 rtl_uString_newFromStr(strDottedInetAddr
, o3tl::toU(ret
));
766 OSL_ASSERT(*strDottedInetAddr
!= nullptr);
768 return osl_Socket_Ok
;
771 oslSocket SAL_CALL
osl_createSocket(
772 oslAddrFamily Family
,
774 oslProtocol Protocol
)
777 oslSocket pSocket
= createSocketImpl(0);
779 if (pSocket
== nullptr)
783 pSocket
->m_Socket
= socket(FAMILY_TO_NATIVE(Family
),
784 TYPE_TO_NATIVE(Type
),
785 PROTOCOL_TO_NATIVE(Protocol
));
787 /* creation failed => free memory */
788 if(pSocket
->m_Socket
== OSL_INVALID_SOCKET
)
790 int nErrno
= WSAGetLastError();
791 SAL_WARN("sal.osl", "socket creation failed: (" << nErrno
<< "): " << WindowsErrorString(nErrno
));
793 destroySocketImpl(pSocket
);
798 pSocket
->m_Flags
= 0;
804 void SAL_CALL
osl_acquireSocket(oslSocket pSocket
)
806 osl_atomic_increment(&(pSocket
->m_nRefCount
));
809 void SAL_CALL
osl_releaseSocket(oslSocket pSocket
)
811 if (pSocket
&& osl_atomic_decrement(&(pSocket
->m_nRefCount
)) == 0)
813 osl_closeSocket(pSocket
);
814 destroySocketImpl(pSocket
);
818 void SAL_CALL
osl_closeSocket(oslSocket pSocket
)
820 /* socket already invalid */
825 closesocket(pSocket
->m_Socket
);
827 pSocket
->m_Socket
= OSL_INVALID_SOCKET
;
831 Note that I rely on the fact that oslSocketAddr and struct sockaddr
832 are the same! I don't like it very much but see no other easy way
833 to conceal the struct sockaddr from the eyes of the user.
835 oslSocketAddr SAL_CALL
osl_getLocalAddrOfSocket(oslSocket pSocket
)
837 struct sockaddr Addr
;
840 if (pSocket
== nullptr) /* ENOTSOCK */
843 AddrLen
= sizeof(struct sockaddr
);
845 if (getsockname(pSocket
->m_Socket
, &Addr
, &AddrLen
) == OSL_SOCKET_ERROR
)
848 oslSocketAddr pAddr
= createSocketAddFromSystem( &Addr
);
852 oslSocketAddr SAL_CALL
osl_getPeerAddrOfSocket(oslSocket pSocket
)
854 struct sockaddr Addr
;
857 if (pSocket
== nullptr) /* ENOTSOCK */
860 AddrLen
= sizeof(struct sockaddr
);
862 if (getpeername(pSocket
->m_Socket
, &Addr
, &AddrLen
) == OSL_SOCKET_ERROR
)
865 oslSocketAddr pAddr
= createSocketAddFromSystem( &Addr
);
869 sal_Bool SAL_CALL
osl_bindAddrToSocket ( oslSocket pSocket
, oslSocketAddr pAddr
)
873 if (pSocket
== nullptr) /* ENOTSOCK */
876 return (bind(pSocket
->m_Socket
,
877 &(pAddr
->m_sockaddr
),
878 sizeof(struct sockaddr
)) != OSL_SOCKET_ERROR
);
881 oslSocketResult SAL_CALL
osl_connectSocketTo (
884 const TimeValue
* pTimeout
)
887 if (pSocket
== nullptr) /* ENOTSOCK */
888 return osl_Socket_Error
;
890 if (pAddr
== nullptr) /* EDESTADDRREQ */
891 return osl_Socket_Error
;
893 if (pTimeout
== nullptr)
895 if(connect(pSocket
->m_Socket
,
896 &(pAddr
->m_sockaddr
),
897 sizeof(struct sockaddr
)) == OSL_SOCKET_ERROR
)
898 return osl_Socket_Error
;
900 return osl_Socket_Ok
;
908 oslSocketResult Result
= osl_Socket_Ok
;
910 if (pSocket
->m_Flags
& OSL_SOCKET_FLAGS_NONBLOCKING
)
912 if (connect(pSocket
->m_Socket
,
913 &(pAddr
->m_sockaddr
),
914 sizeof(struct sockaddr
)) == OSL_SOCKET_ERROR
)
916 switch (WSAGetLastError())
920 return osl_Socket_InProgress
;
923 return osl_Socket_Error
;
927 return osl_Socket_Ok
;
930 /* set socket temporarily to non-blocking */
932 OSL_VERIFY(ioctlsocket(
933 pSocket
->m_Socket
, FIONBIO
, &Param
) != OSL_SOCKET_ERROR
);
935 /* initiate connect */
936 if (connect(pSocket
->m_Socket
,
937 &(pAddr
->m_sockaddr
),
938 sizeof(struct sockaddr
)) != OSL_SOCKET_ERROR
)
940 /* immediate connection */
943 ioctlsocket(pSocket
->m_Socket
, FIONBIO
, &Param
);
945 return osl_Socket_Ok
;
949 error
= WSAGetLastError();
951 /* really an error or just delayed? */
952 if (error
!= WSAEWOULDBLOCK
&& error
!= WSAEINPROGRESS
)
955 ioctlsocket(pSocket
->m_Socket
, FIONBIO
, &Param
);
957 return osl_Socket_Error
;
961 /* prepare select set for socket */
963 FD_SET(pSocket
->m_Socket
, &fds
);
965 /* divide milliseconds into seconds and microseconds */
966 tv
.tv_sec
= pTimeout
->Seconds
;
967 tv
.tv_usec
= pTimeout
->Nanosec
/ 1000L;
970 error
= select(pSocket
->m_Socket
+1,
976 if (error
> 0) /* connected */
979 !FD_ISSET(pSocket
->m_Socket
, &fds
),
981 "osl_connectSocketTo(): select returned but socket not set");
983 Result
= osl_Socket_Ok
;
986 else if(error
< 0) /* error */
988 /* errno == EBADF: most probably interrupted by close() */
989 if(WSAGetLastError() == WSAEBADF
)
991 /* do not access pSockImpl because it is about to be or */
992 /* already destroyed */
993 return osl_Socket_Interrupted
;
996 Result
= osl_Socket_Error
;
1000 Result
= osl_Socket_TimedOut
;
1004 ioctlsocket(pSocket
->m_Socket
, FIONBIO
, &Param
);
1010 sal_Bool SAL_CALL
osl_listenOnSocket (
1012 sal_Int32 MaxPendingConnections
)
1014 if (pSocket
== nullptr) /* ENOTSOCK */
1017 return (listen(pSocket
->m_Socket
,
1018 MaxPendingConnections
== -1 ?
1020 MaxPendingConnections
) != OSL_SOCKET_ERROR
);
1023 oslSocket SAL_CALL
osl_acceptConnectionOnSocket (
1025 oslSocketAddr
* ppAddr
)
1027 if (pSocket
== nullptr) /* ENOTSOCK */
1035 osl_destroySocketAddr( *ppAddr
);
1038 int AddrLen
= sizeof(struct sockaddr
);
1040 /* user wants to know peer Addr */
1041 struct sockaddr Addr
;
1043 Connection
= accept(pSocket
->m_Socket
, &Addr
, &AddrLen
);
1044 OSL_ASSERT(AddrLen
== sizeof(struct sockaddr
));
1046 if(Connection
!= static_cast<SOCKET
>(OSL_SOCKET_ERROR
))
1047 *ppAddr
= createSocketAddFromSystem(&Addr
);
1053 /* user is not interested in peer-addr */
1054 Connection
= accept(pSocket
->m_Socket
, nullptr, nullptr);
1057 /* accept failed? */
1058 if(Connection
== static_cast<SOCKET
>(OSL_SOCKET_ERROR
))
1062 oslSocket pConnectionSocket
;
1063 pConnectionSocket
= createSocketImpl(Connection
);
1065 pConnectionSocket
->m_Flags
= 0;
1067 return pConnectionSocket
;
1070 sal_Int32 SAL_CALL
osl_receiveSocket (
1073 sal_uInt32 BytesToRead
,
1074 oslSocketMsgFlag Flag
)
1076 if (pSocket
== nullptr) /* ENOTSOCK */
1077 return osl_Socket_Error
;
1079 return recv(pSocket
->m_Socket
,
1080 static_cast<char*>(pBuffer
),
1082 MSG_FLAG_TO_NATIVE(Flag
));
1085 sal_Int32 SAL_CALL
osl_receiveFromSocket (
1087 oslSocketAddr SenderAddr
,
1089 sal_uInt32 BufferSize
,
1090 oslSocketMsgFlag Flag
)
1092 struct sockaddr
*pSystemSockAddr
= nullptr;
1096 AddrLen
= sizeof( struct sockaddr
);
1097 pSystemSockAddr
= &(SenderAddr
->m_sockaddr
);
1100 if (pSocket
== nullptr) /* ENOTSOCK */
1101 return osl_Socket_Error
;
1103 return recvfrom(pSocket
->m_Socket
,
1104 static_cast<char*>(pBuffer
),
1106 MSG_FLAG_TO_NATIVE(Flag
),
1111 sal_Int32 SAL_CALL
osl_sendSocket (
1113 const void* pBuffer
,
1114 sal_uInt32 BytesToSend
,
1115 oslSocketMsgFlag Flag
)
1117 if (pSocket
== nullptr) /* ENOTSOCK */
1118 return osl_Socket_Error
;
1120 return send(pSocket
->m_Socket
,
1121 static_cast<char const *>(pBuffer
),
1123 MSG_FLAG_TO_NATIVE(Flag
));
1126 sal_Int32 SAL_CALL
osl_sendToSocket (
1128 oslSocketAddr ReceiverAddr
,
1129 const void* pBuffer
,
1130 sal_uInt32 BytesToSend
,
1131 oslSocketMsgFlag Flag
)
1133 if (pSocket
== nullptr) /* ENOTSOCK */
1134 return osl_Socket_Error
;
1136 /* ReceiverAddr might be 0 when used on a connected socket. */
1137 /* Then sendto should behave like send. */
1139 struct sockaddr
*pSystemSockAddr
= nullptr;
1141 pSystemSockAddr
= &(ReceiverAddr
->m_sockaddr
);
1143 return sendto(pSocket
->m_Socket
,
1144 static_cast<char const *>(pBuffer
),
1146 MSG_FLAG_TO_NATIVE(Flag
),
1148 pSystemSockAddr
== nullptr ? 0 : sizeof(struct sockaddr
));
1151 sal_Int32 SAL_CALL
osl_readSocket( oslSocket pSocket
, void *pBuffer
, sal_Int32 n
)
1153 sal_uInt8
* Ptr
= static_cast<sal_uInt8
*>(pBuffer
);
1155 OSL_ASSERT( pSocket
);
1157 /* loop until all desired bytes were read or an error occurred */
1158 sal_uInt32 BytesRead
= 0;
1159 sal_uInt32 BytesToRead
= n
;
1160 while (BytesToRead
> 0)
1163 RetVal
= osl_receiveSocket(pSocket
,
1166 osl_Socket_MsgNormal
);
1168 /* error occurred? */
1174 BytesToRead
-= RetVal
;
1175 BytesRead
+= RetVal
;
1182 sal_Int32 SAL_CALL
osl_writeSocket( oslSocket pSocket
, const void *pBuffer
, sal_Int32 n
)
1184 OSL_ASSERT( pSocket
);
1186 /* loop until all desired bytes were send or an error occurred */
1187 sal_uInt32 BytesSend
= 0;
1188 sal_uInt32 BytesToSend
= n
;
1189 sal_uInt8
const *Ptr
= static_cast<sal_uInt8
const *>(pBuffer
);
1190 while (BytesToSend
> 0)
1194 RetVal
= osl_sendSocket( pSocket
,Ptr
,BytesToSend
,osl_Socket_MsgNormal
);
1196 /* error occurred? */
1202 BytesToSend
-= RetVal
;
1203 BytesSend
+= RetVal
;
1210 sal_Bool SAL_CALL
osl_isReceiveReady (
1212 const TimeValue
* pTimeout
)
1217 if (pSocket
== nullptr) /* ENOTSOCK */
1221 FD_SET(pSocket
->m_Socket
, &fds
);
1225 tv
.tv_sec
= pTimeout
->Seconds
;
1226 tv
.tv_usec
= pTimeout
->Nanosec
/ 1000L;
1229 return (select(pSocket
->m_Socket
+ 1, /* no of sockets to monitor */
1230 &fds
, /* check read operations */
1231 nullptr, /* check write ops */
1232 nullptr, /* check for OOB */
1233 pTimeout
? &tv
: nullptr)==1); /* use timeout? */
1236 /*****************************************************************************/
1237 /* osl_isSendReady */
1238 /*****************************************************************************/
1239 sal_Bool SAL_CALL
osl_isSendReady (
1241 const TimeValue
* pTimeout
)
1246 if (pSocket
== nullptr) /* ENOTSOCK */
1250 FD_SET(pSocket
->m_Socket
, &fds
);
1254 tv
.tv_sec
= pTimeout
->Seconds
;
1255 tv
.tv_usec
= pTimeout
->Nanosec
/ 1000L;
1258 return (select(pSocket
->m_Socket
+ 1, /* no of sockets to monitor */
1259 nullptr, /* check read operations */
1260 &fds
, /* check write ops */
1261 nullptr, /* check for OOB */
1262 pTimeout
? &tv
: nullptr)==1); /* use timeout? */
1265 sal_Bool SAL_CALL
osl_isExceptionPending (
1267 const TimeValue
* pTimeout
)
1272 if (pSocket
== nullptr) /* ENOTSOCK */
1276 FD_SET(pSocket
->m_Socket
, &fds
);
1280 tv
.tv_sec
= pTimeout
->Seconds
;
1281 tv
.tv_usec
= pTimeout
->Nanosec
/ 1000L;
1284 return (select(pSocket
->m_Socket
+ 1, /* no of sockets to monitor */
1285 nullptr, /* check read operations */
1286 nullptr, /* check write ops */
1287 &fds
, /* check for OOB */
1288 pTimeout
? &tv
: nullptr)==1); /* use timeout? */
1291 sal_Bool SAL_CALL
osl_shutdownSocket (
1293 oslSocketDirection Direction
)
1295 if (pSocket
== nullptr) /* ENOTSOCK */
1298 return (shutdown(pSocket
->m_Socket
, DIRECTION_TO_NATIVE(Direction
))==0);
1301 sal_Int32 SAL_CALL
osl_getSocketOption (
1303 oslSocketOptionLevel Level
,
1304 oslSocketOption Option
,
1306 sal_uInt32 BufferLen
)
1308 if (pSocket
== nullptr) /* ENOTSOCK */
1309 return osl_Socket_Error
;
1311 int len
= BufferLen
;
1312 if (getsockopt(pSocket
->m_Socket
,
1313 OPTION_LEVEL_TO_NATIVE(Level
),
1314 OPTION_TO_NATIVE(Option
),
1315 static_cast<char *>(pBuffer
),
1324 sal_Bool SAL_CALL
osl_setSocketOption (
1326 oslSocketOptionLevel Level
,
1327 oslSocketOption Option
,
1329 sal_uInt32 BufferLen
)
1331 if (pSocket
== nullptr) /* ENOTSOCK */
1334 return(setsockopt(pSocket
->m_Socket
,
1335 OPTION_LEVEL_TO_NATIVE(Level
),
1336 OPTION_TO_NATIVE(Option
),
1337 static_cast<char*>(pBuffer
),
1341 sal_Bool SAL_CALL
osl_enableNonBlockingMode ( oslSocket pSocket
, sal_Bool On
)
1343 unsigned long Param
= On
? 1 : 0;
1345 if (pSocket
== nullptr) /* ENOTSOCK */
1348 pSocket
->m_Flags
= Param
?
1349 (pSocket
->m_Flags
| OSL_SOCKET_FLAGS_NONBLOCKING
) :
1350 (pSocket
->m_Flags
& ~OSL_SOCKET_FLAGS_NONBLOCKING
) ;
1353 ioctlsocket(pSocket
->m_Socket
, FIONBIO
, &Param
) != OSL_SOCKET_ERROR
);
1356 sal_Bool SAL_CALL
osl_isNonBlockingMode(oslSocket pSocket
)
1358 if (pSocket
== nullptr) /* ENOTSOCK */
1361 return (pSocket
->m_Flags
& OSL_SOCKET_FLAGS_NONBLOCKING
) != 0;
1364 oslSocketType SAL_CALL
osl_getSocketType(oslSocket pSocket
)
1367 int TypeSize
= sizeof(Type
);
1369 if (pSocket
== nullptr) /* ENOTSOCK */
1370 return osl_Socket_TypeInvalid
;
1372 if(getsockopt(pSocket
->m_Socket
,
1373 OPTION_LEVEL_TO_NATIVE(osl_Socket_LevelSocket
),
1374 OPTION_TO_NATIVE(osl_Socket_OptionType
),
1375 reinterpret_cast<char *>(&Type
),
1379 return osl_Socket_TypeInvalid
;
1382 return TYPE_FROM_NATIVE(Type
);
1385 void SAL_CALL
osl_getLastSocketErrorDescription (
1386 oslSocket
/*Socket*/,
1387 rtl_uString
**strError
)
1391 switch(error
= WSAGetLastError())
1394 rtl_uString_newFromAscii (strError
, "WSAENOTSOCK, Socket operation on non-socket. A socket created in one process is used by another process.");
1397 case WSAEDESTADDRREQ
:
1398 rtl_uString_newFromAscii (strError
, "WSAEDESTADDRREQ, Destination Addr required");
1402 rtl_uString_newFromAscii (strError
, "WSAEMSGSIZE, Message too long");
1406 rtl_uString_newFromAscii (strError
, "WSAEPROTOTYPE, Protocol wrong type for socket");
1409 case WSAENOPROTOOPT
:
1410 rtl_uString_newFromAscii (strError
, "WSAENOPROTOOPT, Protocol not available");
1413 case WSAEPROTONOSUPPORT
:
1414 rtl_uString_newFromAscii (strError
, "WSAEPROTONOSUPPORT, Protocol not supported");
1417 case WSAESOCKTNOSUPPORT
:
1418 rtl_uString_newFromAscii (strError
, "WSAESOCKTNOSUPPORT, Socket type not supported");
1422 rtl_uString_newFromAscii (strError
, "WSAEOPNOTSUPP, Operation not supported on socket");
1425 case WSAEPFNOSUPPORT
:
1426 rtl_uString_newFromAscii (strError
, "WSAEPFNOSUPPORT, Protocol family not supported");
1429 case WSAEAFNOSUPPORT
:
1430 rtl_uString_newFromAscii (strError
, "WSEAFNOSUPPORT, Addr family not supported by protocol family");
1434 rtl_uString_newFromAscii (strError
, "WSAEADDRINUSE, Triggered by bind() because a process went down without closing a socket.");
1437 case WSAEADDRNOTAVAIL
:
1438 rtl_uString_newFromAscii (strError
, "WSAEADDRNOTAVAIL, Can't assign requested Addr");
1442 rtl_uString_newFromAscii (strError
, "WSAENETDOWN, Network is down");
1445 case WSAENETUNREACH
:
1446 rtl_uString_newFromAscii (strError
, "WSAENETUNREACH, Network is unreachable");
1450 rtl_uString_newFromAscii (strError
, "WSAENETRESET, Network dropped connection or reset");
1453 case WSAECONNABORTED
:
1454 rtl_uString_newFromAscii (strError
, "WSAECONNABORTED, Software caused connection abort");
1458 rtl_uString_newFromAscii (strError
, "WSAECONNRESET, Connection reset by peer");
1462 rtl_uString_newFromAscii (strError
, "WSAENOBUFS, No buffer space available.");
1466 rtl_uString_newFromAscii (strError
, "WSAEISCONN, Socket is already connected");
1470 rtl_uString_newFromAscii (strError
, "WSAENOTCONN, Socket is not connected");
1474 rtl_uString_newFromAscii (strError
, "WSAESHUTDOWN, Can't send after socket shutdown");
1478 rtl_uString_newFromAscii (strError
, "WSAETIMEDOUT, Connection timed out");
1481 case WSAECONNREFUSED
:
1482 rtl_uString_newFromAscii (strError
, "WSAECONNREFUSED, Connection refused");
1486 rtl_uString_newFromAscii (strError
, "WSAEHOSTDOWN, Networking subsystem not started");
1489 case WSAEHOSTUNREACH
:
1490 rtl_uString_newFromAscii (strError
, "WSAEHOSTUNREACH, No route to host");
1493 case WSAEWOULDBLOCK
:
1494 rtl_uString_newFromAscii (strError
, "WSAEWOULDBLOCK, Operation would block");
1497 case WSAEINPROGRESS
:
1498 rtl_uString_newFromAscii (strError
, "WSAEINPROGRESS, Operation now in progress");
1502 rtl_uString_newFromAscii (strError
, "WSAEALREADY, Operation already in progress");
1506 rtl_uString_newFromAscii (strError
, "WSAEALREADY, Operation was interrupted");
1510 rtl_uString_newFromAscii (strError
, "WSAEBADF, Bad file number");
1514 rtl_uString_newFromAscii (strError
, "WSAEACCES, Access is denied");
1518 rtl_uString_newFromAscii (strError
, "WSAEFAULT, Bad memory Addr");
1522 rtl_uString_newFromAscii (strError
, "WSAEINVAL, The socket has not been bound with bind() or is already connected");
1526 rtl_uString_newFromAscii (strError
, "WSAEMFILE, No more file descriptors are available");
1529 case WSAETOOMANYREFS
:
1530 rtl_uString_newFromAscii (strError
, "WSAETOOMANYREFS, Undocumented WinSock error");
1533 case WSAENAMETOOLONG
:
1534 rtl_uString_newFromAscii (strError
, "WSAENAMETOOLONG, Undocumented WinSock error");
1538 rtl_uString_newFromAscii (strError
, "WSAENOTEMPTY, Undocumented WinSock error");
1542 rtl_uString_newFromAscii (strError
, "WSAEPROCLIM, Undocumented WinSock error");
1546 rtl_uString_newFromAscii (strError
, "WSAEUSERS, Undocumented WinSock error");
1550 rtl_uString_newFromAscii (strError
, "WSAEDQUOT, Undocumented WinSock error");
1554 rtl_uString_newFromAscii (strError
, "WSAESTALE, Undocumented WinSock error");
1558 rtl_uString_newFromAscii (strError
, "WSAEREMOTE, Undocumented WinSock error");
1562 rtl_uString_newFromAscii (strError
, "WSAEDISCON, Circuit was gracefully terminated");
1565 case WSASYSNOTREADY
:
1566 rtl_uString_newFromAscii (strError
, "WSASYSNOTREADY, The underlying network subsystem is not ready for network communication");
1569 case WSAVERNOTSUPPORTED
:
1570 rtl_uString_newFromAscii (strError
, "WSAVERNOTSUPPORTED, The version of Windows Sockets API support requested is not provided by this particular Windows Sockets implementation");
1573 case WSANOTINITIALISED
:
1574 rtl_uString_newFromAscii (strError
, "WSANOTINITIALISED, WSAStartup() has not been called");
1577 case WSAHOST_NOT_FOUND
:
1578 rtl_uString_newFromAscii (strError
, "WSAHOST_NOT_FOUND, Authoritative answer host not found");
1582 rtl_uString_newFromAscii (strError
, "WSATRY_AGAIN, Non-authoritative answer host not found or SERVERFAIL");
1585 case WSANO_RECOVERY
:
1586 rtl_uString_newFromAscii (strError
, "WSANO_RECOVERY, Non recoverable errors, FORMERR, REFUSED, NOTIMP");
1590 rtl_uString_newFromAscii (strError
, "WSANO_DATA or WSANO_ADDRESS, Valid name, no data record of requested type");
1595 sal_Unicode message
[128];
1597 wsprintfW(o3tl::toW(message
), L
"Unknown WinSock Error Number %d", error
);
1598 rtl_uString_newFromStr (strError
, message
);
1606 oslSocketError SAL_CALL
osl_getLastSocketError(oslSocket
/*Socket*/)
1608 return ERROR_FROM_NATIVE(WSAGetLastError());
1611 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */