Skip to content

Instantly share code, notes, and snippets.

@devnoname120
Last active November 26, 2024 08:25
Show Gist options
  • Save devnoname120/dbc32cc4ebc13aa60330cc8a26133939 to your computer and use it in GitHub Desktop.
Save devnoname120/dbc32cc4ebc13aa60330cc8a26133939 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <arpa/inet.h>
int main()
{
struct sockaddr_in sa;
char str[INET_ADDRSTRLEN];
inet_pton(AF_INET, "192.168.0.1", &(sa.sin_addr));
printf("0x%x\n", sa.sin_addr.s_addr);
return 0;
}
// Doesn't work
#include <libk/stdio.h>
#include <libk/stdarg.h>
#include <libk/string.h>
#include <psp2kern/net/net.h>
#include "netlog.h"
struct SceNetSockaddrIn stSockAddr;
int socketFd;
void netlogInit(const char *serverIp, int port) {
socketFd = ksceNetSocket("debugnet_socket", SCE_NET_AF_INET , SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
memset(&stSockAddr, 0, sizeof stSockAddr);
stSockAddr.sin_family = SCE_NET_AF_INET;
stSockAddr.sin_port = ksceNetHtons(port);
// Doesn't exist in Kernel, do it yourself on your computer
//ksceNetInetPton(SCE_NET_AF_INET, serverIp, &stSockAddr.sin_addr);
stSockAddr.sin_addr.s_addr = /* This is given by getyourip.c */;
ksceNetConnect(socketFd, (struct SceNetSockaddr *)&stSockAddr, sizeof stSockAddr);
netlogPrintf("Netlog started.\n");
}
void netlogPrintf(const char* fmt, ...) {
char buffer[0x800];
va_list arg;
va_start(arg, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, arg);
va_end(arg);
ksceNetSendto(socketFd, buffer, strlen(buffer), 0, NULL, 0);
}
void netlogInit(const char *serverIp, int port);
void netlogPrintf(const char* fmt, ...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment