Subversion Repositories Kolibri OS

Compare Revisions

Ignore whitespace Rev 1199 → Rev 1200

/kernel/branches/net/applications/arpcfg/arpcfg.asm
0,0 → 1,175
;
; ARPmanager for KolibriOS
;
; hidnplayr@gmail.com
;
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd IM_END ; size of image
dd (I_END+0x100) ; memory for app
dd (I_END+0x100) ; esp
dd I_PARAM , 0x0 ; I_Param , I_Icon
 
__DEBUG__ equ 1
__DEBUG_LEVEL__ equ 1
 
include '..\macros.inc'
include '..\debug-fdo.inc'
 
START: ; start of execution
; TODO: check Parameters
 
DEBUGF 1, 'Hello!\n'
 
redraw:
 
mcall 12, 1
 
mcall 0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc, ,name
 
mcall 4, 25 shl 16 + 31, 0x80000000, title
 
;; call draw_stats
 
mcall 12, 2
 
jmp draw_stats
 
mainloop:
 
mcall 23,50 ; wait for event with timeout (0,5 s)
 
cmp eax, 1
je redraw
cmp eax, 2
je key
cmp eax, 3
je button
 
 
draw_stats:
 
mov edx, 50 shl 16 + 50
 
.loop:
mcall 75, 0x06080003, [last],,,ARP_ENTRY
cmp eax, -1
je mainloop
 
 
mcall 4, edx, 0x80000000, str_entry
mov edx, ebx
 
mov eax, 47
mov ebx, 0x00030000
mov esi, 0x40000000
mov edi, 0x00bcbcbc
xor ecx, ecx
 
mov cl, byte[ARP_ENTRY.IP+0]
mcall
 
mov cl, byte[ARP_ENTRY.IP+1]
add edx, 24 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.IP+2]
add edx, 24 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.IP+3]
add edx, 24 shl 16
mcall
 
 
mov ebx, 0x00020100
mov cl, byte[ARP_ENTRY.MAC+0]
add edx, 36 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.MAC+1]
add edx, 18 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.MAC+2]
add edx, 18 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.MAC+3]
add edx, 18 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.MAC+4]
add edx, 18 shl 16
mcall
 
mov cl, byte[ARP_ENTRY.MAC+5]
add edx, 18 shl 16
mcall
 
mov ebx, 0x00040000
mov cx, [ARP_ENTRY.Status]
add edx, 30 shl 16
mcall
 
mov cx, [ARP_ENTRY.TTL]
add edx, 60 shl 16
mcall
 
add dx, 20
rol edx, 16
mov dx, 50
rol edx, 16
inc [last]
 
jmp .loop
 
 
key:
mcall 2
jmp mainloop
 
 
button: ; button
mcall 17 ; get id
cmp ah, 1
je close
jmp redraw
 
close:
mcall -1
 
 
 
; DATA AREA
 
IM_END:
 
name db 'ARP manager',0
 
title db '# IP-address MAC-address Status TTL',0
str_entry db ' . . . - - - - - s',0
 
last dd 0
 
 
ARP_ENTRY:
.IP dd 192 shl 0 + 168 shl 8 + 1 shl 16 + 1 shl 24
.MAC dp 0xdeadbeef1337
.Status dw 0x0300
.TTL dw 37
.size:
 
include_debug_strings ; ALWAYS present in data section
 
I_PARAM rb 1024
 
I_END:
 
 
/kernel/branches/net/applications/netcfg/macros.inc
File deleted
/kernel/branches/net/applications/netcfg/netcfg.asm
1,4 → 1,4
include 'macros.inc'
include '../macros.inc'
MEOS_APP_START
 
type_ethernet equ 1
/kernel/branches/net/applications/network_lib/network.asm
2,9 → 2,9
 
public @EXPORT as 'EXPORTS'
 
include '../../../struct.inc'
include '../../../proc32.inc'
include '../../../macros.inc'
include '../struct.inc'
include '../proc32.inc'
include '../macros.inc'
purge section,mov,add,sub
 
