urlmon/tests: Make use of todo_wine_if().
[wine.git] / dlls / vnbt.vxd / vnbt.c
blob17f7d969d7b74a8f16fee670b35fe9e9cecb8123
1 /*
2 * VNBT VxD implementation
4 * Copyright 2003 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winsock2.h"
27 #include "iphlpapi.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(vxd);
32 #ifndef INADDR_NONE
33 #define INADDR_NONE ~0UL
34 #endif
36 typedef struct _nbtInfo
38 DWORD ip;
39 DWORD winsPrimary;
40 DWORD winsSecondary;
41 DWORD dnsPrimary;
42 DWORD dnsSecondary;
43 DWORD unk0;
44 } nbtInfo;
46 #define MAX_NBT_ENTRIES 7
48 typedef struct _nbtTable
50 DWORD numEntries;
51 nbtInfo table[MAX_NBT_ENTRIES];
52 UCHAR pad[6];
53 WORD nodeType;
54 WORD scopeLen;
55 char scope[254];
56 } nbtTable;
59 /***********************************************************************
60 * DeviceIoControl (VNB.VXD.@)
62 BOOL WINAPI VNBT_DeviceIoControl(DWORD dwIoControlCode,
63 LPVOID lpvInBuffer, DWORD cbInBuffer,
64 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
65 LPDWORD lpcbBytesReturned,
66 LPOVERLAPPED lpOverlapped)
68 DWORD error;
70 switch (dwIoControlCode)
72 case 116:
73 if (lpcbBytesReturned)
74 *lpcbBytesReturned = sizeof(nbtTable);
75 if (!lpvOutBuffer || cbOutBuffer < sizeof(nbtTable))
76 error = ERROR_BUFFER_OVERFLOW;
77 else
79 nbtTable *info = (nbtTable *)lpvOutBuffer;
80 DWORD size = 0;
82 memset(info, 0, sizeof(nbtTable));
84 error = GetNetworkParams(NULL, &size);
85 if (ERROR_BUFFER_OVERFLOW == error)
87 PFIXED_INFO fixedInfo = HeapAlloc( GetProcessHeap(), 0, size);
89 error = GetNetworkParams(fixedInfo, &size);
90 if (NO_ERROR == error)
92 info->nodeType = (WORD)fixedInfo->NodeType;
93 info->scopeLen = min(strlen(fixedInfo->ScopeId) + 1,
94 sizeof(info->scope) - 2);
95 memcpy(info->scope + 1, fixedInfo->ScopeId,
96 info->scopeLen);
97 info->scope[info->scopeLen + 1] = '\0';
99 /* convert into L2-encoded version */
100 char *ptr, *lenPtr;
102 for (ptr = info->scope + 1; *ptr &&
103 ptr - info->scope < sizeof(info->scope); )
105 for (lenPtr = ptr - 1, *lenPtr = 0;
106 *ptr && *ptr != '.' &&
107 ptr - info->scope < sizeof(info->scope);
108 ptr++)
109 *lenPtr += 1;
110 ptr++;
113 /* could set DNS servers here too, but since
114 * ipconfig.exe and winipcfg.exe read these from the
115 * registry, there's no point */
117 HeapFree(GetProcessHeap(), 0, fixedInfo);
119 size = 0;
120 error = GetAdaptersInfo(NULL, &size);
121 if (ERROR_BUFFER_OVERFLOW == error)
123 PIP_ADAPTER_INFO adapterInfo = HeapAlloc(GetProcessHeap(), 0, size);
125 error = GetAdaptersInfo(adapterInfo, &size);
126 if (NO_ERROR == error)
128 PIP_ADAPTER_INFO ptr;
130 for (ptr = adapterInfo; ptr && info->numEntries <
131 MAX_NBT_ENTRIES; ptr = ptr->Next)
133 unsigned long addr;
135 addr = inet_addr(ptr->IpAddressList.IpAddress.String);
136 if (addr != 0 && addr != INADDR_NONE)
137 info->table[info->numEntries].ip = ntohl(addr);
138 addr = inet_addr(ptr->PrimaryWinsServer.IpAddress.String);
139 if (addr != 0 && addr != INADDR_NONE)
140 info->table[info->numEntries].winsPrimary = ntohl(addr);
141 addr = inet_addr(ptr->SecondaryWinsServer.IpAddress.String);
142 if (addr != 0 && addr != INADDR_NONE)
143 info->table[info->numEntries].winsSecondary = ntohl(addr);
144 info->numEntries++;
147 HeapFree(GetProcessHeap(), 0, adapterInfo);
150 break;
152 case 119:
153 /* nbtstat.exe uses this, but the return seems to be a bunch of
154 * pointers, so it's not so easy to reverse engineer. Fall through
155 * to unimplemented...
157 default:
158 FIXME( "Unimplemented control %d for VxD device VNB\n",
159 dwIoControlCode );
160 error = ERROR_NOT_SUPPORTED;
161 break;
163 if (error)
164 SetLastError(error);
165 return error == NO_ERROR;