From 1094e71a7d416fd45f3c21b6c25793b96aa655c0 Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Mon, 7 Dec 2020 21:19:51 +0000 Subject: [PATCH] - 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 --- programs/develop/ktcc/trunk/bin/lib/libck.a | Bin 133136 -> 134552 bytes .../ktcc/trunk/libc/include/kolibrisys.h | 3 +- .../ktcc/trunk/libc/include/net/network.h | 54 ++++++++++++++++++ .../ktcc/trunk/libc/include/net/socket.h | 2 +- .../ktcc/trunk/libc/kolibrisys/process.asm | 18 ++++-- .../develop/ktcc/trunk/libc/net/network.asm | 50 ++++++++++++++++ .../develop/ktcc/trunk/samples/build_all.sh | 1 + .../develop/ktcc/trunk/samples/net/nslookup.c | 29 ++++++++++ 8 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc/include/net/network.h create mode 100644 programs/develop/ktcc/trunk/libc/net/network.asm create mode 100644 programs/develop/ktcc/trunk/samples/net/nslookup.c diff --git a/programs/develop/ktcc/trunk/bin/lib/libck.a b/programs/develop/ktcc/trunk/bin/lib/libck.a index aa4221024e002e1c78c504ea6a947d660b4571e1..8a4d75cdd57f675da61d63a264463564945f60ed 100644 GIT binary patch delta 2602 zcmcJR3v5$W7{~u#d%N91F?%rwn^@$v4cOKRI1s}iY$`G{9;=|p*0Bx-b6dJrqY1f4 z!8l4nP02dnA%YTuJi>s%Ak^{NlqCi+5LtLANMR_ThzkztcY0g*P#BtclHWP!dz|n4 z&bjCI*5#6G-86L7x`)NBJjyxyI4tXr=f13p_1Y#IY><>cFW$93r{yDtEH z*|vWL;N{|aa+udP%?7?~?c{4-)0GpP^i-D0=}4d_N>7E5f3E~?b3u2~0e>w>V*p7j zKw+mq5j^kf0zD*wA}4~P>p}fL041&m4Qd4qeg-t82{e2*D5(xKQV$xRtxoWm&GUAY3fYE$_+9dzwe&<)orzof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OKy_0qZK`d6frZr!P&2x?s9@I_i+ZGo!D>q# XEoyKjLw&OVSPO=i1=U1!^MvIWZNHsJ diff --git a/programs/develop/ktcc/trunk/libc/include/kolibrisys.h b/programs/develop/ktcc/trunk/libc/include/kolibrisys.h index 5638b8300a..934cdda48e 100644 --- a/programs/develop/ktcc/trunk/libc/include/kolibrisys.h +++ b/programs/develop/ktcc/trunk/libc/include/kolibrisys.h @@ -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); //-------------------------------------------------------------------------------------- -//------------------------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_kill_process(int pid); // if it returns -1 then an error. //--------------------------------------------------------------------------------- //-----------------Old functions for work with sound(Sound Blaster only).--------- diff --git a/programs/develop/ktcc/trunk/libc/include/net/network.h b/programs/develop/ktcc/trunk/libc/include/net/network.h new file mode 100644 index 0000000000..879548f783 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/include/net/network.h @@ -0,0 +1,54 @@ +#ifndef __NETWORK_H +#define __NETWORK_H + +#include + +#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 diff --git a/programs/develop/ktcc/trunk/libc/include/net/socket.h b/programs/develop/ktcc/trunk/libc/include/net/socket.h index 06f57961d0..b250171449 100644 --- a/programs/develop/ktcc/trunk/libc/include/net/socket.h +++ b/programs/develop/ktcc/trunk/libc/include/net/socket.h @@ -83,7 +83,7 @@ typedef struct{ }sockaddr; #pragma pack(pop) -#pragma pack(push, 1) +#pragma pack(push,1) typedef struct{ unsigned int level; unsigned int optionname; diff --git a/programs/develop/ktcc/trunk/libc/kolibrisys/process.asm b/programs/develop/ktcc/trunk/libc/kolibrisys/process.asm index cbff86911e..797a616ecb 100644 --- a/programs/develop/ktcc/trunk/libc/kolibrisys/process.asm +++ b/programs/develop/ktcc/trunk/libc/kolibrisys/process.asm @@ -2,15 +2,23 @@ format ELF ;include "public_stdcall.inc" public _ksys_get_process_table +public _ksys_kill_process section '.text' executable _ksys_get_process_table: ;arg1 - pointer to information ;arg2 - pid - mov eax,9 - mov ebx,[esp+4] - mov ecx,[esp+8] - int 0x40 + mov eax,9 + mov ebx,[esp+4] + mov ecx,[esp+8] + int 0x40 + ret 8 - ret 8 \ No newline at end of file +_ksys_kill_process: +;arg - pid + mov eax, 18 + mov ebx, 18 + mov ecx,[esp+4] + int 0x40 + ret 4 diff --git a/programs/develop/ktcc/trunk/libc/net/network.asm b/programs/develop/ktcc/trunk/libc/net/network.asm new file mode 100644 index 0000000000..5d996a5663 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/net/network.asm @@ -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' diff --git a/programs/develop/ktcc/trunk/samples/build_all.sh b/programs/develop/ktcc/trunk/samples/build_all.sh index 7aa7919dda..fc269226fa 100644 --- a/programs/develop/ktcc/trunk/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/samples/build_all.sh @@ -13,4 +13,5 @@ ../tcc console/console.c -lck -limg -o /tmp0/1/console ../tcc dir_example.c -lck -o /tmp0/1/dir_example ../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo +../tcc net/nslookup.c -lck -o /tmp0/1/nslookup exit diff --git a/programs/develop/ktcc/trunk/samples/net/nslookup.c b/programs/develop/ktcc/trunk/samples/net/nslookup.c new file mode 100644 index 0000000000..010c2b9e6e --- /dev/null +++ b/programs/develop/ktcc/trunk/samples/net/nslookup.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +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); + } +}