Wlan.getIPAddress() function not working

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
joreofiorio35
Posts: 6
Joined: Sat Dec 03, 2005 10:30 am

Wlan.getIPAddress() function not working

Post by joreofiorio35 »

Has anybody got this function to work? I am coding a chat program in LUA and I need to tell the user what IP Address his PSP is so other users can connect to him. Yesterday this was coming up with errors saying, "Invalid IP Address." And today it is coming up as a bunch of jumbled up text when I try to print the string that it returns. Shine, have you looked into this?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Wlan.getIPAddress() function not working

Post by Shine »

joreofiorio35 wrote:Shine, have you looked into this?
Yes, I have the same problem, see my comment in the Applications/WLAN program. I don't know how to fix it.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Re: Wlan.getIPAddress() function not working

Post by Fanjita »

Shine wrote:
joreofiorio35 wrote:Shine, have you looked into this?
Yes, I have the same problem, see my comment in the Applications/WLAN program. I don't know how to fix it.
I think maybe you're not waiting long enough for the Apctl connection to stabilise. Take a look at the code around sceNetApctlGetState() in PspPet's wifi sample code.

It would be easy enough to test this by putting a large sleep between initialising the wifi and getting the IP address.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
joreofiorio35
Posts: 6
Joined: Sat Dec 03, 2005 10:30 am

Post by joreofiorio35 »

Actually shine, I think you have made an error in your coding.

Here is what PspPet has:

Code: Select all

if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
            strcpy(szMyIPAddr, "unknown IP address");
And here is what you have Shine:

Code: Select all

        if (sceNetApctlGetInfo(8, szMyIPAddr) != 0) {
		// TODO: gets garbage
		lua_pushstring(L, szMyIPAddr);
		return 1;
	}
I think you should change the "!=0" to "==0", because if it doesnt equal zero, then it IS a valid IP address.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

Agreed. Both fixes are required for complete stability, I think.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
joreofiorio35
Posts: 6
Joined: Sat Dec 03, 2005 10:30 am

Post by joreofiorio35 »

Yes, Please Do fix it (if that is the problem) and if you can, can you send me the new compiled version once fixed, or post it on the site? (I dont have the pspsdk and dont have space for it)
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Thanks, I've fixed it. Fanjita wants to change something more for testing his 2.00 bootloader and I want to add some more true type font functions (you can set a transformation matrix for rotating and scaling the font and I think there is something for bold fonts), and UDP support is still missing, but then perhaps I'll release a new version this weekend.
joreofiorio35
Posts: 6
Joined: Sat Dec 03, 2005 10:30 am

Post by joreofiorio35 »

I have another way of getting your IP as of right now, this one will only get your router's IP which you can access your PSP through by port forwarding whichever port your program uses to listen with. This just connects a site and gets the IP from that site by picking apart the string of HTML code.

Code: Select all

function GETIPADDRESS()
	thestr = {}
	IP = ""
	a=1
	b=1
	ipgetsock, error = Socket.connect("216.99.213.74", 80)
	while not ipgetsock:isConnected() do System.sleep(100) end
	bytesSent = ipgetsock:send("GET /ipaddress.html HTTP/1.0\r\n")
	bytesSent = ipgetsock:send("host: ww1.nia-nia.com\r\n\r\n")

	while true do
		thestr[a] = ipgetsock:recv()
		if placefound == nil then placefound = string.find(thestr[a], "REMOTE_ADDR=") end
		if placefound then placefound=placefound+12
			while true do
				if string.sub(thestr[a], placefound, placefound) == "R" then IP=string.sub(IP, 1, string.len(IP)-1) return IP end
				IP=IP..string.sub(thestr[a], placefound, placefound)
				placefound=placefound+1
			end
		end
		placefound=nil
		if Controls.read():start() then screen.waitVblankStart(10) break end
		screen.waitVblankStart()
		a=a+1
	end
	return -1
end
Post Reply