ReactOS 0.4.15-dev-5667-ged97270
getproto.c File Reference
#include <ws2_32.h>
#include <debug.h>
Include dependency graph for getproto.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HANDLE WSAAPI GetProtoOpenNetworkDatabase (PCHAR Name)
 
PCHAR WSAAPI GetProtoPatternMatch (IN PCHAR Buffer, IN PCHAR Lookup)
 
PPROTOENT WSAAPI GetProtoGetNextEnt (IN HANDLE DbHandle, IN PWSPROTO_BUFFER Buffer)
 
LPPROTOENT WSAAPI getprotobynumber (IN INT number)
 
LPPROTOENT WSAAPI getprotobyname (IN CONST CHAR FAR *name)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file getproto.c.

Function Documentation

◆ getprotobyname()

LPPROTOENT WSAAPI getprotobyname ( IN CONST CHAR FAR name)

Definition at line 305 of file getproto.c.

306{
310 PPROTOENT Protoent;
311 PVOID GetProtoBuffer;
312 HANDLE DbHandle;
313 DPRINT("getprotobyname: %s\n", name);
314
315 /* Enter prolog */
317 {
318 /* Leave now */
320 return NULL;
321 }
322
323 /* Get our buffer */
324 GetProtoBuffer = WsThreadGetProtoBuffer(Thread);
325 if (!GetProtoBuffer)
326 {
327 /* Fail */
329 return NULL;
330 }
331
332 /* Open the network database */
333 DbHandle = GetProtoOpenNetworkDatabase("protocol");
334 if (DbHandle == INVALID_HANDLE_VALUE)
335 {
336 /* Couldn't open the DB; fail */
338 return NULL;
339 }
340
341 /* Start the scan loop */
342 while (TRUE)
343 {
344 /* Get a protoent entry */
345 Protoent = GetProtoGetNextEnt(DbHandle, GetProtoBuffer);
346
347 /* Break if we didn't get any new one */
348 if (!Protoent) break;
349
350 /* Break if we have a match */
351 if (!_stricmp(Protoent->p_name, name)) break;
352 }
353
354 /* Close the network database */
355 CloseHandle(DbHandle);
356
357 /* Set error if we don't have a protoent */
358 if (!Protoent) SetLastError(WSANO_DATA);
359
360 /* Return it */
361 return Protoent;
362}
#define _stricmp
Definition: cat.c:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
PPROTOENT WSAAPI GetProtoGetNextEnt(IN HANDLE DbHandle, IN PWSPROTO_BUFFER Buffer)
Definition: getproto.c:132
HANDLE WSAAPI GetProtoOpenNetworkDatabase(PCHAR Name)
Definition: getproto.c:20
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define DPRINT
Definition: sndvol32.h:71
Definition: name.c:39
char * p_name
Definition: winsock.h:171
int32_t INT
Definition: typedefs.h:58
#define WSANO_DATA
Definition: winerror.h:2003
PWSPROTO_BUFFER WSAAPI WsThreadGetProtoBuffer(IN PWSTHREAD Thread)
Definition: dthread.c:120
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91

Referenced by adns__tcp_tryconnect(), init_finish(), and WsAsyncGetProto().

◆ getprotobynumber()

LPPROTOENT WSAAPI getprotobynumber ( IN INT  number)

Definition at line 241 of file getproto.c.

242{
246 PPROTOENT Protoent;
247 PVOID GetProtoBuffer;
248 HANDLE DbHandle;
249 DPRINT("getprotobynumber: %lx\n", number);
250
251 /* Enter prolog */
253 {
254 /* Leave now */
256 return NULL;
257 }
258
259 /* Get our buffer */
260 GetProtoBuffer = WsThreadGetProtoBuffer(Thread);
261 if (!GetProtoBuffer)
262 {
263 /* Fail */
265 return NULL;
266 }
267
268 /* Open the network database */
269 DbHandle = GetProtoOpenNetworkDatabase("protocol");
270 if (DbHandle == INVALID_HANDLE_VALUE)
271 {
272 /* Couldn't open the DB; fail */
274 return NULL;
275 }
276
277 /* Start the scan loop */
278 while (TRUE)
279 {
280 /* Get a protoent entry */
281 Protoent = GetProtoGetNextEnt(DbHandle, GetProtoBuffer);
282
283 /* Break if we didn't get any new one */
284 if (!Protoent) break;
285
286 /* Break if we have a match */
287 if (Protoent->p_proto == number) break;
288 }
289
290 /* Close the network database */
291 CloseHandle(DbHandle);
292
293 /* Set error if we don't have a protoent */
294 if (!Protoent) SetLastError(WSANO_DATA);
295
296 /* Return it */
297 return Protoent;
298}
static unsigned int number
Definition: dsound.c:1479
short p_proto
Definition: winsock.h:173

