| 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 | //******************************************************************************
|
|---|
| 23 | // GetComputerName
|
|---|
| 24 | //
|
|---|
| 25 | // Retrieve the NetBIOS name of the computer
|
|---|
| 26 | //******************************************************************************
|
|---|
| 27 | BOOL WIN32API GetComputerNameA(LPSTR lpBuffer, LPDWORD nSize)
|
|---|
| 28 | {
|
|---|
| 29 | char szDefault[] = "NONAME";
|
|---|
| 30 | char * szHostname = getenv("HOSTNAME"); // This is wrong;
|
|---|
| 31 | // We should use NETBIOS computername
|
|---|
| 32 |
|
|---|
| 33 | if (!szHostname) // Hostname not set; assume a default
|
|---|
| 34 | szHostname = szDefault;
|
|---|
| 35 |
|
|---|
| 36 | *nSize = min(strlen(szHostname) + 1, *nSize); // Truncate name as reqd.
|
|---|
| 37 | // NB W95/98 would generate a
|
|---|
| 38 | // BUFFER_OVERFLOW error here
|
|---|
| 39 |
|
|---|
| 40 | if (lpBuffer)
|
|---|
| 41 | {
|
|---|
| 42 | strncpy(lpBuffer, szHostname, *nSize); // Copy back name.
|
|---|
| 43 | lpBuffer[*nSize - 1] = 0; // Ensure terminated.
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | dprintf(("KERNEL32: GetComputerNameA (Name: %.*s, nSize: %d)", *nSize, lpBuffer, *nSize));
|
|---|
| 47 |
|
|---|
| 48 | return TRUE;
|
|---|
| 49 | }
|
|---|
| 50 | //******************************************************************************
|
|---|
| 51 | //******************************************************************************
|
|---|
| 52 | BOOL WIN32API GetComputerNameW(LPWSTR name, LPDWORD size)
|
|---|
| 53 | {
|
|---|
| 54 | LPSTR nameA = NULL;
|
|---|
| 55 | BOOL ret;
|
|---|
| 56 |
|
|---|
| 57 | if (name) nameA=(LPSTR)malloc(2**size);
|
|---|
| 58 |
|
|---|
| 59 | ret = GetComputerNameA(nameA,size);
|
|---|
| 60 |
|
|---|
| 61 | if (ret) AsciiToUnicode(nameA,name);
|
|---|
| 62 |
|
|---|
| 63 | free(nameA);
|
|---|
| 64 |
|
|---|
| 65 | return ret;
|
|---|
| 66 | }
|
|---|
| 67 | //******************************************************************************
|
|---|
| 68 | //******************************************************************************
|
|---|