1 | /* $Id: network.cpp,v 1.11 2001-12-10 11:28:59 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Network apis
|
---|
4 | *
|
---|
5 | * Copyright 1998 Peter Fitzsimmons
|
---|
6 | * 1999 Przemyslaw Dobrowolski
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | */
|
---|
10 | #define INCL_DOSEXCEPTIONS
|
---|
11 | #define INCL_DOSMEMMGR
|
---|
12 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
13 | #include <stdlib.h>
|
---|
14 | #include <stdio.h>
|
---|
15 | #include <string.h>
|
---|
16 | #include "misc.h"
|
---|
17 | #include "unicode.h"
|
---|
18 |
|
---|
19 | #define DBG_LOCALLOG DBG_network
|
---|
20 | #include "dbglocal.h"
|
---|
21 |
|
---|
22 | extern "C" {
|
---|
23 |
|
---|
24 | //******************************************************************************
|
---|
25 | // GetComputerName
|
---|
26 | //
|
---|
27 | // Retrieve the NetBIOS name of the computer
|
---|
28 | //******************************************************************************
|
---|
29 | BOOL WIN32API GetComputerNameA(LPSTR lpBuffer, LPDWORD nSize)
|
---|
30 | {
|
---|
31 | char szDefault[] = "NONAME";
|
---|
32 | char * szHostname = getenv("HOSTNAME"); // This is wrong;
|
---|
33 | // We should use NETBIOS computername
|
---|
34 |
|
---|
35 | if (!szHostname) // Hostname not set; assume a default
|
---|
36 | szHostname = szDefault;
|
---|
37 |
|
---|
38 | *nSize = min(strlen(szHostname) + 1, *nSize); // Truncate name as reqd.
|
---|
39 | // NB W95/98 would generate a
|
---|
40 | // BUFFER_OVERFLOW error here
|
---|
41 |
|
---|
42 | if (lpBuffer)
|
---|
43 | {
|
---|
44 | strncpy(lpBuffer, szHostname, *nSize); // Copy back name.
|
---|
45 | lpBuffer[*nSize - 1] = 0; // Ensure terminated.
|
---|
46 | }
|
---|
47 |
|
---|
48 | dprintf(("KERNEL32: GetComputerNameA (Name: %.*s, nSize: %d)", *nSize, lpBuffer, *nSize));
|
---|
49 |
|
---|
50 | return TRUE;
|
---|
51 | }
|
---|
52 | //******************************************************************************
|
---|
53 | //******************************************************************************
|
---|
54 | BOOL WIN32API GetComputerNameW(LPWSTR name, LPDWORD size)
|
---|
55 | {
|
---|
56 | LPSTR nameA = NULL;
|
---|
57 | BOOL ret;
|
---|
58 |
|
---|
59 | if (name) nameA=(LPSTR)malloc(2**size);
|
---|
60 |
|
---|
61 | ret = GetComputerNameA(nameA,size);
|
---|
62 |
|
---|
63 | if (ret) AsciiToUnicode(nameA,name);
|
---|
64 |
|
---|
65 | free(nameA);
|
---|
66 |
|
---|
67 | return ret;
|
---|
68 | }
|
---|
69 | //******************************************************************************
|
---|
70 | //******************************************************************************
|
---|
71 |
|
---|
72 | } // extern "C"
|
---|