Referenced by WsAsyncGetProto().

◆ GetProtoGetNextEnt()

PPROTOENT WSAAPI GetProtoGetNextEnt ( IN HANDLE  DbHandle,
IN PWSPROTO_BUFFER  Buffer 
)

Definition at line 132 of file getproto.c.

134{
135 DWORD Read;
136 LONG n;
137 PCHAR p, p1, Entry, *Aliases;
138 PPROTOENT ReturnedProtoent;
139
140 /* Find out where we currently are in the file */
141 n = SetFilePointer(DbHandle, 0, 0, FILE_CURRENT);
142
143 while (TRUE)
144 {
145 /* Read 512 bytes */
146 if (!ReadFile(DbHandle,
147 Buffer->LineBuffer,
148 sizeof(Buffer->LineBuffer) - 1,
149 &Read,
150 NULL)) return NULL;
151
152 /* Find out where the line ends */
153 p1 = Buffer->LineBuffer;
154 Buffer->LineBuffer[Read] = ANSI_NULL;
155 p = strchr(Buffer->LineBuffer, '\n');
156
157 /* Bail out if the file is parsed */
158 if (!p) return NULL;
159
160 /* Calculate our new position */
161 n += (LONG)(p - p1) + 1;
162
163 /* Make it so we read from there next time */
164 SetFilePointer(DbHandle, n, 0, FILE_BEGIN);
165
166 /* Null-terminate the buffer so it only contains this line */
167 *p = ANSI_NULL;
168
169 /* If this line is a comment, skip it */
170 if (*p1 == '#') continue;
171
172 /* Get the entry in this line and null-terminate it */
173 Entry = GetProtoPatternMatch(p1, "#\n");
174 if (!Entry) continue;
175 *Entry = ANSI_NULL;
176
177 /* Start with the name */
178 Buffer->Protoent.p_name = p1;
179
180 /* Get the first tab and null-terminate */
181 Entry = GetProtoPatternMatch(p1, " \t");
182 if (!Entry) continue;
183 *Entry++ = ANSI_NULL;
184
185 /* Handle remaining tabs or spaces */
186 while (*Entry == ' ' || *Entry == '\t') Entry++;
187
188 /* Now move our read pointer */
189 p1 = GetProtoPatternMatch(Entry, " \t");
190 if (p1) *p1++ = ANSI_NULL;
191
192 /* This is where the address is */
193 Buffer->Protoent.p_proto = (short)atoi(Entry);
194
195 /* Setup the alias buffer */
196 Buffer->Protoent.p_aliases = Buffer->Aliases;
197 Aliases = Buffer->Protoent.p_aliases;
198
199 /* Check if the pointer is stil valid */
200 if (p1)
201 {
202 /* The first entry is here */
203 Entry = p1;
204
205 /* Loop while there are non-null entries */
206 while (Entry && *Entry)
207 {
208 /* Handle tabs and spaces */
209 while (*Entry == ' ' || *Entry == '\t') Entry++;
210
211 /* Make sure we don't go over the buffer */
212 if (Aliases < &Buffer->Protoent.p_aliases[MAXALIASES - 1])
213 {
214 /* Write the alias */
215 *Aliases++ = Entry;
216 }
217
218 /* Get to the next entry */
220 if (Entry) *Entry++ = ANSI_NULL;
221 }
222 }
223
224 /* Terminate the list */
225 *Aliases = NULL;
226
227 /* Return to caller */
228 ReturnedProtoent = &Buffer->Protoent;
229 break;
230 }
231
232 /* Return whatever we got */
233 return ReturnedProtoent;
234}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
Definition: bufpool.h:45
#define FILE_BEGIN
Definition: compat.h:761
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PCHAR WSAAPI GetProtoPatternMatch(IN PCHAR Buffer, IN PCHAR Lookup)
Definition: getproto.c:111
#define MAXALIASES
Definition: getrpcent.c:58
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define ANSI_NULL
long LONG
Definition: pedump.c:60
_In_ BOOLEAN Read
Definition: strmini.h:479
base of all file and directory entries
Definition: entries.h:83
char * PCHAR
Definition: typedefs.h:51
#define FILE_CURRENT
Definition: winbase.h:113

