Final network question. Honest.

BlitzPlus Forums/BlitzPlus Programming/Final network question. Honest.

Stoop Solo(Posted 2004) [#1]
...for now.

Is there any way to get the local computer's host name from within Blitz?


soja(Posted 2004) [#2]
Use the gethostname function in ws2_32.dll (Win95 and up).

Example:
n = CreateBank(256)
failed% = GetHostName(n, BankSize(n)) 
If Not failed Then
	Notify BankToString(n)
Else
	Notify "Error code: "+failed
EndIf

Function BankToString$(bank)
	While PeekByte(bank, i) <> 0
		s$ = s$ + Chr$(PeekByte(bank, i))
		i = i + 1
	Wend
	Return s$
End Function



skidracer(Posted 2004) [#3]
Print GetEnv("computername")


soja(Posted 2004) [#4]
Hey thanks -- I knew there was an easier way, I just couldn't remember it. Incidentally, is that the same for all Windows versions (do you know?)


Stoop Solo(Posted 2004) [#5]
Thanks guys. Duh, it never occured to me to type "set" and look for an environment variable.

soja, after some searching, I can't seem to get a straight answer as to whether or not the COMPUTERNAME environment variable is set on 9x platforms. I've found one site that says it doesn't, one site that implies it does, and I don't even have any Win98 PCs handy to test it on. Grr. I hope it does.

Unless anyone here knows better than me (which is approximately everyone), I may have to assume worst case scenario and evaluate it via the DLL call you describe. Never tried a DLL call before. Should be interesting.

Thanks for your most helpful replies people, appreciated.


semar(Posted 2004) [#6]
@Stoop Solo,
I guess it works.

Alternatively, you can run the dos command: SET, and route the output on a file, then parse it.

The file contains each environment variable followed by the value, so you can easily locate the USERNAME variable, and the associated value, which is what you need - that is, the host name.

Hope this helps,
Sergio.


soja(Posted 2004) [#7]
Ah, I forgot, to run the above example, just put this in a .decls file in the userlibs folder:
.lib "ws2_32.dll"
GetHostName%(name*, length%):"gethostname"



Stoop Solo(Posted 2004) [#8]
This is all really just to add additional fluff to this game, by displaying both the host name and the host adapter IP list in the chat window when a game has been created. Whether or not I achieve these ends won't impair the functionality of the actual network code, but it's a nice sort of plus to have.


MagicalTux(Posted 2004) [#9]
Prefer using Winsock2 (Win9x users will probably to install winsock2) than reading environnement variables.