include 'network.inc'
28,12 → 28,12
mov [mem.realloc], ecx
mov [dll.load], edx
mov [DNSrequestID], 1
stdcall edx, @IMPORT
stdcall edx, @IMPORT
ret 4
 
;;===========================================================================;;
;; in_addr_t __stdcall inet_addr(__in const char* hostname); ;;
inet_addr: ;;
inet_addr: ;;
;;---------------------------------------------------------------------------;;
;? Convert the string from standard IPv4 dotted notation to integer IP addr. ;;
;;---------------------------------------------------------------------------;;
124,7 → 124,7
 
;;===========================================================================;;
;; Internal auxiliary function for IP parsing. ;;
.get_number: ;;
.get_number: ;;
;;---------------------------------------------------------------------------;;
;? Converts string to number. ;;
;;---------------------------------------------------------------------------;;
155,7 → 155,7
; 3. Loop while digits are encountered.
.convert:
; 4. Convert digit from text representation to binary value.
or al, 20h ; '0'-'9' -> '0'-'9', 'A'-'F' -> 'a'-'f'
or al, 20h ; '0'-'9' -> '0'-'9', 'A'-'F' -> 'a'-'f'
sub al, '0'
cmp al, 9
jbe .digit
189,7 → 189,7
 
;;===========================================================================;;
;; char* __stdcall inet_ntoa(struct in_addr in); ;;
inet_ntoa: ;;
inet_ntoa: ;;
;;---------------------------------------------------------------------------;;
;? Convert the Internet host address to standard IPv4 dotted notation. ;;
;;---------------------------------------------------------------------------;;
263,7 → 263,7
reqid dw ? ; DNS request ID
socktype db ? ; SOCK_* or 0 for any
db ?
service dd ?
service dd ?
flags dd ?
reserved rb 16
ends
273,7 → 273,7
;; __in const char* servname, ;;
;; __in const struct addrinfo* hints, ;;
;; __out struct addrinfo **res); ;;
getaddrinfo: ;;
getaddrinfo: ;;
;;---------------------------------------------------------------------------;;
;? Get a list of IP addresses and port numbers for given host and service ;;
;;---------------------------------------------------------------------------;;
352,7 → 352,7
;; __in const struct addrinfo* hints, ;;
;; __out struct addrinfo **res, ;;
;; __out struct __gai_reqdata* reqdata); ;;
getaddrinfo_start: ;;
getaddrinfo_start: ;;
;;---------------------------------------------------------------------------;;
;? Initiator for getaddrinfo, sends DNS request ;;
;;---------------------------------------------------------------------------;;
429,8 → 429,8
jnz .ret
@@:
; 1e. Valid combinations for ai_socktype/ai_protocol: 0/0 for any or
; SOCK_STREAM/IPPROTO_TCP, SOCK_DGRAM/IPPROTO_UDP
; (raw sockets are not yet supported by the kernel)
; SOCK_STREAM/IPPROTO_TCP, SOCK_DGRAM/IPPROTO_UDP
; (raw sockets are not yet supported by the kernel)
xor edx, edx ; assume 0=any if no hints
jecxz .socket_type_ok
mov edx, [ecx+addrinfo.ai_socktype]
513,8 → 513,8
; 3. Process host name.
mov esi, [.hostname]
; 3a. If hostname is not given,
; use localhost for active sockets and INADDR_ANY for passive sockets.
mov eax, 0x0100007F ; 127.0.0.1 in network byte order
; use localhost for active sockets and INADDR_ANY for passive sockets.
mov eax, 0x0100007F ; 127.0.0.1 in network byte order
test byte [ebx+__gai_reqdata.flags], AI_PASSIVE
jz @f
xor eax, eax
613,8 → 613,8
stosw
mov [ebx+__gai_reqdata.reqid], ax
; 6c. Packed field: QR=0 (query), Opcode=0000 (standard query),
; AA=0 (ignored in requests), TC=0 (no truncation),
; RD=1 (recursion desired)
; AA=0 (ignored in requests), TC=0 (no truncation),
; RD=1 (recursion desired)
mov al, 00000001b
stosb
; 6d. Packed field: ignored in requests
641,7 → 641,7
jz .endname
cmp esi, ebx ; limit exceeded?
jae .wrongname
cmp al, '.' ; end of label?
cmp al, '.' ; end of label?
jz .labelend
stosb ; put next character
inc ecx ; increment label length
660,7 → 660,7
mov eax, ecx
neg eax
mov byte [edi+eax-1], cl
cmp byte [esi-1], 0 ; that was last label in the name?
cmp byte [esi-1], 0 ; that was last label in the name?
jnz .nameloop
; write terminating zero if not yet
mov al, 0
669,8 → 669,8
stosb
@@:
; 6h. Write request data:
; query type = A (host address) = 1,
; query class = IN (internet IPv4 address) = 1
; query type = A (host address) = 1,
; query class = IN (internet IPv4 address) = 1
; Note that network byte order is big-endian.
mov eax, 0x01000100
stosd
679,7 → 679,7
mcall 73, -1
xchg eax, edx
; Loop for all initialized network cards, scanning for initialized DNS address.
mov ebx, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address
mov ebx, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address
.get_dns_loop:
mcall 75
cmp eax, -1
699,7 → 699,7
; 8. Open UDP socket to DNS server, port 53.
; 8a. Create new socket.
mcall 74, 0, AF_INET, IPPROTO_UDP
cmp eax, -1 ; error?
cmp eax, -1 ; error?
jz .ret.dnserr
xchg ecx, eax ; put socket handle to ecx
; 8b. Create sockaddr structure on the stack.
739,7 → 739,7
;;===========================================================================;;
;; int __stdcall getaddrinfo_process(__in struct __gai_reqdata* reqdata, ;;
;; __out struct addrinfo** res); ;;
getaddrinfo_process: ;;
getaddrinfo_process: ;;
;;---------------------------------------------------------------------------;;
;? Processes network events from DNS reply ;;
;;---------------------------------------------------------------------------;;
826,9 → 826,9
lodsd ; get type and class
cmp esi, ecx
ja .ret.no_recovery
cmp eax, 0x01000500 ; type=5, class=1?
cmp eax, 0x01000500 ; type=5, class=1?
jz .got_cname
cmp eax, 0x01000100 ; type=1, class=1?
cmp eax, 0x01000100 ; type=1, class=1?
jnz .answers_loop.next
.got_addr:
; 10d. Process record A, host address.
845,7 → 845,7
mov esi, [.res_list_tail] ; pointer to result
test esi, esi
jz .no_result ; do not save if .res is NULL
mov ebx, [.reqdata] ; request data
mov ebx, [.reqdata] ; request data
call getaddrinfo._.generate_data
mov [.res_list_tail], esi
pop esi ecx ebx
950,7 → 950,7
 
