From 83387bfc23aec2789770be5b9d48fdf348ee6391 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Wed, 7 Oct 2009 20:36:58 +0000 Subject: [PATCH] added very simple ARP manager IPv4 variables are 255.255.255.255 again at reset, 0.0.0.0 was a big mistake.. git-svn-id: svn://kolibrios.org@1200 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../net/applications/arpcfg/arpcfg.asm | 175 ++++++ .../net/applications/netcfg/macros.inc | 543 ------------------ .../net/applications/netcfg/netcfg.asm | 2 +- .../net/applications/network_lib/network.asm | 80 +-- .../net/applications/nslookup/dll.inc | 157 +++++ kernel/branches/net/network/ARP.inc | 24 +- kernel/branches/net/network/IPv4.inc | 4 +- kernel/branches/net/network/stack.inc | 5 + 8 files changed, 398 insertions(+), 592 deletions(-) create mode 100644 kernel/branches/net/applications/arpcfg/arpcfg.asm delete mode 100644 kernel/branches/net/applications/netcfg/macros.inc create mode 100644 kernel/branches/net/applications/nslookup/dll.inc diff --git a/kernel/branches/net/applications/arpcfg/arpcfg.asm b/kernel/branches/net/applications/arpcfg/arpcfg.asm new file mode 100644 index 0000000000..8c22b41c08 --- /dev/null +++ b/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: + + diff --git a/kernel/branches/net/applications/netcfg/macros.inc b/kernel/branches/net/applications/netcfg/macros.inc deleted file mode 100644 index c40830e8a9..0000000000 --- a/kernel/branches/net/applications/netcfg/macros.inc +++ /dev/null @@ -1,543 +0,0 @@ -@^ fix macro comment { -^@ fix } - -; ------------------------- -macro library [lname,fname] -{ - forward - dd __#lname#_library_table__,__#lname#_library_name__ - common - dd 0 - forward - align 4 - __#lname#_library_name__ db fname,0 -} - -macro import lname,[name,sname] -{ - common - align 4 - __#lname#_library_table__: - forward - if used name - name dd __#name#_import_name__ - end if - common - dd 0 - forward - if used name - align 4 - __#name#_import_name__ db sname,0 - end if -} - -macro export [name,sname] -{ - forward - dd __#name#_export_name__,name - common - dd 0 - forward - align 4 - __#name#_export_name__ db sname,0 -} -; ------------------------- - -macro m2m dest,src { - push src - pop dest -} - - -macro iglobal { - IGlobals equ IGlobals, - macro __IGlobalBlock { } - -macro uglobal { - UGlobals equ UGlobals, - macro __UGlobalBlock { } - -endg fix } ; Use endg for ending iglobal and uglobal blocks. - - -macro IncludeIGlobals{ - macro IGlobals dummy,[n] \{ __IGlobalBlock - purge __IGlobalBlock \} - match I, IGlobals \{ I \} } - -macro IncludeUGlobals{ - macro UGlobals dummy,[n] \{ - \common - \local begin, size - begin = $ - virtual at $ - \forward - __UGlobalBlock - purge __UGlobalBlock - \common - size = $ - begin - end virtual - rb size - \} - match U, UGlobals \{ U \} } - -uglobal -endg - -iglobal -endg - - -; new application structure -macro meos_app_start - { - use32 - org 0x0 - - db 'MENUET01' - dd 0x01 - dd __start - dd __end - dd __memory - dd __stack - - if used __params & ~defined __params - dd __params - else - dd 0x0 - end if - - dd 0x0 - } -MEOS_APP_START fix meos_app_start - -macro code - { - __start: - } -CODE fix code - -macro data - { - __data: - IncludeIGlobals - } -DATA fix data - -macro udata - { - if used __params & ~defined __params - __params: - db 0 - __end: - rb 255 - else - __end: - end if - __udata: - IncludeUGlobals - } -UDATA fix udata - -macro meos_app_end - { - align 32 - rb 2048 - __stack: - __memory: - } -MEOS_APP_END fix meos_app_end - - -; macro for defining multiline text data -struc mstr [sstring] - { - forward - local ssize - virtual at 0 - db sstring - ssize = $ - end virtual - dd ssize - db sstring - common - dd -1 - } - -; macro for defining multiline text data -struc mls [sstring] - { - forward - local ssize - virtual at 0 - db sstring ; mod - ssize = $ - end virtual - db ssize - db sstring - common - db -1 ; mod - } - - - -; strings -macro sz name,[data] { ; from MFAR [mike.dld] - common - if used name - name db data - .size = $-name - end if -} - -macro lsz name,[lng,data] { ; from MFAR [mike.dld] - common - if used name - label name - forward - if lang eq lng - db data - end if - common - .size = $-name - end if -} - -macro szc name,elsz,[data] { ; from MFAR [mike.dld] - common - local s,m - m = 0 - if used name - label name - forward - virtual at 0 - db data - s = $ - end virtual - d#elsz s - if m < s - m = s - end if - db data - common - .size = $-name - .maxl = m - end if -} - -macro lszc name,elsz,[lng,data] { ; from MFAR [mike.dld] - common - local s,m,c - m = 0 - c = 0 - if used name - label name - forward - if lang eq lng - virtual at 0 - db data - s = $ - end virtual - d#elsz s - if m < s - m = s - end if - db data - c = c+1 - end if - common - .size = $-name - .maxl = m - .count = c - end if -} - - -; easy system call macro -macro mpack dest, hsrc, lsrc -{ - if (hsrc eqtype 0) & (lsrc eqtype 0) - mov dest, (hsrc) shl 16 + lsrc - else - if (hsrc eqtype 0) & (~lsrc eqtype 0) - mov dest, (hsrc) shl 16 - add dest, lsrc - else - mov dest, hsrc - shl dest, 16 - add dest, lsrc - end if - end if -} - -macro __mov reg,a,b { ; mike.dld - if (~a eq)&(~b eq) - mpack reg,a,b - else if (~a eq)&(b eq) - mov reg,a - end if -} - - -__CPU_type equ p5 -SYSENTER_VAR equ 0 - -macro mcall a,b,c,d,e,f { ; mike.dld, updated by Ghost for Fast System Calls - local ..ret_point - __mov eax,a - __mov ebx,b - __mov ecx,c - __mov edx,d - __mov esi,e - __mov edi,f - - if __CPU_type eq p5 - int 0x40 - else - if __CPU_type eq p6 - push ebp - mov ebp, esp - push ..ret_point ; it may be 2 or 5 byte - sysenter - ..ret_point: - pop edx - pop ecx - - else - if __CPU_type eq k6 - push ecx - syscall - pop ecx - else - display 'ERROR : unknown CPU type (set to p5)', 10, 13 - __CPU_type equ p5 - int 0x40 - end if - end if - end if -} - - -; ------------------------- -macro header a,[b] { - common - use32 - org 0 - db 'MENUET',a - forward - if b eq - dd 0 - else - dd b - end if } -macro section name { align 16 - label name } -macro func name { - if ~used name - display 'FUNC NOT USED: ',`name,13,10 - else - align 4 - name: - ;diff16 `name,0,name -;pushad -;pushfd -;dps `name -;newline -;mcall 5,1 -;popfd -;popad -} -macro endf { end if } - -macro diff16 title,l1,l2 - { - local s,d - s = l2-l1 - display title,': 0x' - repeat 8 - d = '0' + s shr ((8-%) shl 2) and $0F - if d > '9' - d = d + 'A'-'9'-1 - end if - display d - end repeat - display 13,10 - } - -macro diff10 title,l1,l2 - { - local s,d,z,m - s = l2-l1 - z = 0 - m = 1000000000 - display title,': ' - repeat 10 - d = '0' + s / m - s = s - (s/m)*m - m = m / 10 - if d <> '0' - z = 1 - end if - if z <> 0 - display d - end if - end repeat - display 13,10 - } - -; optimize the code for size -__regs fix - -macro add arg1,arg2 - { - if (arg2 eqtype 0) - if (arg2) = 1 - inc arg1 - else - add arg1,arg2 - end if - else - add arg1,arg2 - end if - } - -macro sub arg1,arg2 - { - if (arg2 eqtype 0) - if (arg2) = 1 - dec arg1 - else - sub arg1,arg2 - end if - else - sub arg1,arg2 - end if - } - -macro mov arg1,arg2 - { - if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0')) - if (arg2) = 0 - xor arg1,arg1 - else if (arg2) = 1 - xor arg1,arg1 - inc arg1 - else if (arg2) = -1 - or arg1,-1 - else if (arg2) > -128 & (arg2) < 128 - push arg2 - pop arg1 - else - mov arg1,arg2 - end if - else - mov arg1,arg2 - end if - } - - -macro RGB [a] { - common - match (r=,g=,b),a \{ - \dd ((r) shl 16) or ((g) shl 8) or (b) - \} -} - - -struc POINT _t,_dx,_dy { - .x _t _dx - .y _t _dy -} - -; structure definition helper -include 'struct.inc' - -struct RECT - left dd ? - top dd ? - right dd ? - bottom dd ? -ends - -struct BOX - left dd ? - top dd ? - width dd ? - height dd ? -ends - -; structures used in MeOS -struct process_information - cpu_usage dd ? ; +0 - window_stack_position dw ? ; +4 - window_stack_value dw ? ; +6 - dw ? ; +8 - process_name rb 12 ; +10 - memory_start dd ? ; +22 - used_memory dd ? ; +26 - PID dd ? ; +30 - box BOX ; +34 - slot_state dw ? ; +50 - dw ? ; +52 - client_box BOX ; +54 - wnd_state db ? ; +70 - rb (1024-71) -ends - -struct system_colors - frame dd ? - grab dd ? - grab_button dd ? - grab_button_text dd ? - grab_text dd ? - work dd ? - work_button dd ? - work_button_text dd ? - work_text dd ? - work_graph dd ? -ends - -struct FILEDATE - Second db ? - Minute db ? - Hour db ? - db ? - Day db ? - Month db ? - Year dw ? -ends - -struct FILEINFO - Attributes dd ? - IsUnicode db ? - db 3 dup(?) - DateCreate FILEDATE - DateAccess FILEDATE - DateModify FILEDATE - Size dq ? -ends - -; constants - -; events -EV_IDLE = 0 -EV_TIMER = 0 -EV_REDRAW = 1 -EV_KEY = 2 -EV_BUTTON = 3 -EV_EXIT = 4 -EV_BACKGROUND = 5 -EV_MOUSE = 6 -EV_IPC = 7 -EV_STACK = 8 - -; event mask bits for function 40 -EVM_REDRAW = 1b -EVM_KEY = 10b -EVM_BUTTON = 100b -EVM_EXIT = 1000b -EVM_BACKGROUND = 10000b -EVM_MOUSE = 100000b -EVM_IPC = 1000000b -EVM_STACK = 10000000b - diff --git a/kernel/branches/net/applications/netcfg/netcfg.asm b/kernel/branches/net/applications/netcfg/netcfg.asm index 08546b2d0e..addb78ffd6 100644 --- a/kernel/branches/net/applications/netcfg/netcfg.asm +++ b/kernel/branches/net/applications/netcfg/netcfg.asm @@ -1,4 +1,4 @@ -include 'macros.inc' +include '../macros.inc' MEOS_APP_START type_ethernet equ 1 diff --git a/kernel/branches/net/applications/network_lib/network.asm b/kernel/branches/net/applications/network_lib/network.asm index 291df11129..b1070db39b 100644 --- a/kernel/branches/net/applications/network_lib/network.asm +++ b/kernel/branches/net/applications/network_lib/network.asm @@ -2,9 +2,9 @@ format MS COFF 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 @@ lib_init: ;//////////////////////////////////////////////////////////////////;; 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 @@ inet_addr: ;; ;;===========================================================================;; ;; Internal auxiliary function for IP parsing. ;; -.get_number: ;; +.get_number: ;; ;;---------------------------------------------------------------------------;; ;? Converts string to number. ;; ;;---------------------------------------------------------------------------;; @@ -155,7 +155,7 @@ inet_addr: ;; ; 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 @@ inet_addr: ;; ;;===========================================================================;; ;; 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 @@ struct __gai_reqdata 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 @@ ends ;; __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 @@ getaddrinfo: ;; ;; __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 @@ end virtual 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 @@ end virtual ; 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value ; 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 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value ;;===========================================================================;; ;; 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 @@ end virtual 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 @@ end virtual 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 @@ end virtual ;;===========================================================================;; ;; Internal auxiliary function for skipping names in DNS packet. ;; -.skip_name: ;; +.skip_name: ;; ;;---------------------------------------------------------------------------;; ;? Skips name in DNS packet. ;; ;;---------------------------------------------------------------------------;; @@ -976,7 +976,7 @@ end virtual ;;===========================================================================;; ;; 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 @@ end virtual ;;===========================================================================;; ;; Internal auxiliary function for decoding DNS name. ;; -.decode_name: ;; +.decode_name: ;; ;;---------------------------------------------------------------------------;; ;? Decode name in DNS packet. ;; ;;---------------------------------------------------------------------------;; @@ -1052,7 +1052,7 @@ end virtual ;;===========================================================================;; ;; Internal auxiliary function for allocating memory for getaddrinfo. ;; -getaddrinfo._.memalloc: ;; +getaddrinfo._.memalloc: ;; ;;---------------------------------------------------------------------------;; ;? Memory allocation. ;; ;;---------------------------------------------------------------------------;; @@ -1096,7 +1096,7 @@ getaddrinfo._.memalloc: ;; ;;===========================================================================;; ;; Internal auxiliary function for freeing memory for freeaddrinfo. ;; -getaddrinfo._.memfree: ;; +getaddrinfo._.memfree: ;; ;;---------------------------------------------------------------------------;; ;? Free memory. ;; ;;---------------------------------------------------------------------------;; @@ -1117,7 +1117,7 @@ getaddrinfo._.memfree: ;; ret ;;===========================================================================;; -getaddrinfo._.generate_data: ;; +getaddrinfo._.generate_data: ;; ;;---------------------------------------------------------------------------;; ;? Generate item(s) of getaddrinfo result list by one IP address. ;; ;;---------------------------------------------------------------------------;; @@ -1135,7 +1135,7 @@ getaddrinfo._.generate_data: ;; 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 @@ getaddrinfo._.generate_data: ;; ;;===========================================================================;; ;; 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 @@ getaddrinfo_abort: ;; ;;===========================================================================;; ;; void __stdcall freeaddrinfo(__in struct addrinfo* ai); ;; -freeaddrinfo: ;; +freeaddrinfo: ;; ;;---------------------------------------------------------------------------;; ;? Free one or more addrinfo structures returned by getaddrinfo. ;; ;;---------------------------------------------------------------------------;; @@ -1266,7 +1266,7 @@ freeaddrinfo: ;; 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 @@ export \ 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 @@ export \ 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' diff --git a/kernel/branches/net/applications/nslookup/dll.inc b/kernel/branches/net/applications/nslookup/dll.inc new file mode 100644 index 0000000000..6ceb2d514d --- /dev/null +++ b/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 diff --git a/kernel/branches/net/network/ARP.inc b/kernel/branches/net/network/ARP.inc index 85a99d7015..0564899920 100644 --- a/kernel/branches/net/network/ARP.inc +++ b/kernel/branches/net/network/ARP.inc @@ -601,16 +601,30 @@ ARP_API: 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 diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index ca945d5eea..b8ee99802e 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -85,9 +85,7 @@ IPv4_init: 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 diff --git a/kernel/branches/net/network/stack.inc b/kernel/branches/net/network/stack.inc index a6d200114c..e1bca93fab 100644 --- a/kernel/branches/net/network/stack.inc +++ b/kernel/branches/net/network/stack.inc @@ -50,6 +50,11 @@ IP_PROTO_ICMP equ 1 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