Skip to content

Commit

Permalink
ps5: notify user on ip an port server is running on
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed Oct 29, 2024
1 parent 5a9042f commit ffac3f1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.ps5
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PYTHON ?= python3

BIN := websrv.elf
SRCS := src/main.c src/websrv.c src/asset.c src/fs.c
SRCS += src/ps5/sys.c src/ps5/pt.c src/ps5/elfldr.c src/ps5/hbldr.c
SRCS += src/ps5/sys.c src/ps5/pt.c src/ps5/elfldr.c src/ps5/hbldr.c src/ps5/notify.c
CFLAGS := -Wall -Werror -Isrc -DVERSION_TAG=\"$(VERSION_TAG)\"
LDADD := -lkernel_sys -lmicrohttpd -lSceSystemService -lSceUserService

Expand Down
42 changes: 42 additions & 0 deletions src/ps5/notify.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Copyright (C) 2024 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#include <stdio.h>
#include <string.h>
#include <stdarg.h>


typedef struct notify_request {
char useless1[45];
char message[3075];
} notify_request_t;


int sceKernelSendNotificationRequest(int, notify_request_t*, size_t, int);


void
notify(const char *fmt, ...) {
notify_request_t req;
va_list args;

bzero(&req, sizeof req);
va_start(args, fmt);
vsnprintf(req.message, sizeof req.message, fmt, args);
va_end(args);

sceKernelSendNotificationRequest(0, &req, sizeof req, 0);
}
20 changes: 20 additions & 0 deletions src/ps5/notify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (C) 2024 John Törnblom
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#pragma once


void notify(const char *fmt, ...);
50 changes: 50 additions & 0 deletions src/ps5/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#include <arpa/inet.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

#include <libgen.h>
#include <limits.h>
#include <signal.h>
Expand All @@ -29,6 +34,7 @@ along with this program; see the file COPYING. If not, see

#include "elfldr.h"
#include "hbldr.h"
#include "notify.h"
#include "pt.h"
#include "sys.h"
#include "websrv.h"
Expand Down Expand Up @@ -308,6 +314,48 @@ sys_launch_title(const char* title_id, const char* args) {
}


/**
* Serve FTP on a given port.
**/
static int
ps5_display_server(uint16_t port){
struct ifaddrs *ifaddr;
char ip[INET_ADDRSTRLEN];

if(getifaddrs(&ifaddr) == -1) {
return -1;
}

// Enumerate all AF_INET IPs
for(struct ifaddrs *ifa=ifaddr; ifa!=NULL; ifa=ifa->ifa_next) {
if(ifa->ifa_addr == NULL) {
continue;
}

if(ifa->ifa_addr->sa_family != AF_INET) {
continue;
}

// skip localhost
if(!strncmp("lo", ifa->ifa_name, 2)) {
continue;
}

struct sockaddr_in *in = (struct sockaddr_in*)ifa->ifa_addr;
inet_ntop(AF_INET, &(in->sin_addr), ip, sizeof(ip));

// skip interfaces without an ip
if(!strncmp("0.", ip, 2)) {
continue;
}

notify("Serving HTTP on %s:%d (%s)\n", ip, port, ifa->ifa_name);
}
return 0;
}



__attribute__((constructor)) static void
ps5_init(void) {
pid_t pid;
Expand All @@ -329,6 +377,8 @@ ps5_init(void) {
}

kernel_set_ucred_authid(-1, 0x4801000000000013L);

ps5_display_server(8080);
}


Expand Down

0 comments on commit ffac3f1

Please sign in to comment.