Referenced by getprotobyname(), and getprotobynumber().

◆ GetProtoOpenNetworkDatabase()

HANDLE WSAAPI GetProtoOpenNetworkDatabase ( PCHAR  Name)

Definition at line 20 of file getproto.c.

21{
22 PCHAR ExpandedPath;
25 HKEY DatabaseKey;
26 DWORD RegType;
27 DWORD RegSize = 0;
28 HANDLE ret;
29
30 ExpandedPath = HeapAlloc(WsSockHeap, 0, MAX_PATH);
31 if (!ExpandedPath)
33
34 /* Open the database path key */
36 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
37 0,
39 &DatabaseKey);
40 if (ErrorCode == NO_ERROR)
41 {
42 /* Read the actual path */
43 ErrorCode = RegQueryValueEx(DatabaseKey,
44 "DatabasePath",
45 NULL,
46 &RegType,
47 NULL,
48 &RegSize);
49
50 DatabasePath = HeapAlloc(WsSockHeap, 0, RegSize);
51 if (!DatabasePath)
52 {
53 HeapFree(WsSockHeap, 0, ExpandedPath);
55 }
56
57 /* Read the actual path */
58 ErrorCode = RegQueryValueEx(DatabaseKey,
59 "DatabasePath",
60 NULL,
61 &RegType,
63 &RegSize);
64
65
66 /* Close the key */
67 RegCloseKey(DatabaseKey);
68
69 /* Expand the name */
71
73 }
74 else
75 {
76 /* Use default path */
77 GetSystemDirectory(ExpandedPath, MAX_PATH);
78 if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\')
79 {
80 /* It isn't, so add it ourselves */
81 strncat(ExpandedPath, "\\", MAX_PATH);
82 }
83 strncat(ExpandedPath, "DRIVERS\\ETC\\", MAX_PATH);
84 }
85
86 /* Make sure that the path is backslash-terminated */
87 if (ExpandedPath[strlen(ExpandedPath) - 1] != '\\')
88 {
89 /* It isn't, so add it ourselves */
90 strncat(ExpandedPath, "\\", MAX_PATH);
91 }
92
93 /* Add the database name */
94 strncat(ExpandedPath, Name, MAX_PATH);
95
96 /* Return a handle to the file */
97 ret = CreateFile(ExpandedPath,
99 0,
100 NULL,
103 NULL);
104
105 HeapFree(WsSockHeap, 0, ExpandedPath);
106 return ret;
107}
char * strncat(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:605
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define RegCloseKey(hKey)
Definition: registry.h:47
#define NO_ERROR
Definition: dderror.h:5
#define OPEN_EXISTING
Definition: compat.h:775
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
PWSTR DatabasePath
Definition: database.c:31
#define KEY_READ
Definition: nt_native.h:1023
#define FILE_READ_ACCESS
Definition: nt_native.h:610
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
#define GetSystemDirectory
Definition: winbase.h:3713
#define ExpandEnvironmentStrings
Definition: winbase.h:3645
#define CreateFile
Definition: winbase.h:3620
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
HANDLE WsSockHeap
Definition: dllmain.c:21

Referenced by getprotobyname(), and getprotobynumber().

◆ GetProtoPatternMatch()

PCHAR WSAAPI GetProtoPatternMatch ( IN PCHAR  Buffer,
IN PCHAR  Lookup 
)

Definition at line 111 of file getproto.c.

113{
114 CHAR ScanChar;
115
116 /* Loop as long as we have data */
117 while ((ScanChar = *Buffer))
118 {
119 /* Check for a match and return its pointer if found */
120 if (strchr(Lookup, ScanChar)) return Buffer;
121
122 /* Keep going */
123 Buffer++;
124 }
125
126 /* Nothing found */
127 return NULL;
128}
static void Lookup(RTF_Info *, char *)
Definition: reader.c:2228
char CHAR
Definition: xmlstorage.h:175

Referenced by GetProtoGetNextEnt().