;;===========================================================================;;
;; Internal auxiliary function for skipping names in DNS packet. ;;
.skip_name: ;;
.skip_name: ;;
;;---------------------------------------------------------------------------;;
;? Skips name in DNS packet. ;;
;;---------------------------------------------------------------------------;;
976,7 → 976,7
 
;;===========================================================================;;
;; Internal auxiliary function for calculating length of name in DNS packet. ;;
.get_name_length: ;;
.get_name_length: ;;
;;---------------------------------------------------------------------------;;
;? Calculate length of name (including terminating zero) in DNS packet. ;;
;;---------------------------------------------------------------------------;;
1021,7 → 1021,7
 
;;===========================================================================;;
;; Internal auxiliary function for decoding DNS name. ;;
.decode_name: ;;
.decode_name: ;;
;;---------------------------------------------------------------------------;;
;? Decode name in DNS packet. ;;
;;---------------------------------------------------------------------------;;
1052,7 → 1052,7
 
;;===========================================================================;;
;; Internal auxiliary function for allocating memory for getaddrinfo. ;;
getaddrinfo._.memalloc: ;;
getaddrinfo._.memalloc: ;;
;;---------------------------------------------------------------------------;;
;? Memory allocation. ;;
;;---------------------------------------------------------------------------;;
1096,7 → 1096,7
 
