~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/wsock32/protocol.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * WSOCK32 specific functions
  3  *
  4  * Copyright (C) 2001 Stefan Leichter
  5  * Copyright (C) 2008 Hans Leidekker
  6  *
  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.
 11  *
 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.
 16  *
 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
 20  */
 21 
 22 #define USE_WS_PREFIX
 23 
 24 #include "config.h"
 25 
 26 #include <stdarg.h>
 27 #include <stdio.h>
 28 #include <string.h>
 29 
 30 #ifdef HAVE_ARPA_INET_H
 31 #include <arpa/inet.h>
 32 #endif
 33 #ifdef HAVE_NETDB_H
 34 #include <netdb.h>
 35 #endif
 36 
 37 #include "windef.h"
 38 #include "winbase.h"
 39 #include "winsock2.h"
 40 #include "nspapi.h"
 41 
 42 #include "wine/debug.h"
 43 #include "wine/unicode.h"
 44 
 45 WINE_DEFAULT_DEBUG_CHANNEL(winsock);
 46 
 47 /*****************************************************************************
 48  *          inet_network       [WSOCK32.1100]
 49  */
 50 UINT WINAPI WSOCK32_inet_network(const char *cp)
 51 {
 52 #ifdef HAVE_INET_NETWORK
 53     return inet_network(cp);
 54 #else
 55     return 0;
 56 #endif
 57 }
 58 
 59 /*****************************************************************************
 60  *          getnetbyname       [WSOCK32.1101]
 61  */
 62 struct netent * WINAPI WSOCK32_getnetbyname(const char *name)
 63 {
 64 #ifdef HAVE_GETNETBYNAME
 65     return getnetbyname(name);
 66 #else
 67     return NULL;
 68 #endif
 69 }
 70 
 71 static DWORD map_service(DWORD wsaflags)
 72 {
 73     DWORD flags = 0;
 74 
 75     if (wsaflags & XP1_CONNECTIONLESS)      flags |= XP_CONNECTIONLESS;
 76     if (wsaflags & XP1_GUARANTEED_DELIVERY) flags |= XP_GUARANTEED_DELIVERY;
 77     if (wsaflags & XP1_GUARANTEED_ORDER)    flags |= XP_GUARANTEED_ORDER;
 78     if (wsaflags & XP1_MESSAGE_ORIENTED)    flags |= XP_MESSAGE_ORIENTED;
 79     if (wsaflags & XP1_PSEUDO_STREAM)       flags |= XP_PSEUDO_STREAM;
 80     if (wsaflags & XP1_GRACEFUL_CLOSE)      flags |= XP_GRACEFUL_CLOSE;
 81     if (wsaflags & XP1_EXPEDITED_DATA)      flags |= XP_EXPEDITED_DATA;
 82     if (wsaflags & XP1_CONNECT_DATA)        flags |= XP_CONNECT_DATA;
 83     if (wsaflags & XP1_DISCONNECT_DATA)     flags |= XP_DISCONNECT_DATA;
 84     if (wsaflags & XP1_SUPPORT_BROADCAST)   flags |= XP_SUPPORTS_BROADCAST;
 85     if (wsaflags & XP1_SUPPORT_MULTIPOINT)  flags |= XP_SUPPORTS_MULTICAST;
 86     if (wsaflags & XP1_QOS_SUPPORTED)       flags |= XP_BANDWITH_ALLOCATION;
 87     if (wsaflags & XP1_PARTIAL_MESSAGE)     flags |= XP_FRAGMENTATION;
 88     return flags;
 89 }
 90 
 91 /*****************************************************************************
 92  *          EnumProtocolsA       [WSOCK32.1111]
 93  */
 94 INT WINAPI EnumProtocolsA(LPINT protocols, LPVOID buffer, LPDWORD buflen)
 95 {
 96     INT ret;
 97     DWORD size, string_size = WSAPROTOCOL_LEN + 1;
 98 
 99     TRACE("%p, %p, %p\n", protocols, buffer, buflen);
100 
101     if (!buflen) return SOCKET_ERROR;
102 
103     size = 0;
104     ret = WSAEnumProtocolsA(protocols, NULL, &size);
105 
106     if (ret == SOCKET_ERROR && WSAGetLastError() == WSAENOBUFS)
107     {
108         DWORD num_protocols = size / sizeof(WSAPROTOCOL_INFOA);
109         if (*buflen < num_protocols * (sizeof(PROTOCOL_INFOA) + string_size))
110         {
111             *buflen = num_protocols * (sizeof(PROTOCOL_INFOA) + string_size);
112             return SOCKET_ERROR;
113         }
114         if (buffer)
115         {
116             WSAPROTOCOL_INFOA *wsabuf;
117             PROTOCOL_INFOA *pi = buffer;
118             unsigned int i, string_offset;
119 
120             if (!(wsabuf = HeapAlloc(GetProcessHeap(), 0, size))) return SOCKET_ERROR;
121 
122             ret = WSAEnumProtocolsA(protocols, wsabuf, &size);
123             string_offset = ret * sizeof(PROTOCOL_INFOA);
124 
125             for (i = 0; i < ret; i++)
126             {
127                 pi[i].dwServiceFlags = map_service(wsabuf[i].dwServiceFlags1);
128                 pi[i].iAddressFamily = wsabuf[i].iAddressFamily;
129                 pi[i].iMaxSockAddr   = wsabuf[i].iMaxSockAddr;
130                 pi[i].iMinSockAddr   = wsabuf[i].iMinSockAddr;
131                 pi[i].iSocketType    = wsabuf[i].iSocketType;
132                 pi[i].iProtocol      = wsabuf[i].iProtocol;
133                 pi[i].dwMessageSize  = wsabuf[i].dwMessageSize;
134 
135                 memcpy((char *)buffer + string_offset, wsabuf[i].szProtocol, string_size);
136                 pi[i].lpProtocol = (char *)buffer + string_offset;
137                 string_offset += string_size;
138             }
139             HeapFree(GetProcessHeap(), 0, wsabuf);
140         }
141     }
142     return ret;
143 }
144 
145 /*****************************************************************************
146  *          EnumProtocolsW       [WSOCK32.1112]
147  */
148 INT WINAPI EnumProtocolsW(LPINT protocols, LPVOID buffer, LPDWORD buflen)
149 {
150     INT ret;
151     DWORD size, string_size = (WSAPROTOCOL_LEN + 1) * sizeof(WCHAR);
152 
153     TRACE("%p, %p, %p\n", protocols, buffer, buflen);
154 
155     if (!buflen) return SOCKET_ERROR;
156 
157     size = 0;
158     ret = WSAEnumProtocolsW(protocols, NULL, &size);
159 
160     if (ret == SOCKET_ERROR && WSAGetLastError() == WSAENOBUFS)
161     {
162         DWORD num_protocols = size / sizeof(WSAPROTOCOL_INFOW);
163         if (*buflen < num_protocols * (sizeof(PROTOCOL_INFOW) + string_size))
164         {
165             *buflen = num_protocols * (sizeof(PROTOCOL_INFOW) + string_size);
166             return SOCKET_ERROR;
167         }
168         if (buffer)
169         {
170             WSAPROTOCOL_INFOW *wsabuf;
171             PROTOCOL_INFOW *pi = buffer;
172             unsigned int i, string_offset;
173 
174             if (!(wsabuf = HeapAlloc(GetProcessHeap(), 0, size))) return SOCKET_ERROR;
175 
176             ret = WSAEnumProtocolsW(protocols, wsabuf, &size);
177             string_offset = ret * sizeof(PROTOCOL_INFOW);
178 
179             for (i = 0; i < ret; i++)
180             {
181                 pi[i].dwServiceFlags = map_service(wsabuf[i].dwServiceFlags1);
182                 pi[i].iAddressFamily = wsabuf[i].iAddressFamily;
183                 pi[i].iMaxSockAddr   = wsabuf[i].iMaxSockAddr;
184                 pi[i].iMinSockAddr   = wsabuf[i].iMinSockAddr;
185                 pi[i].iSocketType    = wsabuf[i].iSocketType;
186                 pi[i].iProtocol      = wsabuf[i].iProtocol;
187                 pi[i].dwMessageSize  = wsabuf[i].dwMessageSize;
188 
189                 memcpy((char *)buffer + string_offset, wsabuf[i].szProtocol, string_size);
190                 pi[i].lpProtocol = (WCHAR *)(char *)buffer + string_offset;
191                 string_offset += string_size;
192             }
193             HeapFree(GetProcessHeap(), 0, wsabuf);
194         }
195     }
196     return ret;
197 }
198 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.