- The virtual netbios device driver is properly named vnbt.vxd, not
[wine/multimedia.git] / dlls / vnbt.vxd / vnbt.c
bloba4e5751864d0082ed054c50440f61ecd8d706fa7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "iphlpapi.h"
27 #include "winsock2.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 = (PFIXED_INFO)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 if (fixedInfo)
118 HeapFree(GetProcessHeap(), 0, fixedInfo);
120 size = 0;
121 error = GetAdaptersInfo(NULL, &size);
122 if (ERROR_BUFFER_OVERFLOW == error)
124 PIP_ADAPTER_INFO adapterInfo = HeapAlloc(GetProcessHeap(), 0, size);
126 error = GetAdaptersInfo(adapterInfo, &size);
127 if (NO_ERROR == error)
129 PIP_ADAPTER_INFO ptr = adapterInfo;
131 for (ptr = adapterInfo; ptr && info->numEntries <
132 MAX_NBT_ENTRIES; ptr = ptr->Next)
134 unsigned long addr;
136 addr = inet_addr(ptr->IpAddressList.IpAddress.String);
137 if (addr != 0 && addr != INADDR_NONE)
138 info->table[info->numEntries].ip = ntohl(addr);
139 addr = inet_addr(ptr->PrimaryWinsServer.IpAddress.String);
140 if (addr != 0 && addr != INADDR_NONE)
141 info->table[info->numEntries].winsPrimary = ntohl(addr);
142 addr = inet_addr(ptr->SecondaryWinsServer.IpAddress.String);
143 if (addr != 0 && addr != INADDR_NONE)
144 info->table[info->numEntries].winsSecondary = ntohl(addr);
145 info->numEntries++;
148 if (adapterInfo)
149 HeapFree(GetProcessHeap(), 0, adapterInfo);
152 break;
154 case 119:
155 /* nbtstat.exe uses this, but the return seems to be a bunch of
156 * pointers, so it's not so easy to reverse engineer. Fall through
157 * to unimplemented...
159 default:
160 FIXME( "Unimplemented control %ld for VxD device VNB\n",
161 dwIoControlCode );
162 error = ERROR_NOT_SUPPORTED;
163 break;
165 if (error)
166 SetLastError(error);
167 return error == NO_ERROR;