;;===========================================================================;;
;; Internal auxiliary function for freeing memory for freeaddrinfo. ;;
getaddrinfo._.memfree: ;;
getaddrinfo._.memfree: ;;
;;---------------------------------------------------------------------------;;
;? Free memory. ;;
;;---------------------------------------------------------------------------;;
1117,7 → 1117,7
ret
 
;;===========================================================================;;
getaddrinfo._.generate_data: ;;
getaddrinfo._.generate_data: ;;
;;---------------------------------------------------------------------------;;
;? Generate item(s) of getaddrinfo result list by one IP address. ;;
;;---------------------------------------------------------------------------;;
1135,7 → 1135,7
jnz .has_service
call .append_item
; 1a. If neither protocol nor socktype were specified,
; leave zeroes in socktype and protocol.
; leave zeroes in socktype and protocol.
mov cl, [ebx+__gai_reqdata.socktype]
test cl, cl
jz .no_socktype
1228,7 → 1228,7
 
;;===========================================================================;;
;; void __stdcall getaddrinfo_abort(__in struct __gai_reqdata* reqdata); ;;
getaddrinfo_abort: ;;
getaddrinfo_abort: ;;
;;---------------------------------------------------------------------------;;
;? Abort process started by getaddrinfo_start, free all resources. ;;
;;---------------------------------------------------------------------------;;
1246,7 → 1246,7
 
;;===========================================================================;;
;; void __stdcall freeaddrinfo(__in struct addrinfo* ai); ;;
freeaddrinfo: ;;
freeaddrinfo: ;;
;;---------------------------------------------------------------------------;;
;? Free one or more addrinfo structures returned by getaddrinfo. ;;
;;---------------------------------------------------------------------------;;
1266,7 → 1266,7
call getaddrinfo._.memfree
.no_canon_name:
; 2b. Remember next item
; (after freeing the field ai_next can became unavailable).
; (after freeing the field ai_next can became unavailable).
pushd [edx+addrinfo.ai_next]
; 2c. Free item itself.
xchg eax, edx
1294,9 → 1294,9
0x00010001 , 'version' , \
inet_addr , 'inet_addr' , \
inet_ntoa , 'inet_ntoa' , \
getaddrinfo , 'getaddrinfo' , \
getaddrinfo , 'getaddrinfo' , \
getaddrinfo_start , 'getaddrinfo_start' , \
getaddrinfo_process , 'getaddrinfo_process' , \
getaddrinfo_process , 'getaddrinfo_process' , \
getaddrinfo_abort , 'getaddrinfo_abort' , \
freeaddrinfo , 'freeaddrinfo'
 
1304,7 → 1304,7
align 4
@IMPORT:
 
library libini, 'libini.obj'
library libini, 'libini.obj'
import libini, \
ini.get_str, 'ini_get_str', \
ini.get_int, 'ini_get_int'
/kernel/branches/net/applications/nslookup/dll.inc
0,0 → 1,157
;-----------------------------------------------------------------------------
proc mem.Alloc size ;/////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------
push ebx ecx
mov eax,[size]
lea ecx,[eax+4+4095]
and ecx,not 4095
mcall 68,12
add ecx,-4
mov [eax],ecx
add eax,4
pop ecx ebx
ret
endp
 
;-----------------------------------------------------------------------------
proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
;-----------------------------------------------------------------------------
push ebx ecx esi edi eax
mov eax,[mptr]
mov ebx,[size]
or eax,eax
jz @f
lea ecx,[ebx+4+4095]
and ecx,not 4095
add ecx,-4
cmp ecx,[eax-4]
je .exit
@@: mov eax,ebx
call mem.Alloc
xchg eax,[esp]
or eax,eax
jz .exit
mov esi,eax
xchg eax,[esp]
mov edi,eax
mov ecx,[esi-4]
cmp ecx,[edi-4]
jbe @f
mov ecx,[edi-4]
@@: add ecx,3
shr ecx,2
cld
rep movsd
xchg eax,[esp]
call mem.Free
.exit:
pop eax edi esi ecx ebx
ret
endp
 
