* I'm sure that UDP data length includes sizeof UDP header

* network library with DNS resolving from trunk and
  an application for DNS name lookup
  (do not work at moment due to crashes in the kernel)


git-svn-id: svn://kolibrios.org@1197 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2009-10-06 11:52:00 +00:00
parent 602924a5b5
commit 9c06d10fb3
4 changed files with 1517 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
; Socket types
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3 ; not supported by the kernel
; IP protocols
IPPROTO_IP = 0
IPPROTO_ICMP = 1 ; not supported by the kernel
IPPROTO_TCP = 6
IPPROTO_UDP = 17
; Address families
AF_UNSPEC = 0
AF_INET = 2 ; IPv4
;AF_INET6 = 28 ; IPv6 (not supported)
PF_UNSPEC = AF_UNSPEC
PF_INET = AF_INET
;PF_INET6 = AF_INET6
; Flags for addrinfo
AI_PASSIVE = 1
AI_CANONNAME = 2
AI_NUMERICHOST = 4
AI_NUMERICSERV = 8
AI_ADDRCONFIG = 0x400
; internal definition
AI_SUPPORTED = 0x40F
struct sockaddr_in
sin_family dw ? ; sa_family_t
sin_port dw ? ; in_port_t
sin_addr dd ? ; struct in_addr
sin_zero rb 8 ; zero
ends
struct addrinfo
ai_flags dd ? ; bitmask of AI_*
ai_family dd ? ; PF_*
ai_socktype dd ? ; SOCK_*
ai_protocol dd ? ; 0 or IPPROTO_*
ai_addrlen dd ? ; length of ai_addr
ai_canonname dd ? ; char*
ai_addr dd ? ; struct sockaddr*
ai_next dd ? ; struct addrinfo*
ends
EAI_ADDRFAMILY = 1
EAI_AGAIN = 2
EAI_BADFLAGS = 3
EAI_FAIL = 4
EAI_FAMILY = 5
EAI_MEMORY = 6
EAI_NONAME = 8
EAI_SERVICE = 9
EAI_SOCKTYPE = 10
EAI_BADHINTS = 12
EAI_PROTOCOL = 13
EAI_OVERFLOW = 14

View File

@ -0,0 +1,134 @@
use32
; standard header
db 'MENUET01' ; signature
dd 1 ; header version
dd start ; entry point
dd i_end ; initialized size
dd mem ; required memory
dd mem ; stack pointer
dd 0 ; parameters
dd 0 ; path
; useful includes
include '../macros.inc'
purge mov,add,sub
include '../proc32.inc'
include 'dll.inc'
include '../network_lib/network.inc'
; entry point
start:
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
; initialize console
push 1
call [con_start]
push title
push -1
push -1
push -1
push -1
call [con_init]
; main loop
main:
; write prompt
push str1
call [con_write_asciiz]
; read string
mov esi, s
push 256
push esi
call [con_gets]
; check for exit
test eax, eax
jz done
cmp byte [esi], 10
jz done
; delete terminating '\n'
push esi
@@:
lodsb
test al, al
jnz @b
mov byte [esi-2], al
pop esi
; resolve name
push esp ; reserve stack place
push esp ; fourth parameter
push 0 ; third parameter
push 0 ; second parameter
push esi ; first parameter
call [getaddrinfo]
pop esi
; test for error
test eax, eax
jnz fail
; write results
push str2
call [con_write_asciiz]
mov edi, esi
addrloop:
; before all subsequent addresses print comma
cmp edi, esi
jz @f
push str3
call [con_write_asciiz]
@@:
; convert IP address to decimal notation
mov eax, [edi+addrinfo.ai_addr]
pushd [eax+sockaddr_in.sin_addr]
call [inet_ntoa]
; write result
push eax
call [con_write_asciiz]
; advance to next item
mov edi, [edi+addrinfo.ai_next]
test edi, edi
jnz addrloop
; free allocated memory
push esi
call [freeaddrinfo]
; write newline and continue main loop
push str4
@@:
call [con_write_asciiz]
jmp main
fail:
push str5
jmp @b
done:
push 1
call [con_exit]
exit:
mcall -1
; data
title db 'Names resolver',0
str1 db 'Host name to resolve: ',0
str2 db 'IP address(es): ',0
str3 db ', ',0
str4 db 10,0
str5 db 'Name resolution failed.',10,0
; import
align 4
@IMPORT:
library network, 'network.obj', console, 'console.obj'
import network, \
getaddrinfo, 'getaddrinfo', \
freeaddrinfo, 'freeaddrinfo', \
inet_ntoa, 'inet_ntoa'
import console, \
con_start, 'START', \
con_init, 'con_init', \
con_write_asciiz, 'con_write_asciiz', \
con_exit, 'con_exit', \
con_gets, 'con_gets'
i_end:
s rb 256
align 4
rb 4096 ; stack
mem:

View File

@ -218,9 +218,9 @@ UDP_create_packet:
cmp edi, -1
je .exit
sub ecx , UDP_Packet.Data
mov byte[edi + UDP_Packet.Length], ch
mov byte[edi + UDP_Packet.Length+1], cl
sub ecx , UDP_Packet.Data
pop esi
push edi