cmd: DIR command outputs free space for the path.
[wine.git] / dlls / vnbt.vxd / vnbt.c
blobea9b48f7f0681fa2b95fab2748ea70b85d4481bc
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 <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winsock2.h"
25 #include "iphlpapi.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(vxd);
30 typedef struct _nbtInfo
32 DWORD ip;
33 DWORD winsPrimary;
34 DWORD winsSecondary;
35 DWORD dnsPrimary;
36 DWORD dnsSecondary;
37 DWORD unk0;
38 } nbtInfo;
40 #define MAX_NBT_ENTRIES 7
42 typedef struct _nbtTable
44 DWORD numEntries;
45 nbtInfo table[MAX_NBT_ENTRIES];
46 UCHAR pad[6];
47 WORD nodeType;
48 WORD scopeLen;
49 char scope[254];
50 } nbtTable;
53 /***********************************************************************
54 * DeviceIoControl (VNB.VXD.@)
56 BOOL WINAPI VNBT_DeviceIoControl(DWORD dwIoControlCode,
57 LPVOID lpvInBuffer, DWORD cbInBuffer,
58 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
59 LPDWORD lpcbBytesReturned,
60 LPOVERLAPPED lpOverlapped)
62 DWORD error;
64 switch (dwIoControlCode)
66 case 116:
67 if (lpcbBytesReturned)
68 *lpcbBytesReturned = sizeof(nbtTable);
69 if (!lpvOutBuffer || cbOutBuffer < sizeof(nbtTable))
70 error = ERROR_BUFFER_OVERFLOW;
71 else
73 nbtTable *info = (nbtTable *)lpvOutBuffer;
74 DWORD size = 0;
76 memset(info, 0, sizeof(nbtTable));
78 error = GetNetworkParams(NULL, &size);
79 if (ERROR_BUFFER_OVERFLOW == error)
81 PFIXED_INFO fixedInfo = HeapAlloc( GetProcessHeap(), 0, size);
83 error = GetNetworkParams(fixedInfo, &size);
84 if (NO_ERROR == error)
86 info->nodeType = (WORD)fixedInfo->NodeType;
87 info->scopeLen = min(strlen(fixedInfo->ScopeId) + 1,
88 sizeof(info->scope) - 2);
89 memcpy(info->scope + 1, fixedInfo->ScopeId,
90 info->scopeLen);
91 info->scope[info->scopeLen + 1] = '\0';
93 /* convert into L2-encoded version */
94 char *ptr, *lenPtr;
96 for (ptr = info->scope + 1; *ptr &&
97 ptr - info->scope < sizeof(info->scope); )
99 for (lenPtr = ptr - 1, *lenPtr = 0;
100 *ptr && *ptr != '.' &&
101 ptr - info->scope < sizeof(info->scope);
102 ptr++)
103 *lenPtr += 1;
104 ptr++;
107 /* could set DNS servers here too, but since
108 * ipconfig.exe and winipcfg.exe read these from the
109 * registry, there's no point */
111 HeapFree(GetProcessHeap(), 0, fixedInfo);
113 size = 0;
114 error = GetAdaptersInfo(NULL, &size);
115 if (ERROR_BUFFER_OVERFLOW == error)
117 PIP_ADAPTER_INFO adapterInfo = HeapAlloc(GetProcessHeap(), 0, size);
119 error = GetAdaptersInfo(adapterInfo, &size);
120 if (NO_ERROR == error)
122 PIP_ADAPTER_INFO ptr;
124 for (ptr = adapterInfo; ptr && info->numEntries <
125 MAX_NBT_ENTRIES; ptr = ptr->Next)
127 unsigned long addr;
129 addr = inet_addr(ptr->IpAddressList.IpAddress.String);
130 if (addr != 0 && addr != INADDR_NONE)
131 info->table[info->numEntries].ip = ntohl(addr);
132 addr = inet_addr(ptr->PrimaryWinsServer.IpAddress.String);
133 if (addr != 0 && addr != INADDR_NONE)
134 info->table[info->numEntries].winsPrimary = ntohl(addr);
135 addr = inet_addr(ptr->SecondaryWinsServer.IpAddress.String);
136 if (addr != 0 && addr != INADDR_NONE)
137 info->table[info->numEntries].winsSecondary = ntohl(addr);
138 info->numEntries++;
141 HeapFree(GetProcessHeap(), 0, adapterInfo);
144 break;
146 case 119:
147 /* nbtstat.exe uses this, but the return seems to be a bunch of
148 * pointers, so it's not so easy to reverse engineer. Fall through
149 * to unimplemented...
151 default:
152 FIXME( "Unimplemented control %ld for VxD device VNB\n",
153 dwIoControlCode );
154 error = ERROR_NOT_SUPPORTED;
155 break;
157 if (error)
158 SetLastError(error);
159 return error == NO_ERROR;