- added network.obj loader

- added _ksys_kill_process function
in libck.a ktcc

git-svn-id: svn://kolibrios.org@8337 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
superturbocat2001 2020-12-07 21:19:51 +00:00
parent 7a2c280f29
commit 1094e71a7d
8 changed files with 150 additions and 7 deletions

View File

@ -171,8 +171,9 @@ extern int stdcall _ksys_pci_write_config_word(int bus,int dev,int fn,int reg,i
extern int stdcall _ksys_pci_write_config_dword(int bus,int dev,int fn,int reg,int value); extern int stdcall _ksys_pci_write_config_dword(int bus,int dev,int fn,int reg,int value);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
//------------------------Process information-------------------------------------- //------------------------Working with processes--------------------------------------
extern int stdcall _ksys_get_process_table(struct process_table_entry *proctab,int pid); //if pid=-1 than get info about him. extern int stdcall _ksys_get_process_table(struct process_table_entry *proctab,int pid); //if pid=-1 than get info about him.
extern int stdcall _ksys_kill_process(int pid); // if it returns -1 then an error.
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
//-----------------Old functions for work with sound(Sound Blaster only).--------- //-----------------Old functions for work with sound(Sound Blaster only).---------

View File

@ -0,0 +1,54 @@
#ifndef __NETWORK_H
#define __NETWORK_H
#include <net/socket.h>
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_OVERFLOW 14
// Flags for addrinfo
#define AI_PASSIVE 1
#define AI_CANONNAME 2
#define AI_NUMERICHOST 4
#define AI_NUMERICSERV 8
#define AI_ADDRCONFIG 0x400
#pragma pack(push, 1)
struct ARP_entry{
unsigned int IP;
unsigned char MAC[6];
unsigned short status;
unsigned short TTL;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
int ai_addrlen;
char *ai_canonname;
sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#pragma pack(pop)
extern int networklib_init ();
extern int (*inet_addr __attribute__ ((stdcall)))(const char* hostname);
extern char* (*inet_ntoa __attribute__ ((stdcall)))(int ip_addr);
extern int (*getaddrinfo __attribute__ ((stdcall)))(char* hostname, int servname, struct addrinfo* hints, struct addrinfo** res);
extern void (*freeaddrinfo __attribute__ ((stdcall)))(struct addrinfo* ai);
#endif

View File

@ -2,6 +2,7 @@ format ELF
;include "public_stdcall.inc" ;include "public_stdcall.inc"
public _ksys_get_process_table public _ksys_get_process_table
public _ksys_kill_process
section '.text' executable section '.text' executable
@ -12,5 +13,12 @@ _ksys_get_process_table:
mov ebx,[esp+4] mov ebx,[esp+4]
mov ecx,[esp+8] mov ecx,[esp+8]
int 0x40 int 0x40
ret 8 ret 8
_ksys_kill_process:
;arg - pid
mov eax, 18
mov ebx, 18
mov ecx,[esp+4]
int 0x40
ret 4

View File

@ -0,0 +1,50 @@
format elf
use32 ; Tell compiler to use 32 bit instructions
; ELF section
section '.text' executable
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
public lib_init as 'networklib_init'
proc lib_init
local retval dd ?
mov [retval], eax
pusha
mcall 68, 11
test eax, eax
jnz @f
mov [retval], -1
jmp exit_init_networklib
@@:
stdcall dll.Load, @IMPORT
test eax, eax
jz exit_init_networklib
mov [retval], -1
exit_init_networklib:
popa
mov eax, [retval]
ret
endp
section '.data' writeable
@IMPORT:
library networklib, 'network.obj'
import networklib, \
inet_addr, 'inet_addr', \
inet_ntoa, 'inet_ntoa', \
getaddrinfo, 'getaddrinfo', \
freeaddrinfo, 'freeaddrinfo'
public inet_addr as 'inet_addr'
public inet_ntoa as 'inet_ntoa'
public getaddrinfo as 'getaddrinfo'
public freeaddrinfo as 'freeaddrinfo'

View File

@ -13,4 +13,5 @@
../tcc console/console.c -lck -limg -o /tmp0/1/console ../tcc console/console.c -lck -limg -o /tmp0/1/console
../tcc dir_example.c -lck -o /tmp0/1/dir_example ../tcc dir_example.c -lck -o /tmp0/1/dir_example
../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo ../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo
../tcc net/nslookup.c -lck -o /tmp0/1/nslookup
exit exit

View File

@ -0,0 +1,29 @@
#include <net/network.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
struct addrinfo *res;
char host[256];
void main()
{
con_init_console_dll();
networklib_init();
con_set_title("nslookup demo");
printf("Host name to resolve: ");
con_gets(host, 256);
host[strlen(host)-1] = '\0';
if(getaddrinfo(host ,0, 0, &res)!=0)
{
puts("Host not found!");
freeaddrinfo(res);
con_exit(0);
}
else
{
printf("%s",inet_ntoa(res->ai_addr->sin_addr));
freeaddrinfo(res);
con_exit(0);
}
}