pspdev / pspsdk

An open-source SDK for PSP homebrew development.
Other
856 stars 143 forks source link

add gethostname implementation #224

Closed tpimh closed 4 days ago

tpimh commented 2 months ago

PSP doesn't really has a hostname, however it has a nickname that can serve the same function. Been playing around with PSP networking recently, and the lack of this function was a bit frustrating. This is a very simple replacement function that I came up with.

tpimh commented 2 months ago

Oops, psputils.h and psputility.h are not the same thing...

sharkwouter commented 2 months ago

I did a little test with this and it does work. Here is my testing code.

main.c:

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <sys/unistd.h>

PSP_MODULE_INFO("PSP HOSTNAME", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);

int main(int argc, char *argv[])
{
    pspDebugScreenInit();

    char hostname[128];
    gethostname(hostname, 128);

    pspDebugScreenPrintf("%s", hostname);

    while (1)
    {
        sceDisplayWaitVblankStart();
    }
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)

project(hostname)

add_executable(${PROJECT_NAME}
  main.c
)

target_link_libraries(${PROJECT_NAME}
  pspdebug
  pspdisplay
  pspge
)

create_pbp_file(
    TARGET ${PROJECT_NAME}
    ICON_PATH NULL
    BACKGROUND_PATH NULL
    PREVIEW_PATH NULL
    TITLE ${PROJECT_NAME}
)

I'm not sure if we should be using the nickname, though. I think it would probably make more sense to just set it to PSP or maybe PSP-nickname or something like that.

tpimh commented 2 months ago

Hmmm, I need to test it. I got the same code working in my project, so I must've made a mistake when copying it to libcglue.c.

sharkwouter commented 2 months ago

It actually works, I just thought using the nickname is a bit odd and I added the code I used to test to make it a bit easier for others to also review this.

tpimh commented 2 months ago

I wonder what is the shortest and the longest nickname that can be set? And how does it compare to _SC_HOST_NAME_MAX?

sharkwouter commented 2 months ago

I think the limit is 128 characters, but I don't think anyone would actually use a nickname that long.

diamant3 commented 2 months ago

Thanks for the PR @tpimh and testing @sharkwouter!

I'll also add my review a bit to this one because we're on the same page as my PR #209 and I'll base my judgment on that.

tpimh commented 2 months ago

I was thinking about implementing sethostname later which can be added to the same object file (hostname.o), but it can also be in a separate object file.

diamant3 commented 1 month ago

I was thinking about implementing sethostname later which can be added to the same object file (hostname.o), but it can also be in a separate object file.

Sure! Feel free to make a separate PR for that. Also, it's much better that every function is separate and corresponds to each object file. Please stick with that.