wined3d: Remove the redundant "pow2_width" and "pow2_height" fields.
[wine.git] / dlls / dhcpcsvc / dhcpcsvc.c
blob37098610760e8fc30882b19614ba6f8df6208abf
1 /*
2 * Copyright 2011 Stefan Leichter
3 * Copyright 2019 Hans Leidekker for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "dhcpcsdk.h"
25 #include "winioctl.h"
26 #include "winternl.h"
27 #include "ws2def.h"
28 #include "ws2ipdef.h"
29 #include "iphlpapi.h"
30 #include "netioapi.h"
31 #define WINE_MOUNTMGR_EXTENSIONS
32 #include "ddk/mountmgr.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dhcpcsvc);
38 void WINAPI DhcpCApiCleanup(void)
40 FIXME(": stub\n");
43 DWORD WINAPI DhcpCApiInitialize(LPDWORD version)
45 *version = 2; /* 98, XP, and 8 */
46 FIXME(": stub\n");
47 return ERROR_SUCCESS;
50 static DWORD get_adapter_luid( const WCHAR *adapter, NET_LUID *luid )
52 UNICODE_STRING ustr;
53 NTSTATUS status;
54 GUID guid;
56 if (adapter[0] == '{')
58 RtlInitUnicodeString( &ustr, adapter );
59 status = RtlGUIDFromString( &ustr, &guid );
60 if (!status) return ConvertInterfaceGuidToLuid( &guid, luid );
62 return ConvertInterfaceNameToLuidW( adapter, luid );
65 #define IF_NAMESIZE 16
66 static DWORD get_adapter_name( const WCHAR *adapter, char *unix_name, DWORD len )
68 WCHAR unix_nameW[IF_NAMESIZE];
69 NET_LUID luid;
70 DWORD ret;
72 if ((ret = get_adapter_luid( adapter, &luid ))) return ret;
73 if ((ret = ConvertInterfaceLuidToAlias( &luid, unix_nameW, ARRAY_SIZE(unix_nameW) ))) return ret;
74 if (!WideCharToMultiByte( CP_UNIXCP, 0, unix_nameW, -1, unix_name, len, NULL, NULL ))
75 return ERROR_INVALID_PARAMETER;
76 return ERROR_SUCCESS;
79 DWORD WINAPI DhcpRequestParams( DWORD flags, void *reserved, WCHAR *adapter, DHCPCAPI_CLASSID *class_id,
80 DHCPCAPI_PARAMS_ARRAY send_params, DHCPCAPI_PARAMS_ARRAY recv_params, BYTE *buf,
81 DWORD *buflen, WCHAR *request_id )
83 struct mountmgr_dhcp_request_params *query;
84 DWORD i, size, err;
85 BYTE *src, *dst;
86 HANDLE mgr;
87 char unix_name[IF_NAMESIZE];
89 TRACE( "(%08lx, %p, %s, %p, %lu, %lu, %p, %p, %s)\n", flags, reserved, debugstr_w(adapter), class_id,
90 send_params.nParams, recv_params.nParams, buf, buflen, debugstr_w(request_id) );
92 if (!adapter || !buflen) return ERROR_INVALID_PARAMETER;
93 if (flags != DHCPCAPI_REQUEST_SYNCHRONOUS) FIXME( "unsupported flags %08lx\n", flags );
94 if ((err = get_adapter_name( adapter, unix_name, sizeof(unix_name) ))) return err;
96 for (i = 0; i < send_params.nParams; i++)
97 FIXME( "send option %lu not supported\n", send_params.Params->OptionId );
99 mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
100 OPEN_EXISTING, 0, 0 );
101 if (mgr == INVALID_HANDLE_VALUE) return GetLastError();
103 size = FIELD_OFFSET(struct mountmgr_dhcp_request_params, params[recv_params.nParams]) + *buflen;
104 if (!(query = calloc( 1, size )))
106 err = ERROR_OUTOFMEMORY;
107 goto done;
109 for (i = 0; i < recv_params.nParams; i++) query->params[i].id = recv_params.Params[i].OptionId;
110 query->count = recv_params.nParams;
111 strcpy( query->unix_name, unix_name );
113 if (!DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS, query, size, query, size, NULL, NULL ))
115 err = GetLastError();
116 if (err == ERROR_MORE_DATA) *buflen = query->size - (size - *buflen);
117 goto done;
120 dst = buf;
121 for (i = 0; i < query->count; i++)
123 if (buf)
125 recv_params.Params[i].OptionId = query->params[i].id;
126 recv_params.Params[i].IsVendor = FALSE; /* FIXME */
127 if (query->params[i].size)
129 src = (BYTE *)query + query->params[i].offset;
130 memcpy( dst, src, query->params[i].size );
132 recv_params.Params[i].Data = dst;
133 recv_params.Params[i].nBytesData = query->params[i].size;
135 else
137 recv_params.Params[i].Data = NULL;
138 recv_params.Params[i].nBytesData = 0;
141 dst += query->params[i].size;
144 *buflen = dst - buf;
145 err = ERROR_SUCCESS;
147 done:
148 free( query );
149 CloseHandle( mgr );
150 return err;