;-----------------------------------------------------------------------------
proc mem.Free mptr ;//////////////////////////////////////////////////////////
;-----------------------------------------------------------------------------
mov eax,[mptr]
or eax,eax
jz @f
push ebx ecx
lea ecx,[eax-4]
mcall 68,13
pop ecx ebx
@@: ret
endp
 
 
proc dll.Load, import_table:dword
mov esi,[import_table]
.next_lib: mov edx,[esi]
or edx,edx
jz .exit
push esi
mov esi,[esi+4]
mov edi,s_libdir.fname
@@: lodsb
stosb
or al,al
jnz @b
mcall 68,19,s_libdir
or eax,eax
jz .fail
stdcall dll.Link,eax,edx
stdcall dll.Init,[eax+4]
pop esi
add esi,8
jmp .next_lib
.exit: xor eax,eax
ret
.fail: add esp,4
xor eax,eax
inc eax
ret
endp
 
proc dll.Link, exp:dword,imp:dword
push eax
mov esi,[imp]
test esi,esi
jz .done
.next: lodsd
test eax,eax
jz .done
stdcall dll.GetProcAddress,[exp],eax
or eax,eax
jz @f
mov [esi-4],eax
jmp .next
@@: mov dword[esp],0
.done: pop eax
ret
endp
 
proc dll.Init, dllentry:dword
pushad
mov eax,mem.Alloc
mov ebx,mem.Free
mov ecx,mem.ReAlloc
mov edx,dll.Load
stdcall [dllentry]
popad
ret
endp
 
proc dll.GetProcAddress, exp:dword,sz_name:dword
mov edx,[exp]
xor eax,eax
.next: or edx,edx
jz .end
cmp dword[edx],0
jz .end
stdcall strcmp,[edx],[sz_name]
test eax,eax
jz .ok
add edx,8
jmp .next
.ok: mov eax,[edx+4]
.end: ret
endp
 
proc strcmp, str1:dword,str2:dword
push esi edi
mov esi,[str1]
mov edi,[str2]
xor eax,eax
@@: lodsb
scasb
jne .fail
or al,al
jnz @b
jmp .ok
.fail: or eax,-1
.ok: pop edi esi
ret
endp
 
s_libdir:
db '/sys/lib/'
.fname rb 32
/kernel/branches/net/network/ARP.inc
601,16 → 601,30
ret
 
.read:
; TODO: write code
cmp ecx, [NumARP]
jge .error
; edi = pointer to buffer
; ecx = # entry
imul ecx, ARP_ENTRY.size
add ecx, ARPTable
mov esi, ecx
mov ecx, ARP_ENTRY.size/2
rep movsw
 
xor eax, eax
ret
 
.write:
; TODO: write code
; call ARP_write_entry
ret
; esi = pointer to buffer
sub esp, ARP_ENTRY.size
mov edi, esp
mov ecx, ARP_ENTRY.size/2
rep movsw
jmp ARP_add_entry ;out: eax = entry number, -1 on error
 
.remove:
mov esi, eax
; ecx = # entry
mov esi, ecx
call ARP_del_entry
ret
 
/kernel/branches/net/network/IPv4.inc
85,9 → 85,7
 
or eax, -1
mov edi, BROADCAST
stosd
xor eax, eax
mov ecx, 4*MAX_IP
mov ecx, 4*MAX_IP+1
rep stosd
 
xor eax, eax
/kernel/branches/net/network/stack.inc
50,6 → 50,11
IP_PROTO_TCP equ 6
IP_PROTO_UDP equ 17
 
; Socket types
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
 
; TCP opening modes
SOCKET_PASSIVE equ 0
SOCKET_ACTIVE equ 1