-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dd5af9
commit 85ee6e5
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <sys/socket.h> | ||
#include <arpa/inet.h> | ||
#include <netinet/in.h> | ||
#include "nifm.h" | ||
|
||
static JSValue nx_nifm_exit(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) | ||
{ | ||
nifmExit(); | ||
return JS_UNDEFINED; | ||
} | ||
|
||
static JSValue nx_nifm_initialize(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) | ||
{ | ||
Result rc = nifmInitialize(NifmServiceType_User); | ||
if (R_FAILED(rc)) | ||
{ | ||
diagAbortWithResult(rc); | ||
} | ||
return JS_NewCFunction(ctx, nx_nifm_exit, "", 0); | ||
} | ||
|
||
static JSValue nx_network_info(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) | ||
{ | ||
JSValue info = JS_NewObject(ctx); | ||
char str[INET_ADDRSTRLEN]; | ||
struct in_addr ip; | ||
struct in_addr subnet_mask; | ||
struct in_addr gateway; | ||
struct in_addr primary_dns_server; | ||
struct in_addr secondary_dns_server; | ||
Result rc = nifmGetCurrentIpConfigInfo( | ||
&ip.s_addr, | ||
&subnet_mask.s_addr, | ||
&gateway.s_addr, | ||
&primary_dns_server.s_addr, | ||
&secondary_dns_server.s_addr); | ||
if (R_FAILED(rc)) | ||
{ | ||
// TODO: throw error | ||
} | ||
|
||
inet_ntop(AF_INET, &(ip.s_addr), str, INET_ADDRSTRLEN); | ||
JS_SetPropertyStr(ctx, info, "ip", JS_NewString(ctx, str)); | ||
|
||
inet_ntop(AF_INET, &(subnet_mask.s_addr), str, INET_ADDRSTRLEN); | ||
JS_SetPropertyStr(ctx, info, "subnetMask", JS_NewString(ctx, str)); | ||
|
||
inet_ntop(AF_INET, &(gateway.s_addr), str, INET_ADDRSTRLEN); | ||
JS_SetPropertyStr(ctx, info, "gateway", JS_NewString(ctx, str)); | ||
|
||
inet_ntop(AF_INET, &(primary_dns_server.s_addr), str, INET_ADDRSTRLEN); | ||
JS_SetPropertyStr(ctx, info, "primaryDnsServer", JS_NewString(ctx, str)); | ||
|
||
inet_ntop(AF_INET, &(secondary_dns_server.s_addr), str, INET_ADDRSTRLEN); | ||
JS_SetPropertyStr(ctx, info, "secondaryDnsServer", JS_NewString(ctx, str)); | ||
|
||
return info; | ||
} | ||
|
||
static const JSCFunctionListEntry function_list[] = { | ||
JS_CFUNC_DEF("nifmInitialize", 1, nx_nifm_initialize), | ||
JS_CFUNC_DEF("networkInfo", 1, nx_network_info), | ||
}; | ||
|
||
void nx_init_nifm(JSContext *ctx, JSValueConst init_obj) | ||
{ | ||
JS_SetPropertyFunctionList(ctx, init_obj, function_list, countof(function_list)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include "types.h" | ||
|
||
void nx_init_nifm(JSContext *ctx, JSValueConst init_obj); |