2 * WSOCK32 specific functions
4 * Copyright (C) 2001 Stefan Leichter
5 * Copyright (C) 2008 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(winsock
);
33 /*****************************************************************************
34 * inet_network [WSOCK32.1100]
36 UINT WINAPI
WSOCK32_inet_network(const char *cp
)
38 return ntohl( inet_addr( cp
) );
41 /*****************************************************************************
42 * getnetbyname [WSOCK32.1101]
44 struct netent
* WINAPI
WSOCK32_getnetbyname(const char *name
)
46 ERR( "%s: not supported\n", debugstr_a(name
) );
50 static DWORD
map_service(DWORD wsaflags
)
54 if (wsaflags
& XP1_CONNECTIONLESS
) flags
|= XP_CONNECTIONLESS
;
55 if (wsaflags
& XP1_GUARANTEED_DELIVERY
) flags
|= XP_GUARANTEED_DELIVERY
;
56 if (wsaflags
& XP1_GUARANTEED_ORDER
) flags
|= XP_GUARANTEED_ORDER
;
57 if (wsaflags
& XP1_MESSAGE_ORIENTED
) flags
|= XP_MESSAGE_ORIENTED
;
58 if (wsaflags
& XP1_PSEUDO_STREAM
) flags
|= XP_PSEUDO_STREAM
;
59 if (wsaflags
& XP1_GRACEFUL_CLOSE
) flags
|= XP_GRACEFUL_CLOSE
;
60 if (wsaflags
& XP1_EXPEDITED_DATA
) flags
|= XP_EXPEDITED_DATA
;
61 if (wsaflags
& XP1_CONNECT_DATA
) flags
|= XP_CONNECT_DATA
;
62 if (wsaflags
& XP1_DISCONNECT_DATA
) flags
|= XP_DISCONNECT_DATA
;
63 if (wsaflags
& XP1_SUPPORT_BROADCAST
) flags
|= XP_SUPPORTS_BROADCAST
;
64 if (wsaflags
& XP1_SUPPORT_MULTIPOINT
) flags
|= XP_SUPPORTS_MULTICAST
;
65 if (wsaflags
& XP1_QOS_SUPPORTED
) flags
|= XP_BANDWIDTH_ALLOCATION
;
66 if (wsaflags
& XP1_PARTIAL_MESSAGE
) flags
|= XP_FRAGMENTATION
;
70 /*****************************************************************************
71 * EnumProtocolsA [WSOCK32.1111]
73 INT WINAPI
EnumProtocolsA(LPINT protocols
, LPVOID buffer
, LPDWORD buflen
)
76 DWORD size
, string_size
= WSAPROTOCOL_LEN
+ 1;
78 TRACE("%p, %p, %p\n", protocols
, buffer
, buflen
);
80 if (!buflen
) return SOCKET_ERROR
;
83 ret
= WSAEnumProtocolsA(protocols
, NULL
, &size
);
85 if (ret
== SOCKET_ERROR
&& WSAGetLastError() == WSAENOBUFS
)
87 DWORD num_protocols
= size
/ sizeof(WSAPROTOCOL_INFOA
);
88 if (*buflen
< num_protocols
* (sizeof(PROTOCOL_INFOA
) + string_size
))
90 *buflen
= num_protocols
* (sizeof(PROTOCOL_INFOA
) + string_size
);
95 WSAPROTOCOL_INFOA
*wsabuf
;
96 PROTOCOL_INFOA
*pi
= buffer
;
97 unsigned int string_offset
;
100 if (!(wsabuf
= HeapAlloc(GetProcessHeap(), 0, size
))) return SOCKET_ERROR
;
102 ret
= WSAEnumProtocolsA(protocols
, wsabuf
, &size
);
103 string_offset
= ret
* sizeof(PROTOCOL_INFOA
);
105 for (i
= 0; i
< ret
; i
++)
107 pi
[i
].dwServiceFlags
= map_service(wsabuf
[i
].dwServiceFlags1
);
108 pi
[i
].iAddressFamily
= wsabuf
[i
].iAddressFamily
;
109 pi
[i
].iMaxSockAddr
= wsabuf
[i
].iMaxSockAddr
;
110 pi
[i
].iMinSockAddr
= wsabuf
[i
].iMinSockAddr
;
111 pi
[i
].iSocketType
= wsabuf
[i
].iSocketType
;
112 pi
[i
].iProtocol
= wsabuf
[i
].iProtocol
;
113 pi
[i
].dwMessageSize
= wsabuf
[i
].dwMessageSize
;
115 memcpy((char *)buffer
+ string_offset
, wsabuf
[i
].szProtocol
, string_size
);
116 pi
[i
].lpProtocol
= (char *)buffer
+ string_offset
;
117 string_offset
+= string_size
;
119 HeapFree(GetProcessHeap(), 0, wsabuf
);
125 /*****************************************************************************
126 * EnumProtocolsW [WSOCK32.1112]
128 INT WINAPI
EnumProtocolsW(LPINT protocols
, LPVOID buffer
, LPDWORD buflen
)
131 DWORD size
, string_size
= (WSAPROTOCOL_LEN
+ 1) * sizeof(WCHAR
);
133 TRACE("%p, %p, %p\n", protocols
, buffer
, buflen
);
135 if (!buflen
) return SOCKET_ERROR
;
138 ret
= WSAEnumProtocolsW(protocols
, NULL
, &size
);
140 if (ret
== SOCKET_ERROR
&& WSAGetLastError() == WSAENOBUFS
)
142 DWORD num_protocols
= size
/ sizeof(WSAPROTOCOL_INFOW
);
143 if (*buflen
< num_protocols
* (sizeof(PROTOCOL_INFOW
) + string_size
))
145 *buflen
= num_protocols
* (sizeof(PROTOCOL_INFOW
) + string_size
);
150 WSAPROTOCOL_INFOW
*wsabuf
;
151 PROTOCOL_INFOW
*pi
= buffer
;
152 unsigned int string_offset
;
155 if (!(wsabuf
= HeapAlloc(GetProcessHeap(), 0, size
))) return SOCKET_ERROR
;
157 ret
= WSAEnumProtocolsW(protocols
, wsabuf
, &size
);
158 string_offset
= ret
* sizeof(PROTOCOL_INFOW
);
160 for (i
= 0; i
< ret
; i
++)
162 pi
[i
].dwServiceFlags
= map_service(wsabuf
[i
].dwServiceFlags1
);
163 pi
[i
].iAddressFamily
= wsabuf
[i
].iAddressFamily
;
164 pi
[i
].iMaxSockAddr
= wsabuf
[i
].iMaxSockAddr
;
165 pi
[i
].iMinSockAddr
= wsabuf
[i
].iMinSockAddr
;
166 pi
[i
].iSocketType
= wsabuf
[i
].iSocketType
;
167 pi
[i
].iProtocol
= wsabuf
[i
].iProtocol
;
168 pi
[i
].dwMessageSize
= wsabuf
[i
].dwMessageSize
;
170 memcpy((char *)buffer
+ string_offset
, wsabuf
[i
].szProtocol
, string_size
);
171 pi
[i
].lpProtocol
= (WCHAR
*)((char *)buffer
+ string_offset
);
172 string_offset
+= string_size
;
174 HeapFree(GetProcessHeap(), 0, wsabuf
);