Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gethostname implementation #224

Merged
merged 1 commit into from
Sep 30, 2024
Merged

add gethostname implementation #224

merged 1 commit into from
Sep 30, 2024

Conversation

tpimh
Copy link
Contributor

@tpimh tpimh commented Aug 5, 2024

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
Copy link
Contributor Author

tpimh commented Aug 5, 2024

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

@sharkwouter
Copy link
Member

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
Copy link
Contributor Author

tpimh commented Aug 5, 2024

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
Copy link
Member

sharkwouter commented Aug 5, 2024

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
Copy link
Contributor Author

tpimh commented Aug 5, 2024

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
Copy link
Member

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

@diamant3
Copy link
Member

diamant3 commented Aug 5, 2024

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.

src/libcglue/glue.c Outdated Show resolved Hide resolved
src/libcglue/glue.c Outdated Show resolved Hide resolved
src/libcglue/glue.c Outdated Show resolved Hide resolved
src/libcglue/Makefile.am Outdated Show resolved Hide resolved
@tpimh
Copy link
Contributor Author

tpimh commented Aug 5, 2024

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
Copy link
Member

diamant3 commented Aug 7, 2024

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.

src/libcglue/glue.c Outdated Show resolved Hide resolved
@tpimh tpimh marked this pull request as ready for review September 30, 2024 06:10
Copy link
Member

@sharkwouter sharkwouter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great and looks good now, thanks!

@sharkwouter sharkwouter merged commit d9aaa87 into pspdev:master Sep 30, 2024
1 check passed
int gethostname (char *__name, size_t __len) {
char nickname[_SC_HOST_NAME_MAX];
memset(nickname, 0, _SC_HOST_NAME_MAX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this memset looks superfluous, in the worst case if sceUtilityGetSystemParamString requires a valid C string as input, which seems unlikely, nickname[0] = 0; should be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants