# - Local objects (use the kernel includes)\r
OBJ := helpers.o threads.o threads_glue.o server.o syscalls.o time.o\r
OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o\r
-OBJ += net.o\r
+OBJ += net.o syscall_getpath.o\r
\r
BUILDINFO_OBJ := obj-$(PLATFORM)/buildinfo.o\r
BUILDINFO_SRC := $(BUILDINFO_OBJ:%.o=%.c)\r
extern int giBuildNumber;
// === GLOBALS ===
-const char *gsAcessDir = "../Usermode/Output/x86_64";
+const char *gsAcessDir = "../Usermode/Output/native";
// === CODE ===
#ifndef __WIN32__
--- /dev/null
+/*
+ * AcessNative Kernel
+ *
+ * syscall_getpath.c
+ * - Implementation of the SYS_AN_GETPATH system call
+ */
+
+#include <acess.h>
+#include <vfs_int.h>
+
+extern char *getcwd(char *buf, size_t size);
+
+extern tVFS_NodeType gNativeFS_FileNodeType;
+extern tVFS_NodeType gNativeFS_DirNodeType;
+
+int Syscall_AN_GetPath_Real(char *Dst, size_t DstLen, const char *Path)
+{
+ tVFS_Node *node = VFS_ParsePath(Path, NULL, NULL);
+ if(!node) return -1;
+
+ const char *relpath = NULL;
+
+ if( node->Type == &gNativeFS_FileNodeType || node->Type == &gNativeFS_DirNodeType )
+ {
+ relpath = node->Data;
+ }
+ else
+ {
+ relpath = NULL;
+ }
+
+ size_t ret;
+ if( relpath )
+ {
+ if( relpath[0] == '/' ) {
+ ret = snprintf(Dst, DstLen, "%s", relpath);
+ }
+ else {
+ getcwd(Dst, DstLen);
+ ret = strlen(Dst);
+ ret += snprintf(Dst+ret, DstLen-ret, "/%s", relpath);
+ }
+ }
+ else
+ {
+ ret = 0;
+ }
+
+ _CloseNode(node);
+ return ret;
+}
// === IMPORTS ===
extern int Threads_Fork(void); // AcessNative only function
extern int Threads_Spawn(int nFD, int FDs[], const void *info);
+extern int Syscall_AN_GetPath_Real(char *Dest, size_t DstLen, const char *Path);
// === TYPES ===
typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes);
// === MACROS ===
+#define _SYSCALL_CHKFMT(_name,_fmtstr,Fmt) do{ \
+ if(strcmp(Fmt,_fmtstr) != 0) {\
+ *Errno = EINVAL;\
+ Log_Error("Syscalls", "Call %s takes args '%s', given '%s'", #_name, _fmtstr, Fmt);\
+ return -1;\
+ }\
+} while(0)
#define SYSCALL6(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _t5, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;_t5 a5;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
a1 = *(_t1*)Args;Args+=sizeof(_t1);\
a2 = *(_t2*)Args;Args+=sizeof(_t2);\
}
#define SYSCALL5(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
a1 = *(_t1*)Args;Args+=sizeof(_t1);\
a2 = *(_t2*)Args;Args+=sizeof(_t2);\
}
#define SYSCALL4(_name, _fmtstr, _t0, _t1, _t2, _t3, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;_t2 a2;_t3 a3;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
a1 = *(_t1*)Args;Args+=sizeof(_t1);\
a2 = *(_t2*)Args;Args+=sizeof(_t2);\
#define SYSCALL3(_name, _fmtstr, _t0, _t1, _t2, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;_t2 a2;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
a1 = *(_t1*)Args;Args+=sizeof(_t1);\
a2 = *(_t2*)Args;Args+=sizeof(_t2);\
#define SYSCALL2(_name, _fmtstr, _t0, _t1, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
a1 = *(_t1*)Args;Args+=sizeof(_t1);\
LOG("SYSCALL2 '%s' %p %p", Fmt, (intptr_t)a0,(intptr_t)a1);\
#define SYSCALL1(_name, _fmtstr, _t0, _call) int _name(Uint*Errno,const char*Fmt, void*Args,int*Sizes){\
_t0 a0;\
- if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
a0 = *(_t0*)Args;Args+=sizeof(_t0);\
LOG("SYSCALL1 '%s' %p", Fmt,(intptr_t)a0);\
_call;\
}
#define SYSCALL0(_name, _call) int _name(Uint*Errno,const char*Fmt, void*Args,int*Sizes){\
- if(strcmp(Fmt,"")!=0)return 0;\
+ _SYSCALL_CHKFMT(_name,"",Fmt);\
LOG("SYSCALL0");\
_call;\
}
SYSCALL1(Syscall_Chdir, "s", const char *,
return VFS_ChDir(a0);
);
+
+SYSCALL2(Syscall_AN_Getpath, "ds", char *, const char *,
+ return Syscall_AN_GetPath_Real(a0, Sizes[0], a1);
+);
+
SYSCALL0(Syscall_Sleep,
Threads_Sleep();
return 0;
[SYS_MOUNT] = Syscall_Mount,
[SYS_REOPEN] = NULL, // SYS_REOPEN
[SYS_CHDIR] = Syscall_Chdir,
+ [SYS_AN_GETPATH] = Syscall_AN_Getpath,
[SYS_WAITTID] = Syscall_WaitTID,
[SYS_SETUID] = Syscall_SetUID,
Syscall_GetGID,
Syscall_Sleep,
- Syscall_AN_Fork,
- Syscall_AN_Spawn,
+ [SYS_AN_FORK] = Syscall_AN_Fork,
+ [SYS_AN_SPAWN] = Syscall_AN_Spawn,
Syscall_SendMessage,
Syscall_GetMessage,
CFLAGS += -Wall
CFLAGS += -Werror
-CFLAGS += -g
+CFLAGS += -g -std=c99
CPPFLAGS += -DARCHDIR_is_x86_64=1
LDFLAGS += -g -Wl,-T,obj-$(PLATFORM)/link.ld
return _Syscall(SYS_CHDIR, ">s", Path);
}
-int acess__SysOpen(const char *Path, int Flags)
+int acess__SysOpen(const char *Path, unsigned int Flags)
{
if( strncmp(Path, "$$$$", 4) == 0 )
{
int kernel_tid;
int newID;
- newID = _Syscall(SYS_AN_SPAWN, "<d >d >d", sizeof(int), &kernel_tid,
+ newID = _Syscall(SYS_AN_SPAWN, "<d >d >d",
+ sizeof(int), &kernel_tid,
nfd*sizeof(int), fds,
info ? sizeof(*info) : 0, info);
#define _EXPORTS_H_
#include <stddef.h>
+#include <stdint.h>
// Syscall request (used by acess_*)
extern uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...);
extern int native_spawn(const char *filename, const char *const argv[], const char *const envp[]);
// Syscalls used by the linker
-extern int acess__SysOpen(const char *Path, int Flags);
+extern int acess__SysOpen(const char *Path, unsigned int Flags);
extern void acess__SysClose(int FD);
extern size_t acess__SysRead(int FD, void *Dest, size_t Bytes);
extern int acess__SysSeek(int FD, int64_t Offset, int Dir);
int native_spawn(const char *filename, const char *const argv[], const char *const envp[])
{
int rv;
-
+
+ fprintf(stderr, "native_spawn('%s')\n", filename);
+
#if __WIN32__
rv = _spawnve(_P_NOWAIT, filename, argv, envp);
#else
rv = posix_spawn(NULL, filename, NULL, NULL, (void*)argv, (void*)envp);
#endif
+ if( rv == 0 ) {
+ perror("native_spawn");
+ }
+
return rv;
}
ifeq ($(PLATFORM),lin)
BIN := ../libacess-native.so
endif
+BINLINK := ../../Usermode/Output/native/Libs/$(notdir $(BIN))
+$(warning $(BINLINK))
CFLAGS += -Wall
CFLAGS += -Werror
.PHONY: all clean
-all: $(BIN)
+all: $(BIN) $(BINLINK)
clean:
$(RM) $(BIN) $(OBJ) $(DEPFILES)
$(CC) -o $@ $(OBJ) $(LDFLAGS)
+$(BINLINK): $(BIN)
+ @mkdir -p $(dir $@)
+ @cd $(dir $@) && ln -sf ../../../../AcessNative/$(notdir $@)
+
obj-$(PLATFORM)/%.o: %.c
@mkdir -p $(dir $@)
@echo [CC] -o $@
--- /dev/null
+
+#ifndef _LIBACESSNATIVE_COMMON_H_
+#define _LIBACESSNATIVE_COMMON_H_
+
+extern int giSyscall_ClientID;
+extern void Request_Preinit(void);
+extern int acess__SysOpen(const char *Path, unsigned int flags);
+extern int acessnative_spawn(const char *Binary, int SyscallID, const char * const * argv, const char * const * envp);
+
+#define ENV_VAR_PREOPENS "AN_PREOPEN"
+#define ENV_VAR_KEY "ACESSNATIVE_KEY"
+
+#endif
+
+#include "common.h"
#define acess__SysSpawn _disabled_acess__SysSpawn
#include "../ld-acess_src/exports.c"
int acess__SysSpawn(const char *binary, const char **argv, const char **envp, int nfd, int fds[], struct s_sys_spawninfo *info)
{
int argc = 0;
- while( argv[argc++] );
+ while( argv[argc++] )
+ ;
Debug("_SysSpawn('%s', %p (%i), %p, %i, %p, %p)",
binary, argv, argc, envp, nfd, fds, info);
- int kernel_tid;
- int newID;
- newID = _Syscall(SYS_AN_SPAWN, "<d >d >d", sizeof(int), &kernel_tid,
+ char realpath[256];
+ realpath[255] = 0;
+
+ if( _Syscall(SYS_AN_GETPATH, "<d >s", sizeof(realpath)-1, realpath, binary) <= 0 ) {
+ Warning("No translation for path '%s'", binary);
+ acess__errno = -11;
+ return -1;
+ }
+
+ Warning("TODO: Spawn '%s' = '%s'", binary, realpath);
+
+ int emulated_tid;
+ int newID = _Syscall(SYS_AN_SPAWN, "<d >d >d",
+ sizeof(emulated_tid), &emulated_tid,
nfd*sizeof(int), fds,
- info ? sizeof(*info) : 0, info);
-
+ (info ? sizeof(*info) : 0), info
+ );
- Warning("TODO: Spawn '%s'", binary);
- // TODO: Translate internal path to actual path
+ if( newID <= 0 ) {
+ return -1;
+ }
- // TODO: set environment variables for libacess-native
- // > ACESSNATIVE_KEY=`newID`
- //native_spawn(binary, argv, envp);
+ if( acessnative_spawn(realpath, newID, argv, envp) ) {
+ }
- return 0;
+ return emulated_tid;
}
void ldacess_DumpLoadedLibraries(void)
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-
-extern int giSyscall_ClientID;
-extern void Request_Preinit(void);
-extern int acess__SysOpen(const char *Path, unsigned int flags);
+#include <stdbool.h>
+#include "common.h"
+#include <stdint.h>
+#include "../ld-acess_src/exports.h"
#ifdef __WINDOWS__
int DllMain(void)
{
Request_Preinit();
- const char *preopens = getenv_p(envp, "AN_PREOPEN");
+ const char *preopens = getenv_p(envp, ENV_VAR_PREOPENS);
printf("preopens = %s\n", preopens);
if( preopens )
{
}
}
-// if( !getenv("ACESSNATIVE_ID")
+// if( !getenv(ENV_VAR_KEY)
return 0;
}
#endif
+int acessnative_spawn(const char *Binary, int SyscallID, const char * const * argv, const char * const * envp)
+{
+ int envc = 0;
+ while( envp[envc++] )
+ envc ++;
+
+ // Set environment variables for libacess-native
+ // > ACESSNATIVE_KEY=`newID`
+ size_t keystr_len = snprintf(NULL, 0, "%s=%i", ENV_VAR_KEY, SyscallID);
+ char keystr[keystr_len+1];
+ snprintf(keystr, keystr_len+1, "%s=%i", ENV_VAR_KEY, SyscallID);
+ bool bKeyHit = false;
+
+ const char *newenv[envc+2+1];
+ int i = 0;
+ for( ; envp[i]; i ++ )
+ {
+ const char *ev = envp[i];
+ if( strncmp(ev, ENV_VAR_KEY"=", sizeof(ENV_VAR_KEY"=")) == 0 ) {
+ ev = keystr;
+ bKeyHit = true;
+ }
+ newenv[i] = ev;
+ }
+ if( !bKeyHit )
+ newenv[i++] = keystr;
+ newenv[i++] = "LD_LIBRARY_PATH=Libs/"; // HACK
+ newenv[i] = NULL;
+
+ // TODO: Detect native_spawn failing
+ return native_spawn(Binary, argv, newenv);
+}
void Debug(const char *format, ...)
{
{
}
+void __stack_chk_fail(void)
+{
+ fprintf(stderr, "__stack_chk_fail");
+ exit(1);
+}
+
_(SYS_MOUNT),
_(SYS_CHDIR),
+_(SYS_AN_GETPATH),
+
_(SYS_WAITTID),
_(SYS_SETUID),
_(SYS_SETGID),
* \name ACL Permissions
* \{
*/
-/**
- * \brief Readable
- */
-#define VFS_PERM_READ 0x00000001
-/**
- * \brief Writeable
- */
-#define VFS_PERM_WRITE 0x00000002
-/**
- * \brief Append allowed
- */
-#define VFS_PERM_APPEND 0x00000004
-/**
- * \brief Executable
- */
-#define VFS_PERM_EXECUTE 0x00000008
-/**
- * \brief All permissions granted
- */
-#define VFS_PERM_ALL 0x7FFFFFFF // Mask for permissions
-/**
- * \brief Denies instead of granting permissions
- * \note Denials take precedence
- */
-#define VFS_PERM_DENY 0x80000000 // Inverts permissions
+#define VFS_PERM_READ 0x00000001 //!< Readable
+#define VFS_PERM_WRITE 0x00000002 //!< Writable
+#define VFS_PERM_APPEND 0x00000004 //!< Appendable (/create file)
+#define VFS_PERM_EXEC 0x00000008 //!< Executable (/Traversable)
+#define VFS_PERM_ALL 0x7FFFFFFF //!< All permission bits
+#define VFS_PERM_DENY 0x80000000 //!< Flag for denying a permission set (higher precedence)
/**
* \}
*/
// === GLOBALS ===
tVFS_ACL gVFS_ACL_EveryoneRWX = { {1,-1}, {0,VFS_PERM_ALL} };
-tVFS_ACL gVFS_ACL_EveryoneRW = { {1,-1}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE} };
-tVFS_ACL gVFS_ACL_EveryoneRX = { {1,-1}, {0,VFS_PERM_READ|VFS_PERM_EXECUTE} };
+tVFS_ACL gVFS_ACL_EveryoneRW = { {1,-1}, {0,VFS_PERM_ALL^VFS_PERM_EXEC} };
+tVFS_ACL gVFS_ACL_EveryoneRX = { {1,-1}, {0,VFS_PERM_READ|VFS_PERM_EXEC} };
tVFS_ACL gVFS_ACL_EveryoneRO = { {1,-1}, {0,VFS_PERM_READ} };
// === CODE ===
ret[0].Perm.Inv = 0; ret[0].Perm.Perms = 0;
if(Mode & 0400) ret[0].Perm.Perms |= VFS_PERM_READ;
if(Mode & 0200) ret[0].Perm.Perms |= VFS_PERM_WRITE;
- if(Mode & 0100) ret[0].Perm.Perms |= VFS_PERM_EXECUTE;
+ if(Mode & 0100) ret[0].Perm.Perms |= VFS_PERM_EXEC;
// Group
ret[1].Ent.Group = 1; ret[1].Ent.ID = Group;
ret[1].Perm.Inv = 0; ret[1].Perm.Perms = 0;
if(Mode & 0040) ret[1].Perm.Perms |= VFS_PERM_READ;
if(Mode & 0020) ret[1].Perm.Perms |= VFS_PERM_WRITE;
- if(Mode & 0010) ret[1].Perm.Perms |= VFS_PERM_EXECUTE;
+ if(Mode & 0010) ret[1].Perm.Perms |= VFS_PERM_EXEC;
// Global
ret[2].Ent.Group = 1; ret[2].Ent.ID = -1;
ret[2].Perm.Inv = 0; ret[2].Perm.Perms = 0;
if(Mode & 0004) ret[2].Perm.Perms |= VFS_PERM_READ;
if(Mode & 0002) ret[2].Perm.Perms |= VFS_PERM_WRITE;
- if(Mode & 0001) ret[2].Perm.Perms |= VFS_PERM_EXECUTE;
+ if(Mode & 0001) ret[2].Perm.Perms |= VFS_PERM_EXEC;
// Return buffer
return ret;
}
// Permissions Check
- if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
+ if( !VFS_CheckACL(parent, VFS_PERM_EXEC|VFS_PERM_WRITE) ) {
errno = EACCES;
goto _error;
}
{{0,-1}, {0,VFS_PERM_ALL^VFS_PERM_WRITE}} // World (Nobody)
};
tVFS_ACL RootFS_FileACLs[3] = {
- {{0,0}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE}}, // Owner (Root)
- {{1,0}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE}}, // Group (Root)
+ {{0,0}, {0,VFS_PERM_ALL^VFS_PERM_EXEC}}, // Owner (Root)
+ {{1,0}, {0,VFS_PERM_ALL^VFS_PERM_EXEC}}, // Group (Root)
{{0,-1}, {0,VFS_PERM_READ}} // World (Nobody)
};
tVFS_NodeType gRootFS_DirType = {
pathEle[nextSlash] = 0;
// Check permissions on root of filesystem
- if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) {
+ if( !VFS_CheckACL(curNode, VFS_PERM_EXEC) ) {
LOG("Permissions failure on '%s'", Path);
errno = EPERM;
goto _error;
ENTER("pNode pMount xMode", Node, Mount, Mode);
i = 0;
- i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXECUTE : 0;
+ i |= (Mode & VFS_OPENFLAG_EXEC) ? VFS_PERM_EXEC : 0;
i |= (Mode & VFS_OPENFLAG_READ) ? VFS_PERM_READ : 0;
i |= (Mode & VFS_OPENFLAG_WRITE) ? VFS_PERM_WRITE : 0;
}
// Check ACLs on the parent
- if( !VFS_CheckACL(pnode, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) {
+ if( !VFS_CheckACL(pnode, VFS_PERM_EXEC|VFS_PERM_WRITE) ) {
errno = EACCES;
goto _pnode_err;
}
* - Core
*/
#include <stdio.h>
+#include <string.h>
#include <errno.h>
#include <acess/sys.h>
#define BUFLEN 1024
// === PROTOTYPES ===
-char *GetUsername();
-char *GetPassword();
+char *GetUsername(void);
+char *GetPassword(void);
// === CODE ===
int main(int argc, char *argv[])
*/
char *GetUsername()
{
- char ret[BUFLEN] = {0};
- int pos = 0;
- char ch;
-
// Prompt the user
printf("Username: ");
fflush(stdout);
FD_SET(server_fd, &fds); FD_SET(server_fd, &err_fds);\r
\r
// Wait for data (no timeout)\r
- rv = select(server_fd+1, &fds, NULL, &err_fds, NULL);\r
+ rv = _SysSelect(server_fd+1, &fds, NULL, &err_fds, NULL, 0);\r
if( rv < 0 ) break;\r
\r
// Check for remote data avaliable\r
#include "common.h"
#include <stdint.h>
+#include <assert.h>
#include "elf32.h"
#include "elf64.h"
#include <string.h>
#include <image.h>
//#include <image_sif.h>
-#include <acess/sys.h> // _SysDebug
+#include <acess/sys.h> // DEBUGS
-#define _SysDebug(...) do{}while(0)
+#if ENABLE_DEBUG
+# define DEBUGS(v...) _SysDebug(v)
+#else
+#define DEBUGS(...) do{}while(0)
+#endif
// === STRUCTURES ===
struct sHeader
int sampleSize;
struct sHeader *hdr = Buffer;
- _SysDebug("Image_SIF_Parse: (Buffer=%p, Size=0x%x)", Buffer, Size);
+ DEBUGS("Image_SIF_Parse: (Buffer=%p, Size=0x%x)", Buffer, Size);
// Get magic word and determine byte ordering
if(hdr->Magic == 0x51F0) // Little Endian
else if(hdr->Magic == 0xF051) // Big Endian
bRevOrder = 1;
else {
- _SysDebug(" Image_SIF_Parse: Magic invalid (0x%x)", hdr->Magic);
+ DEBUGS(" Image_SIF_Parse: Magic invalid (0x%x)", hdr->Magic);
return NULL;
}
- _SysDebug(" Image_SIF_Parse: bRevOrder = %i", bRevOrder);
+ DEBUGS(" Image_SIF_Parse: bRevOrder = %i", bRevOrder);
// Read flags
comp = hdr->Flags & 7;
w = hdr->Width;
h = hdr->Height;
- _SysDebug(" Image_SIF_Parse: Dimensions %ix%i", w, h);
+ DEBUGS(" Image_SIF_Parse: Dimensions %ix%i", w, h);
// Get image format
switch(fmt)
return NULL;
}
- _SysDebug(" Image_SIF_Parse: sampleSize = %i, fmt = %i", sampleSize, fmt);
+ DEBUGS(" Image_SIF_Parse: sampleSize = %i, fmt = %i", sampleSize, fmt);
fileOfs = sizeof(struct sHeader);
}
if(bRevOrder)
flip_buffer_endian(ret->Data, sampleSize, w*h);
- _SysDebug("Image_SIF_Parse: Complete at %i bytes", fileOfs);
+ DEBUGS("Image_SIF_Parse: Complete at %i bytes", fileOfs);
return ret;
// Channel 1.7.8 RLE
k = 0;
for( ; j < 8; j ++, k++)
{
- Addr[j*2] = hi[k]>>8;
- Addr[j*2+1] = hi[k]&0xFF;
+ Addr[j*2] = low[k]>>8;
+ Addr[j*2+1] = low[k]&0xFF;
}
return 1;
return 0;
}
-static const char *Net_PrintIPv4Address(uint8_t *Address)
+static const char *Net_PrintIPv4Address(const uint8_t *Address)
{
static __thread char ret[4*3+3+1]; // '255.255.255.255\0'
return ret;
}
-static const char *Net_PrintIPv6Address(uint16_t *Address)
+static const char *Net_PrintIPv6Address(const uint16_t *Address)
{
static __thread char ret[8*4+7+1]; // 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF\0'
#if 0
return ret;
}
-const char *Net_PrintAddress(int AddressType, void *Address)
+const char *Net_PrintAddress(int AddressType, const void *Address)
{
switch( AddressType )
{
* \param AddressType Address family as returned by Net_ParseAddress
* \param Address Address data
*/
-extern const char *Net_PrintAddress(int AddressType, void *Address);
+extern const char *Net_PrintAddress(int AddressType, const void *Address);
/**
* \brief Get the size in bytes of an address type
int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout)
{
- long long int ltimeout = 0, *ltimeoutp = NULL;
+ int64_t ltimeout = 0, *ltimeoutp = NULL;
if( timeout )
{
ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000;
// === CODE ===
char *crypt(const char *key, const char *salt)
{
+ if( *salt == '$' )
+ {
+ // $x$salt$
+ // x=1 : MD5
+ // x=5 : SHA-256
+ // x=6 : SHA-512
+ }
return "YIH14pBTDJvJ6"; // 'password' with the salt YI
}
// Convert `node` into types
if( service )
{
- char *end;
+ const char *end;
- default_port = strtol(service, &end, 0);
+ default_port = strtol(service, (char**)&end, 0);
if( *end != '\0' && (hints->ai_flags & AI_NUMERICSERV) )
{
return EAI_NONAME;
switch(af)
{
case AF_INET:
- str = Net_PrintAddress(4, &((struct in_addr*)src)->s_addr);
+ str = Net_PrintAddress(4, &((const struct in_addr*)src)->s_addr);
break;
case AF_INET6:
- str = Net_PrintAddress(6, ((struct in6_addr*)src)->s6_addr);
+ str = Net_PrintAddress(6, &((const struct in6_addr*)src)->s6_addr);
break;
default:
str = NULL;
// true URI
if(tmp[0] == ':' && tmp[1] == '/' && tmp[2] == '/')
{
- int hostlen, portlen, pathlen;
+ int hostlen, portlen;
tmp += 3; // Eat '://'
ret = malloc(sizeof(tURI) + protolen + 1 + strlen(tmp) + 1);