/programs/network/autodhcp/trunk/zeroconf.asm |
---|
File deleted |
\ No newline at end of file |
/programs/network/autodhcp/trunk/debug-fdo.inc |
---|
File deleted |
/programs/network/autodhcp/trunk/build.bat |
---|
File deleted |
\ No newline at end of file |
/programs/network/autodhcp/trunk/dhcp.inc |
---|
File deleted |
/programs/network/autodhcp/trunk/ETH.INC |
---|
File deleted |
/programs/network/autodhcp/trunk/zeroconf.ini |
---|
File deleted |
\ No newline at end of file |
/programs/network/autodhcp/trunk/dll.inc |
---|
File deleted |
/programs/network/stackcfg/trunk/stackcfg.asm |
---|
22,15 → 22,56 |
dd PARAMS , 0x0 ; I_Param , I_Icon |
include 'lang.inc' |
include 'macros.inc' |
include '../../../macros.inc' |
START: ; start of execution |
cmp [PARAMS], dword 'BOOT' |
jz boot_set_settings |
read_stack_setup: |
no_params: |
mov eax,52 |
mov ebx,0 |
mcall |
mov [config],eax |
mov eax,52 |
mov ebx,1 |
mcall |
mov dword [ip_address],eax |
mov eax,52 |
mov ebx,9 |
mcall |
mov dword [gateway_ip],eax |
mov eax,52 |
mov ebx,10 |
mcall |
mov dword [subnet_mask],eax |
mov eax,52 |
mov ebx,13 |
mcall |
mov dword [dns_ip],eax |
mov eax,[config] ; unwrap com IRQ |
shr eax,8 |
and eax,0xf |
mov [com_irq],eax |
mov eax,[config] ; unwrap com PORT |
shr eax,16 |
and eax,0xfff |
mov [com_add],eax |
mov eax,[config] ; unwrap IRQ |
and eax,0xf |
mov [interface],eax |
mov eax,[config] ; unwrap com PORT |
shr eax,7 |
and eax,1 |
mov [assigned],eax |
red: |
call draw_window ; at first, draw the window |
255,53 → 296,6 |
no_ip_sf: |
jmp still |
read_stack_setup: |
mov eax,52 |
mov ebx,0 |
mcall |
mov [config],eax |
mov eax,52 |
mov ebx,1 |
mcall |
mov dword [ip_address],eax |
mov eax,52 |
mov ebx,9 |
mcall |
mov dword [gateway_ip],eax |
mov eax,52 |
mov ebx,10 |
mcall |
mov dword [subnet_mask],eax |
mov eax,52 |
mov ebx,13 |
mcall |
mov dword [dns_ip],eax |
mov eax,[config] ; unwrap com IRQ |
shr eax,8 |
and eax,0xf |
mov [com_irq],eax |
mov eax,[config] ; unwrap com PORT |
shr eax,16 |
and eax,0xfff |
mov [com_add],eax |
mov eax,[config] ; unwrap IRQ |
and eax,0xf |
mov [interface],eax |
mov eax,[config] ; unwrap com PORT |
shr eax,7 |
and eax,1 |
mov [assigned],eax |
jmp red |
apply_stack_setup: |
mov eax,[com_irq] |
625,32 → 619,7 |
ret |
;****************************************************************************** |
boot_set_settings: |
mov eax,52 |
mov ebx,0 |
mcall |
mov [config],eax |
shr eax,8 ; unwrap com IRQ |
and eax,0xf |
mov [com_irq],eax |
mov eax,[config] ; unwrap com PORT |
shr eax,16 |
and eax,0xfff |
mov [com_add],eax |
call apply_stack_setup |
mov eax,-1 ; close this program |
mcall |
;****************************************************************************** |
; DATA AREA |
if lang eq ru |
660,7 → 629,7 |
db ' Slip à¥àë¢ ¨¥ ¬®¤¥¬ : 0x < ' |
db ' PPP ' |
db ' à ©¢¥à ¯ ª¥â®¢ IP server § ç¥ë© ' |
db ' ¨ªá. . . . < ' |
db ' (Ethernet) ¨ªá. . . . < ' |
db ' «î§: . . . < ' |
db ' ®¤á¥âì: . . . < ' |
db ' DNS IP: . . . < ' |
667,6 → 636,20 |
db ' ' |
db 'w ¨â âì ਬ¥¨âì ' |
elseif lang eq nl |
title db 'Netwerk configuratie',0 |
text: |
db ' Niet actief Modem Com Poort: 0x < ' |
db ' Slip Modem Com Irq: 0x < ' |
db ' PPP ' |
db ' Pakket Driver Door IP-server toegekend ' |
db ' (Ethernet) Vast IP: . . . < ' |
db ' Gateway: . . . < ' |
db ' Subnet: . . . < ' |
db ' DNS IP: . . . < ' |
db ' ' |
db 'w Vernieuw Toepassen ' |
else |
title db 'Stack configuration',0 |
text: |
674,7 → 657,7 |
db ' Slip Modem Com Irq: 0x < ' |
db ' PPP ' |
db ' Packet Driver IP server assigned ' |
db ' Fixed: . . . < ' |
db ' (Ethernet) Fixed: . . . < ' |
db ' Gateway: . . . < ' |
db ' Subnet: . . . < ' |
db ' DNS IP: . . . < ' |
687,19 → 670,18 |
button_color dd 0x2254b9 |
;ENTER YOUR SETTINGS HERE: |
ip_address db 010,005,004,175 |
gateway_ip db 010,005,000,001 |
subnet_mask db 255,255,000,000 |
dns_ip db 213,184,238,006 |
ip_address dd ? |
gateway_ip dd ? |
subnet_mask dd ? |
dns_ip dd ? |
com_irq dd 0 ; irq for slip/ppp |
com_add dd 0 ; com port address for slip/ppp |
interface dd 3 ; not active,slip,ppp,packet driver |
assigned dd 0 ; get ip from server |
com_irq dd ? ; irq for slip/ppp |
com_add dd ? ; com port address for slip/ppp |
interface dd ? ; not active,slip,ppp,packet driver |
assigned dd ? ; get ip from server |
config dd 0 |
config dd ? |
I_END: |
/programs/network/zeroconf/trunk/ETH.INC |
---|
0,0 → 1,413 |
; |
; ETH.INC |
; |
; made by hidnplayr (hidnplayr@kolibrios.org) for KolibriOS |
; |
; The given code before every macro is only a simple example |
; |
; |
; HISTORY |
; |
; v1.0: august 2006 original release |
; v1.1: december 2006 bugfixes and improvements |
; v1.2: february 2007 more bugfixes and improvements |
macro mov arg1,arg2 { |
if arg1 eq arg2 |
else |
mov arg1,arg2 |
end if |
} |
TCB_LISTEN = 1 |
TCB_SYN_SENT = 2 |
TCB_SYN_RECEIVED = 3 |
TCB_ESTABLISHED = 4 |
TCB_FIN_WAIT_1 = 5 |
TCB_FIN_WAIT_2 = 6 |
TCB_CLOSE_WAIT = 7 |
TCB_CLOSING = 8 |
TCB_LAST_ASK = 9 |
TCB_TIME_WAIT = 10 |
TCB_CLOSED = 11 |
PASSIVE = 0 |
ACTIVE = 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
macro eth.get_IP IP { |
mov ebx,1 |
mov eax,52 |
mcall |
mov IP ,eax |
} |
macro eth.get_GATEWAY GATEWAY { |
mov ebx,9 |
mov eax,52 |
mcall |
mov GATEWAY ,eax |
} |
macro eth.get_SUBNET SUBNET { |
mov ebx,10 |
mov eax,52 |
mcall |
mov SUBNET ,eax |
} |
macro eth.get_DNS DNS { |
mov ebx,13 |
mov eax,52 |
mcall |
mov DNS ,eax |
} |
macro eth.set_IP IP { |
mov ecx,IP |
mov ebx,3 |
mov eax,52 |
mcall |
} |
macro eth.set_GATEWAY GATEWAY { |
mov ecx,GATEWAY |
mov ebx,11 |
mov eax,52 |
mcall |
} |
macro eth.set_SUBNET SUBNET { |
mov ecx,SUBNET |
mov ebx,12 |
mov eax,52 |
mcall |
} |
macro eth.set_DNS DNS { |
mov ecx,DNS |
mov ebx,14 |
mov eax,52 |
mcall |
} |
macro eth.set_network_drv conf { |
mov ecx,conf |
mov ebx,2 |
mov eax,52 |
mcall |
} |
macro eth.open_udp local,remote,ip,socket { |
mov ecx, local |
mov edx, remote |
mov esi, ip |
mov ebx, 0 |
mov eax, 53 |
mcall |
mov socket,eax |
} |
macro eth.close_udp socket { |
mov ecx, socket |
mov ebx, 1 |
mov eax, 53 |
mcall |
} |
macro eth.poll socket { |
mov ecx, socket |
mov ebx, 2 |
mov eax, 53 |
mcall |
} |
macro eth.read_byte socket, result { |
mov ecx, socket |
mov ebx, 3 |
mov eax, 53 |
mcall |
mov result,bl |
} |
macro eth.read_packet socket, result, buffersize { |
mov esi, buffersize |
mov edx, result |
mov ecx, socket |
mov ebx, 11 |
mov eax, 53 |
mcall |
} |
macro eth.write_udp socket,length,msg,verify { |
mov ecx, socket |
mov edx, length |
mov esi, msg |
mov ebx, 4 |
mov eax, 53 |
mcall |
if verify eq 1 |
call verifysend |
end if |
} |
verifysend: |
test eax,eax |
jnz @f |
ret |
@@: |
pusha |
mov eax,5 |
mov ebx,100 |
mcall |
popa |
mcall |
ret |
macro eth.open_tcp local,remote,ip,passive,socket { |
mov ecx, local |
mov edx, remote |
mov esi, ip |
mov edi, passive ; 0 = PASSIVE open |
mov ebx, 5 |
mov eax, 53 |
mcall |
mov socket,eax |
} |
macro eth.socket_status socket,result { |
mov ecx, socket |
mov ebx, 6 |
mov eax, 53 |
mcall |
mov result,eax |
} |
macro eth.write_tcp socket,length,msg,verify { |
mov ecx, socket |
mov edx, length |
mov esi, msg |
mov ebx, 7 |
mov eax, 53 |
mcall |
if verify eq 1 |
call verifysend |
end if |
} |
macro eth.read_mac mac { |
mov eax, 52 |
mov ebx, 15 |
xor ecx, ecx |
pusha |
mcall |
mov dword[mac],eax |
popa |
add cl, 4 |
mcall |
mov word[mac+4],ax |
} |
macro eth.close_tcp socket { |
mov ecx, socket |
mov ebx, 8 |
mov eax, 53 |
mcall |
} |
macro eth.check_port port,result { |
mov ecx, port |
mov ebx, 9 |
mov eax, 53 |
mcall |
mov result,eax |
} |
macro eth.check_cable result { |
mov ebx, 10 |
mov eax, 53 |
mcall |
mov result,eax |
} |
macro eth.status status { |
mov ebx, 255 |
mov ecx, 6 |
mov eax, 53 |
mcall |
mov status,eax |
} |
macro eth.search_port port,result { |
mov edx,port |
@@: |
inc edx |
eth.check_port edx,eax |
cmp eax,0 |
je @r |
mov result,edx |
} |
macro eth.ARP_PROBE address{ |
mov edx,address |
mov eax,52 |
mov ebx,16 |
xor ecx,ecx |
mcall |
} |
macro eth.ARP_ANNOUNCE address{ |
mov edx,address |
mov eax,52 |
mov ebx,16 |
xor ecx,ecx |
inc ecx |
mcall |
} |
macro eth.read_data socket,dest,endptr,bufferl { |
local .getdata,.loop,.end |
mov eax, dest |
mov endptr, eax |
.getdata: |
cmp endptr, bufferl |
jg .end |
eth.read_packet socket, endptr, 0 |
add endptr,eax |
test eax, eax |
jnz .getdata |
xor edx, edx |
.loop: |
eth.poll socket |
test eax, eax |
jnz .getdata |
mov eax,5 |
mov ebx,1 |
mcall |
inc edx |
cmp edx,30 |
jl .loop |
.end: |
} |
macro eth.wait_for_data socket,TIMEOUT,abort { |
mov edx,TIMEOUT |
@@: |
eth.poll socket |
cmp eax,0 |
jne @f |
dec edx |
jz abort |
mov eax,5 ; wait here for event |
mov ebx,10 |
mcall |
jmp @r |
@@: |
} |
Ip2dword: |
push edx |
; This code validates if the query is an IP containing 4 numbers and 3 dots |
xor al, al ; make al (dot count) zero |
@@: |
cmp byte[edx],'0' ; check if this byte is a number, if not jump to no_IP |
jl no_IP ; |
cmp byte[edx],'9' ; |
jg no_IP ; |
inc edx ; the byte was a number, so lets check the next byte |
cmp byte[edx],0 ; is this byte zero? (have we reached end of query?) |
jz @f ; jump to next @@ then |
cmp byte[edx],':' |
jz @f |
cmp byte[edx],'.' ; is this byte a dot? |
jne @r ; if not, jump to previous @@ |
inc al ; the byte was a dot so increment al(dot count) |
inc edx ; next byte |
jmp @r ; lets check for numbers again (jump to previous @@) |
@@: ; we reach this when end of query reached |
cmp al,3 ; check if there where 3 dots |
jnz no_IP ; if not, jump to no_IP |
; The following code will convert this IP into a dword and output it in eax |
; If there is also a port number specified, this will be returned in ebx, otherwise ebx is -1 |
pop esi ; edx (query address) was pushed onto stack and is now popped in esi |
xor edx, edx ; result |
xor eax, eax ; current character |
xor ebx, ebx ; current byte |
.outer_loop: |
shl edx, 8 |
add edx, ebx |
xor ebx, ebx |
.inner_loop: |
lodsb |
test eax, eax |
jz .finish |
cmp al, '.' |
jz .outer_loop |
sub eax, '0' |
imul ebx, 10 |
add ebx, eax |
jmp .inner_loop |
.finish: |
shl edx, 8 |
add edx, ebx |
bswap edx ; we want little endian order |
ret |
no_IP: |
pop edx |
xor edx, edx |
ret |
/programs/network/zeroconf/trunk/build.bat |
---|
0,0 → 1,2 |
@fasm autodhcp.asm autodhcp |
@pause |
/programs/network/zeroconf/trunk/debug-fdo.inc |
---|
0,0 → 1,422 |
; |
; Formatted Debug Output (FDO) |
; Copyright (c) 2005-2006, mike.dld |
; Created: 2005-01-29, Changed: 2006-11-10 |
; |
; For questions and bug reports, mail to mike.dld@gmail.com |
; |
; Available format specifiers are: %s, %d, %u, %x (with partial width support) |
; |
; to be defined: |
; __DEBUG__ equ 1 |
; __DEBUG_LEVEL__ equ 5 |
macro debug_func name { |
if used name |
name@of@func equ name |
} |
macro debug_beginf { |
align 4 |
name@of@func: |
} |
debug_endf fix end if |
macro DEBUGS _sign,[_str] { |
common |
local tp |
tp equ 0 |
match _arg:_num,_str \{ |
DEBUGS_N _sign,_num,_arg |
tp equ 1 |
\} |
match =0 _arg,tp _str \{ |
DEBUGS_N _sign,,_arg |
\} |
} |
macro DEBUGS_N _sign,_num,[_str] { |
common |
pushf |
pushad |
local ..str,..label,is_str |
is_str = 0 |
forward |
if _str eqtype '' |
is_str = 1 |
end if |
common |
if is_str = 1 |
jmp ..label |
..str db _str,0 |
..label: |
add esp,4*8+4 |
mov edx,..str |
sub esp,4*8+4 |
else |
mov edx,_str |
end if |
if ~_num eq |
if _num eqtype eax |
if _num in <eax,ebx,ecx,edx,edi,ebp,esp> |
mov esi,_num |
else if ~_num eq esi |
movzx esi,_num |
end if |
else if _num eqtype 0 |
mov esi,_num |
else |
local tp |
tp equ 0 |
match [_arg],_num \{ |
mov esi,dword[_arg] |
tp equ 1 |
\} |
match =0 =dword[_arg],tp _num \{ |
mov esi,dword[_arg] |
tp equ 1 |
\} |
match =0 =word[_arg],tp _num \{ |
movzx esi,word[_arg] |
tp equ 1 |
\} |
match =0 =byte[_arg],tp _num \{ |
movzx esi,byte[_arg] |
tp equ 1 |
\} |
match =0,tp \{ |
'Error: specified string width is incorrect' |
\} |
end if |
else |
mov esi,0x7FFFFFFF |
end if |
call fdo_debug_outstr |
popad |
popf |
} |
macro DEBUGD _sign,_dec { |
local tp |
tp equ 0 |
match _arg:_num,_dec \{ |
DEBUGD_N _sign,_num,_arg |
tp equ 1 |
\} |
match =0 _arg,tp _dec \{ |
DEBUGD_N _sign,,_arg |
\} |
} |
macro DEBUGD_N _sign,_num,_dec { |
pushf |
pushad |
if (~_num eq) |
if (_dec eqtype eax | _dec eqtype 0) |
'Error: precision allowed only for in-memory variables' |
end if |
if (~_num in <1,2,4>) |
if _sign |
'Error: 1, 2 and 4 are only allowed for precision in %d' |
else |
'Error: 1, 2 and 4 are only allowed for precision in %u' |
end if |
end if |
end if |
if _dec eqtype eax |
if _dec in <ebx,ecx,edx,esi,edi,ebp,esp> |
mov eax,_dec |
else if ~_dec eq eax |
if _sign = 1 |
movsx eax,_dec |
else |
movzx eax,_dec |
end if |
end if |
else if _dec eqtype 0 |
mov eax,_dec |
else |
add esp,4*8+4 |
if _num eq |
mov eax,dword _dec |
else if _num = 1 |
if _sign = 1 |
movsx eax,byte _dec |
else |
movzx eax,byte _dec |
end if |
else if _num = 2 |
if _sign = 1 |
movsx eax,word _dec |
else |
movzx eax,word _dec |
end if |
else |
mov eax,dword _dec |
end if |
sub esp,4*8+4 |
end if |
mov cl,_sign |
call fdo_debug_outdec |
popad |
popf |
} |
macro DEBUGH _sign,_hex { |
local tp |
tp equ 0 |
match _arg:_num,_hex \{ |
DEBUGH_N _sign,_num,_arg |
tp equ 1 |
\} |
match =0 _arg,tp _hex \{ |
DEBUGH_N _sign,,_arg |
\} |
} |
macro DEBUGH_N _sign,_num,_hex { |
pushf |
pushad |
if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>) |
'Error: 1..8 are only allowed for precision in %x' |
end if |
if _hex eqtype eax |
if _hex in <eax,ebx,ecx,edx,esi,edi,ebp,esp> |
if ~_hex eq eax |
mov eax,_hex |
end if |
else if _hex in <ax,bx,cx,dx,si,di,bp,sp> |
if ~_hex eq ax |
movzx eax,_hex |
end if |
shl eax,16 |
if (_num eq) |
mov edx,4 |
end if |
else if _hex in <al,ah,bl,bh,cl,ch,dl,dh> |
if ~_hex eq al |
movzx eax,_hex |
end if |
shl eax,24 |
if (_num eq) |
mov edx,2 |
end if |
end if |
else if _hex eqtype 0 |
mov eax,_hex |
else |
add esp,4*8+4 |
mov eax,dword _hex |
sub esp,4*8+4 |
end if |
if ~_num eq |
mov edx,_num |
else |
mov edx,8 |
end if |
call fdo_debug_outhex |
popad |
popf |
} |
;----------------------------------------------------------------------------- |
debug_func fdo_debug_outchar |
debug_beginf |
pushad |
mov cl,al |
mov ebx,1 |
mov eax,63 |
mcall |
popad |
ret |
debug_endf |
debug_func fdo_debug_outstr |
debug_beginf |
mov eax,63 |
mov ebx,1 |
.l1: dec esi |
js .l2 |
mov cl,[edx] |
or cl,cl |
jz .l2 |
mcall |
inc edx |
jmp .l1 |
.l2: ret |
debug_endf |
debug_func fdo_debug_outdec |
debug_beginf |
or cl,cl |
jz @f |
or eax,eax |
jns @f |
neg eax |
push eax |
mov al,'-' |
call fdo_debug_outchar |
pop eax |
@@: push 10 |
pop ecx |
push -'0' |
.l1: xor edx,edx |
div ecx |
push edx |
test eax,eax |
jnz .l1 |
.l2: pop eax |
add al,'0' |
jz .l3 |
call fdo_debug_outchar |
jmp .l2 |
.l3: ret |
debug_endf |
debug_func fdo_debug_outhex |
__fdo_hexdigits db '0123456789ABCDEF' |
debug_beginf |
mov cl,dl |
neg cl |
add cl,8 |
shl cl,2 |
rol eax,cl |
.l1: rol eax,4 |
push eax |
and eax,0x0000000F |
mov al,[__fdo_hexdigits+eax] |
call fdo_debug_outchar |
pop eax |
dec edx |
jnz .l1 |
ret |
debug_endf |
;----------------------------------------------------------------------------- |
macro DEBUGF _level,_format,[_arg] { |
common |
if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__ |
local ..f1,f2,a1,a2,c1,c2,c3,..lbl |
_debug_str_ equ __debug_str_ # a1 |
a1 = 0 |
c2 = 0 |
c3 = 0 |
f2 = 0 |
repeat ..lbl-..f1 |
virtual at 0 |
db _format,0,0 |
load c1 word from %-1 |
end virtual |
if c1 = '%s' |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER S,a1,0,_arg |
else if c1 = '%x' |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER H,a1,0,_arg |
else if c1 = '%d' | c1 = '%u' |
local c4 |
if c1 = '%d' |
c4 = 1 |
else |
c4 = 0 |
end if |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER D,a1,c4,_arg |
else if c1 = '\n' |
c3 = c3 + 1 |
end if |
end repeat |
virtual at 0 |
db _format,0,0 |
load c1 from f2-c2 |
end virtual |
if (c1<>0)&(f2<>..lbl-..f1-1) |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
virtual at 0 |
..f1 db _format,0 |
..lbl: |
__debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3 |
end virtual |
end if |
} |
macro __include_debug_strings dummy,[_id,_fmt,_len] { |
common |
local c1,a1,a2 |
forward |
if defined _len & ~_len eq |
_id: |
a1 = 0 |
a2 = 0 |
repeat _len |
virtual at 0 |
db _fmt,0,0 |
load c1 word from %+a2-1 |
end virtual |
if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u') |
db 0 |
a2 = a2 + 1 |
else if (c1='\n') |
dw $0A0D |
a1 = a1 + 1 |
a2 = a2 + 1 |
else |
db c1 and 0x0FF |
end if |
end repeat |
db 0 |
end if |
} |
macro DEBUGF_HELPER _letter,_num,_sign,[_arg] { |
common |
local num |
num = 0 |
forward |
if num = _num |
DEBUG#_letter _sign,_arg |
end if |
num = num+1 |
common |
_num = _num+1 |
} |
macro include_debug_strings { |
if __DEBUG__ = 1 |
match dbg_str,__debug_strings \{ |
__include_debug_strings dbg_str |
\} |
end if |
} |
/programs/network/zeroconf/trunk/dhcp.inc |
---|
0,0 → 1,263 |
;Name Number Length Meaning |
dhcp_pad_option equ 0 ; 0 None |
dhcp_end_option equ 255 ; 0 None |
dhcp_subnet_mask equ 1 ; 4 Subnet Mask Value |
dhcp_time_offset equ 2 ; 4 Time Offset in Seconds from UTC |
dhcp_router equ 3 ; N×4 Router addresses |
dhcp_time_server equ 4 ; N×4 Timeserver addresses |
dhcp_name_server equ 5 ; N×4 IEN-116 Server addresses |
dhcp_domain_server equ 6 ; N×4 DNS Server addresses |
dhcp_log_server equ 7 ; N×4 Logging Server addresses |
dhcp_quotes_server equ 8 ; N×4 Quotes Server addresses |
dhcp_lpr_server equ 9 ; N×4 Printer Server addresses |
dhcp_impress_server equ 10 ; N×4 Impress Server addresses |
dhcp_rlp_server equ 11 ; N×4 N RLP Server addresses |
dhcp_hostname equ 12 ; N Hostname string |
dhcp_boot_file_size equ 13 ; 2 Size of boot file in 512-octet blocks |
dhcp_merit_dump_file equ 14 ; N Client to dump and name the file to dump it to |
dhcp_domain_name equ 15 ; N The DNS domain name of the client |
dhcp_swap_server equ 16 ; 4 Swap Server address |
dhcp_root_path equ 17 ; N Path name for root disk |
dhcp_extension_file equ 18 ; N Path name for more BOOTP info |
;IP Layer Parameters per Host |
dhcp_forward equ 19 ; 1 Enable/Disable IP Forwarding |
dhcp_srcrte equ 20 ; 1 Enable/Disable Non-Local Source Routing |
dhcp_policy equ 21 ; N×8 Non-Local Source Routing Policy Filters |
dhcp_mag_dg_assembly equ 22 ; 2 Max Datagram Reassembly Size |
dhcp_default_ip_tll equ 23 ; 1 Default IP Time to Live |
dhcp_mtu_timeout equ 24 ; 4 Path MTU Aging Timeout |
dhcp_mtu_plateau equ 25 ; N×2 Path MTU Plateau Table |
;IP Layer Parameters per Interface |
dhcp_mtu_interface equ 26 ; 2 Interface MTU Size |
dhcp_mtu_subnet equ 27 ; 1 All Subnets are Local |
dhcp_broadcast_address equ 28 ; 4 Broadcast Address |
dhcp_mask_discovery equ 29 ; 1 Perform Mask Discovery |
dhcp_mask_supplier equ 30 ; 1 Provide Mask to Others |
dhcp_router_discovery equ 31 ; 1 Perform Router Discovery |
dhcp_router_request equ 32 ; 4 Router Solicitation Address |
dhcp_static_route equ 33 ; N×8 Static Routing Table |
;Link Layer Parameters per Interface |
dhcp_trailers equ 34 ; 1 Trailer Encapsulation |
dhcp_arp_timeout equ 35 ; 4 ARP Cache Timeout |
dhcp_ethernet equ 36 ; 1 Ethernet Encapsulation |
;TCP Parameters |
dhcp_default_tcp_tll equ 37 ; 1 Default TCP Time to Live |
dhcp_keepalive_time equ 38 ; 4 TCP Keepalive Interval |
dhcp_keepalive_data equ 39 ; 1 TCP Keepalive Garbage |
;Application and Service Parameters |
dhcp_nis_domain equ 40 ; N NIS Domain Name |
dhcp_nis_servers equ 41 ; N×4 NIS Server Addresses |
dhcp_ntp_servers equ 42 ; N×4 NTP Server Addresses |
dhcp_vendor_specific equ 43 ; N Vendor Specific Information |
dhcp_netbios_name_srv equ 44 ; N×4 NETBIOS Name Servers |
dhcp_netbios_dist_srv equ 45 ; N×4 NETBIOS Datagram Distribution |
dhcp_netbios_node_type equ 46 ; 1 NETBIOS Node Type |
dhcp_netbios_scope equ 47 ; N NETBIOS Scope |
dhcp_x_window_font equ 48 ; N×4 X Window Font Server |
dhcp_x_window_manager equ 49 ; N×4 X Window Display Manager |
dhcp_nis_domain_name equ 64 ; N NIS+ v3 Client Domain Name |
dhcp_nis_server_addr equ 65 ; N×4 NIS+ v3 Server Addresses |
dhcp_home_agent_addrs equ 68 ; N×4 Mobile IP Home Agent Addresses |
dhcp_smtp_server equ 69 ; N×4 Simple Mail Server Addresses |
dhcp_pop3_server equ 70 ; N×4 Post Office Server Addresses |
dhcp_nntp_server equ 71 ; N×4 Network News Server Addresses |
dhcp_www_server equ 72 ; N×4 WWW Server Addresses |
dhcp_finger_server equ 73 ; N×4 Finger Server Addresses |
dhcp_irc_server equ 74 ; N×4 Chat Server Addresses |
dhcp_streettalk_server equ 75 ; N×4 StreetTalk Server Addresses |
dhcp_stda_server equ 76 ; N×4 ST Directory Assist. Addresses |
;DHCP Extensions |
dhcp_address_request equ 50 ; 4 Requested IP Address |
dhcp_address_time equ 51 ; 4 IP Address Lease Time |
dhcp_option_overload equ 52 ; 1 Overload "sname" or "file" |
dhcp_msg_type equ 53 ; 1 DHCP Message Type |
dhcp_dhcp_server_id equ 54 ; 4 DHCP Server Identification |
dhcp_parameter_list equ 55 ; N Parameter Request List |
dhcp_dhcp_message equ 56 ; N DHCP Error Message |
dhcp_dhcp_max_msg_size equ 57 ; 2 DHCP Maximum Message Size |
dhcp_renewal_time equ 58 ; 4 DHCP Renewal (T1) Time |
dhcp_rebinding_time equ 59 ; 4 DHCP Rebinding (T2) Time |
dhcp_class_id equ 60 ; N Vendor Class Identifier |
dhcp_client_id equ 61 ; N Client Identifier |
dhcp_server_name equ 66 ; N TFTP Server Name |
dhcp_bootfile_name equ 67 ; N Boot File Name |
;Newer extensions |
dhcp_netware_ip_domain equ 62 ; N Netware/IP Domain Name |
dhcp_netware_ip_option equ 63 ; N Netware/IP sub Options |
dhcp_user_class equ 77 ; N User Class Information |
dhcp_directory_agent equ 78 ; N directory agent information |
dhcp_service_scope equ 79 ; N service location agent scope |
dhcp_rapid_commit equ 80 ; 0 Rapid Commit |
dhcp_client_fqdn equ 81 ; N Fully Qualified Domain Name |
dhcp_relay_agent_info equ 82 ; N Relay Agent Information, RFC 3046 |
dhcp_isns equ 83 ; N Internet Storage Name Service |
; 84 REMOVED/Unassigned |
dhcp_nds_servers equ 85 ; N Novell Directory Services |
dhcp_nds_tree_name equ 86 ; N Novell Directory Services |
dhcp_nds_conext equ 87 ; N Novell Directory Services |
dhcp_bcmcs equ 88 ; Controller Domain Name list |
dhcp_bcmcs equ 89 ; Controller IPv4 address option |
dhcp_authentication equ 90 ; N Authentication |
; 91 REMOVED/Unassigned |
; 92 REMOVED/Unassigned |
dhcp_client_system equ 93 ; N Client System Architecture |
dhcp_client_ndi equ 94 ; N Client Network Device Interface |
dhcp_ldap equ 95 ; N Lightweight Directory Access Protocol |
; 96 REMOVED/Unassigned |
dhcp_uuid_guid equ 97 ; N UUID/GUID-based Client Identifier |
dchp_user_auth equ 98 ; N Open Group's User Authentication |
; 99 REMOVED/Unassigned |
; 100 REMOVED/Unassigned |
; 101 REMOVED/Unassigned |
; 102 REMOVED/Unassigned |
; 103 REMOVED/Unassigned |
; 104 REMOVED/Unassigned |
; 105 REMOVED/Unassigned |
; 106 REMOVED/Unassigned |
; 107 REMOVED/Unassigned |
; 108 REMOVED/Unassigned |
; 109 REMOVED/Unassigned |
; 110 REMOVED/Unassigned |
; 111 REMOVED/Unassigned |
dhcp_netinfo_address equ 112 ; N NetInfo Parent Server Address |
dhcp_netinfo_tag equ 113 ; N NetInfo Parent Server Tag |
dhcp_url equ 114 ; N URL |
; 115 REMOVED/Unassigned |
dhcp_auto_config equ 116 ; N DHCP Auto-Configuration |
dhcp_ns_search equ 117 ; N Name Service Search |
dhcp_subnet_selection equ 118 ; 4 Subnet Selection Option |
dhcp_domain_search equ 119 ; N DNS domain search list |
dhcp_sip_servers equ 120 ; N SIP Servers DHCP Option |
dhcp_cl_static_route equ 121 ; N Classless Static Route Option |
dhcp_ccc equ 122 ; N CableLabs Client Configuration |
dhcp_geoconf equ 123 ; 16 GeoConf Option |
dhcp_v_i_vendor_class equ 124 ; Vendor-Identifying Vendor Class |
dhcp_v_i_vendor_spec equ 125 ; Vendor-Identifying Vendor-Specific |
; 126 REMOVED/Unassigned |
; 127 REMOVED/Unassigned |
dhcp_pxe equ 128 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_etherboot_sign equ 128 ; Etherboot signature. 6 bytes: E4:45:74:68:00:00 |
dhcp_docsis equ 128 ; DOCSIS "full security" server IP address |
dhcp_tftp_server_ip equ 128 ; TFTP Server IP address (for IP Phone software load) |
dhcp_pxe equ 129 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_kernel_options equ 129 ; Kernel options. Variable length string |
dhcp_call_server_ip equ 129 ; Call Server IP address |
dhcp_pxe equ 130 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_ethernet_interface equ 130 ; Ethernet interface. Variable length string. |
dhcp_siscrimination equ 130 ; Discrimination string (to identify vendor) |
dhcp_pxe equ 131 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_remote_stat_server equ 131 ; Remote statistics server IP address |
dhcp_pxe equ 132 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_802.1p equ 132 ; 802.1P VLAN ID |
dhcp_pxe equ 133 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_802.1q equ 133 ; 802.1Q L2 Priority |
dhcp_pxe equ 134 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_diffserv equ 134 ; Diffserv Code Point |
dhcp_pxe equ 135 ; PXE - undefined (vendor specific) (Tentatively Assigned - 23 June 2005) |
dhcp_http_proxy_psa equ 135 ; HTTP Proxy for phone-specific applications |
; 136 REMOVED/Unassigned |
; 137 REMOVED/Unassigned |
; 138 REMOVED/Unassigned |
; 139 REMOVED/Unassigned |
; 140 REMOVED/Unassigned |
; 141 REMOVED/Unassigned |
; 142 REMOVED/Unassigned |
; 143 REMOVED/Unassigned |
; 144 REMOVED/Unassigned |
; 145 REMOVED/Unassigned |
; 146 REMOVED/Unassigned |
; 147 REMOVED/Unassigned |
; 148 REMOVED/Unassigned |
; 149 REMOVED/Unassigned |
dhcp_tftp_server_addr equ 150 ; TFTP server address (Tentatively Assigned - 23 June 2005) |
dhcp_etherboot equ 150 ; Etherboot |
dhcp_grub_conf_path equ 150 ; GRUB configuration path name |
; 151 REMOVED/Unassigned |
; 152 REMOVED/Unassigned |
; 153 REMOVED/Unassigned |
; 154 REMOVED/Unassigned |
; 155 REMOVED/Unassigned |
; 156 REMOVED/Unassigned |
; 157 REMOVED/Unassigned |
; 158 REMOVED/Unassigned |
; 159 REMOVED/Unassigned |
; 160 REMOVED/Unassigned |
; 161 REMOVED/Unassigned |
; 162 REMOVED/Unassigned |
; 163 REMOVED/Unassigned |
; 164 REMOVED/Unassigned |
; 165 REMOVED/Unassigned |
; 166 REMOVED/Unassigned |
; 167 REMOVED/Unassigned |
; 168 REMOVED/Unassigned |
; 169 REMOVED/Unassigned |
; 170 REMOVED/Unassigned |
; 171 REMOVED/Unassigned |
; 172 REMOVED/Unassigned |
; 173 REMOVED/Unassigned |
; 174 REMOVED/Unassigned |
dhcp_etherboot equ 175 ; Etherboot (Tentatively Assigned - 23 June 2005) |
dhcp_ip_telephone equ 176 ; IP Telephone (Tentatively Assigned - 23 June 2005) |
dhcp_etherboot equ 177 ; Etherboot (Tentatively Assigned - 23 June 2005) |
dhcp_packetcable equ 177 ; PacketCable and CableHome (replaced by 122) |
; 178 REMOVED/Unassigned |
; 179 REMOVED/Unassigned |
; 180 REMOVED/Unassigned |
; 181 REMOVED/Unassigned |
; 182 REMOVED/Unassigned |
; 183 REMOVED/Unassigned |
; 184 REMOVED/Unassigned |
; 185 REMOVED/Unassigned |
; 186 REMOVED/Unassigned |
; 187 REMOVED/Unassigned |
; 188 REMOVED/Unassigned |
; 189 REMOVED/Unassigned |
; 190 REMOVED/Unassigned |
; 191 REMOVED/Unassigned |
; 192 REMOVED/Unassigned |
; 193 REMOVED/Unassigned |
; 194 REMOVED/Unassigned |
; 195 REMOVED/Unassigned |
; 196 REMOVED/Unassigned |
; 197 REMOVED/Unassigned |
; 198 REMOVED/Unassigned |
; 199 REMOVED/Unassigned |
; 200 REMOVED/Unassigned |
; 201 REMOVED/Unassigned |
; 202 REMOVED/Unassigned |
; 203 REMOVED/Unassigned |
; 204 REMOVED/Unassigned |
; 205 REMOVED/Unassigned |
; 206 REMOVED/Unassigned |
; 207 REMOVED/Unassigned |
dhcp_pxelinux.magic equ 208 ; pxelinux.magic (string) = F1:00:74:7E (241.0.116.126) (Tentatively Assigned - 23 June 2005) |
dhcp_pxelinux.conffile equ 209 ; pxelinux.configfile (text) (Tentatively Assigned - 23 June 2005) |
dhcp_pxelinux.path equ 210 ; pxelinux.pathprefix (text) (Tentatively Assigned - 23 June 2005) |
dhcp_pxelinux.reboot equ 211 ; pxelinux.reboottime (unsigned integer 32 bits) (Tentatively Assigned - 23 June 2005) |
; 212 REMOVED/Unassigned |
; 213 REMOVED/Unassigned |
; 214 REMOVED/Unassigned |
; 215 REMOVED/Unassigned |
; 216 REMOVED/Unassigned |
; 217 REMOVED/Unassigned |
; 218 REMOVED/Unassigned |
; 219 REMOVED/Unassigned |
dhcp_subnet_aloc equ 220 ; Subnet Allocation Option (Tentatively Assigned - 23 June 2005) |
dhcp_virtual_subnet equ 221 ; Virtual Subnet Selection Option (Tentatively Assigned - 23 June 2005) |
; 222 REMOVED/Unassigned |
; 223 REMOVED/Unassigned |
/programs/network/zeroconf/trunk/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 |
/programs/network/zeroconf/trunk/zeroconf.asm |
---|
0,0 → 1,498 |
; Zero-config |
; v 1.4 |
; |
; DHCP code is based on that by Mike Hibbet (DHCP client for menuetos) |
; |
; Written by HidnPlayr & Derpenguin |
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 ; memory for app |
dd I_END ; esp |
dd 0x0 , path ; I_Param , I_Icon |
; CONFIGURATION |
TIMEOUT equ 60 ; in seconds |
BUFFER equ 1024 ; in bytes |
__DEBUG__ equ 1 ; enable/disable |
__DEBUG_LEVEL__ equ 1 ; 1 = all, 2 = errors |
; CONFIGURATION FOR LINK-LOCAL |
PROBE_WAIT equ 1 ; second (initial random delay) |
PROBE_MIN equ 1 ; second (minimum delay till repeated probe) |
PROBE_MAX equ 2 ; seconds (maximum delay till repeated probe) |
PROBE_NUM equ 3 ; (number of probe packets) |
ANNOUNCE_NUM equ 2 ; (number of announcement packets) |
ANNOUNCE_INTERVAL equ 2 ; seconds (time between announcement packets) |
ANNOUNCE_WAIT equ 2 ; seconds (delay before announcing) |
MAX_CONFLICTS equ 10 ; (max conflicts before rate limiting) |
RATE_LIMIT_INTERVAL equ 60 ; seconds (delay between successive attempts) |
DEFEND_INTERVAL equ 10 ; seconds (min. wait between defensive ARPs) |
include '../../../proc32.inc' |
include '../../../macros.inc' |
include 'eth.inc' |
include 'debug-fdo.inc' |
include 'dhcp.inc' |
include 'dll.inc' |
START: ; start of execution |
mcall 40, 0 |
eth.set_network_drv 0x00000383 |
DEBUGF 1,"Zero-config service:\n" |
eth.status eax ; Read the Stack status |
test eax,eax ; if eax is zero, no driver was found |
jnz @f |
DEBUGF 1,"No Card found!\n" |
jmp close |
@@: |
DEBUGF 1,"Detected card: %x\n",eax |
@@: |
eth.check_cable eax |
test al,al |
jnz @f |
DEBUGF 1,"Cable disconnected!\n" |
mcall 5, 500 ; loop until cable is connected (check every 5 sec) |
jmp @r |
@@: |
eth.read_mac MAC |
DEBUGF 1,"MAC: %x-%x-%x-%x-%x-%x\n",[MAC]:2,[MAC+1]:2,[MAC+2]:2,[MAC+3]:2,[MAC+4]:2,[MAC+5]:2 |
cld |
mov edi, path ; Calculate the length of zero-terminated string |
xor al , al |
mov ecx, 1024 |
repnz scas byte[es:edi] |
dec edi |
mov esi, filename |
mov ecx, 5 |
rep movsb |
mcall 64,1,I_END_2 |
mcall 68,11 |
stdcall dll.Load,@IMPORT |
or eax,eax |
jnz skip_ini |
invoke ini.get_str, path, str_ipconfig, str_type, inibuf, 16, 0 |
mov eax,dword[inibuf] |
cmp eax,'stat' |
jne skip_ini |
invoke ini.get_str, path, str_ipconfig, str_ip, inibuf, 16, 0 |
mov edx, inibuf |
call Ip2dword |
eth.set_IP edx |
invoke ini.get_str, path, str_ipconfig, str_gateway, inibuf, 16, 0 |
mov edx, inibuf |
call Ip2dword |
eth.set_GATEWAY edx |
invoke ini.get_str, path, str_ipconfig, str_dns, inibuf, 16, 0 |
mov edx, inibuf |
call Ip2dword |
eth.set_DNS edx |
invoke ini.get_str, path, str_ipconfig, str_subnet, inibuf, 16, 0 |
mov edx, inibuf |
call Ip2dword |
eth.set_SUBNET edx |
mcall -1 |
skip_ini: |
eth.check_port 68,eax ; Check if port 68 is available |
cmp eax,1 |
je @f |
DEBUGF 1,"Port 68 is already in use!\n" |
jmp close |
@@: |
eth.open_udp 68,67,-1,[socketNum] ; open socket (local,remote,ip,socket) |
; Setup the first msg we will send |
mov byte [dhcpMsgType], 0x01 ; DHCP discover |
mov dword [dhcpLease], esi ; esi is still -1 (-1 = forever) |
mcall 26, 9 |
imul eax,100 |
mov [currTime],eax |
buildRequest: ; Creates a DHCP request packet. |
stdcall mem.Alloc, BUFFER |
mov [dhcpMsg], eax |
test eax,eax |
jz apipa |
mov edi, eax |
mov ecx,BUFFER |
xor eax,eax |
cld |
rep stosb |
mov edx,[dhcpMsg] |
mov [edx], byte 0x01 ; Boot request |
mov [edx+1], byte 0x01 ; Ethernet |
mov [edx+2], byte 0x06 ; Ethernet h/w len |
mov [edx+4], dword 0x11223344 ; xid |
mov eax,[currTime] |
mov [edx+8], eax ; secs, our uptime |
mov [edx+10], byte 0x80 ; broadcast flag set |
mov eax, dword [MAC] ; first 4 bytes of MAC |
mov [edx+28],dword eax |
mov ax, word [MAC+4] ; last 2 bytes of MAC |
mov [edx+32],word ax |
mov [edx+236], dword 0x63538263 ; magic number |
mov [edx+240], word 0x0135 ; option DHCP msg type |
mov al, [dhcpMsgType] |
mov [edx+240+2], al |
mov [edx+240+3], word 0x0433 ; option Lease time = infinity |
mov eax, [dhcpLease] |
mov [edx+240+5], eax |
mov [edx+240+9], word 0x0432 ; option requested IP address |
mov eax, [dhcpClientIP] |
mov [edx+240+11], eax |
mov [edx+240+15], word 0x0437 ; option request list |
mov [edx+240+17], dword 0x0f060301 |
cmp [dhcpMsgType], byte 0x01 ; Check which msg we are sending |
jne request_options |
mov [edx+240+21], byte 0xff ; "Discover" options |
mov [dhcpMsgLen], dword 262 ; end of options marker |
jmp send_request |
request_options: |
mov [edx+240+21], word 0x0436 ; server IP |
mov eax, [dhcpServerIP] |
mov [edx+240+23], eax |
mov [edx+240+27], byte 0xff ; end of options marker |
mov [dhcpMsgLen], dword 268 |
send_request: |
eth.write_udp [socketNum],[dhcpMsgLen],[dhcpMsg] ; write to socket ( send broadcast request ) |
mov eax, [dhcpMsg] ; Setup the DHCP buffer to receive response |
mov [dhcpMsgLen], eax ; Used as a pointer to the data |
mov eax,23 ; wait here for event (data from remote) |
mov ebx,TIMEOUT*10 |
mcall |
eth.poll [socketNum] |
test eax,eax |
jnz read_data |
DEBUGF 2,"Timeout!\n" |
eth.close_udp [socketNum] |
jmp apipa ; no server found, lets try zeroconf |
read_data: ; we have data - this will be the response |
eth.read_packet [socketNum], [dhcpMsg], BUFFER |
mov [dhcpMsgLen], eax |
eth.close_udp [socketNum] |
; depending on which msg we sent, handle the response |
; accordingly. |
; If the response is to a dhcp discover, then: |
; 1) If response is DHCP OFFER then |
; 1.1) record server IP, lease time & IP address. |
; 1.2) send a request packet |
; If the response is to a dhcp request, then: |
; 1) If the response is DHCP ACK then |
; 1.1) extract the DNS & subnet fields. Set them in the stack |
cmp [dhcpMsgType], byte 0x01 ; did we send a discover? |
je discover |
cmp [dhcpMsgType], byte 0x03 ; did we send a request? |
je request |
jmp close ; really unknown, what we did |
discover: |
call parseResponse |
cmp [dhcpMsgType], byte 0x02 ; Was the response an offer? |
jne apipa ; NO - so we do zeroconf |
mov [dhcpMsgType], byte 0x03 ; DHCP request |
jmp buildRequest |
request: |
call parseResponse |
cmp [dhcpMsgType], byte 0x05 ; Was the response an ACK? It should be |
jne apipa ; NO - so we do zeroconf |
jmp close |
;*************************************************************************** |
; Function |
; parseResponse |
; |
; Description |
; extracts the fields ( client IP address and options ) from |
; a DHCP response |
; The values go into |
; dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP, |
; dhcpDNSIP, dhcpSubnet |
; The message is stored in dhcpMsg |
; |
;*************************************************************************** |
parseResponse: |
DEBUGF 1,"Data received, parsing response\n" |
mov edx, [dhcpMsg] |
pusha |
eth.set_IP [edx+16] |
mov eax,[edx] |
mov [dhcpClientIP],eax |
DEBUGF 1,"Client: %u.%u.%u.%u\n",[edx+16]:1,[edx+17]:1,[edx+18]:1,[edx+19]:1 |
popa |
add edx, 240 ; Point to first option |
xor ecx, ecx |
next_option: |
add edx, ecx |
pr001: |
mov al, [edx] |
cmp al, 0xff ; End of options? |
je pr_exit |
cmp al, dhcp_msg_type ; Msg type is a single byte option |
jne @f |
mov al, [edx+2] |
mov [dhcpMsgType], al |
add edx, 3 |
jmp pr001 ; Get next option |
@@: |
inc edx |
movzx ecx, byte [edx] |
inc edx ; point to data |
cmp al, dhcp_dhcp_server_id ; server ip |
jne @f |
mov eax, [edx] |
mov [dhcpServerIP], eax |
DEBUGF 1,"Server: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
jmp next_option |
@@: |
cmp al, dhcp_address_time |
jne @f |
pusha |
mov eax,[edx] |
bswap eax |
mov [dhcpLease],eax |
DEBUGF 1,"lease: %d\n",eax |
popa |
jmp next_option |
@@: |
cmp al, dhcp_subnet_mask |
jne @f |
pusha |
eth.set_SUBNET [edx] |
DEBUGF 1,"Subnet: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
popa |
jmp next_option |
@@: |
cmp al, dhcp_router |
jne @f |
pusha |
eth.set_GATEWAY [edx] |
DEBUGF 1,"Gateway: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
popa |
jmp next_option |
@@: |
cmp al, dhcp_domain_server |
jne next_option |
pusha |
eth.set_DNS [edx] |
DEBUGF 1,"DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
popa |
jmp next_option |
pr_exit: |
; DEBUGF 1,"Sending ARP announce\n" |
; eth.ARP_ANNOUNCE [dhcpClientIP] ; send an ARP announce packet |
jmp close |
apipa: |
stdcall mem.Free, [dhcpMsg] |
link_local: |
call random |
mov ecx,0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 |
mov cx,ax |
eth.set_IP ecx ; mask is 255.255.0.0 |
DEBUGF 1,"Link Local IP assinged: 169.254.%u.%u\n",[generator+2]:1,[generator+3]:1 |
eth.set_SUBNET 0xffff |
eth.set_GATEWAY 0x0 |
eth.set_DNS 0x0 |
mcall 5, PROBE_WAIT*100 |
xor esi,esi |
probe_loop: |
call random ; create a pseudo random number in eax (seeded by MAC) |
cmp al,PROBE_MIN*100 ; check if al is bigger then PROBE_MIN |
jge @f ; all ok |
add al,(PROBE_MAX-PROBE_MIN)*100 ; al is too small |
@@: |
cmp al,PROBE_MAX*100 |
jle @f |
sub al,(PROBE_MAX-PROBE_MIN)*100 |
@@: |
movzx ebx,al |
DEBUGF 1,"Waiting %u0ms\n",ebx |
mcall 5 |
DEBUGF 1,"Sending Probe\n" |
; eth.ARP_PROBE MAC |
inc esi |
cmp esi,PROBE_NUM |
jl probe_loop |
; now we wait further ANNOUNCE_WAIT seconds and send ANNOUNCE_NUM ARP announces. If any other host has assingned |
; IP within this time, we should create another adress, that have to be done later |
DEBUGF 1,"Waiting %us\n",ANNOUNCE_WAIT |
mcall 5, ANNOUNCE_WAIT*100 |
xor esi,esi |
announce_loop: |
DEBUGF 1,"Sending Announce\n" |
; eth.ARP_ANNOUNCE MAC |
inc esi |
cmp esi,ANNOUNCE_NUM |
je @f |
DEBUGF 1,"Waiting %us\n",ANNOUNCE_INTERVAL |
mcall 5, ANNOUNCE_INTERVAL*100 |
jmp announce_loop |
@@: |
; we should, instead of closing, detect ARP conflicts and detect if cable keeps connected ;) |
close: |
mcall -1 |
random: ; Pseudo random actually |
mov eax,[generator] |
add eax,-43ab45b5h |
ror eax,1 |
bswap eax |
xor eax,dword[MAC] |
ror eax,1 |
xor eax,dword[MAC+2] |
mov [generator],eax |
ret |
; DATA AREA |
align 16 |
@IMPORT: |
library \ |
libini,'libini.obj' |
import libini, \ |
ini.get_str,'ini.get_str',\ |
ini.set_str,'ini.set_str',\ |
ini.get_int,'ini.get_int',\ |
ini.set_int,'ini.set_int',\ |
ini.enum_sections,'ini.enum_sections',\ |
ini.enum_keys,'ini.enum_keys' |
include_debug_strings |
filename db '.ini',0 |
str_ip db 'ip',0 |
str_subnet db 'subnet',0 |
str_gateway db 'gateway',0 |
str_dns db 'dns',0 |
str_ipconfig db 'ipconfig',0 |
str_type db 'type',0 |
IM_END: |
inibuf rb 16 |
dhcpClientIP dd ? |
dhcpMsgType db ? |
dhcpLease dd ? |
dhcpServerIP dd ? |
dhcpMsgLen dd ? |
socketNum dd ? |
MAC dp ? |
currTime dd ? |
renewTime dd ? |
generator dd ? |
dhcpMsg dd ? |
I_END_2: |
path rb 1024+5 |
I_END: |
/programs/network/zeroconf/trunk/zeroconf.ini |
---|
0,0 → 1,9 |
[ipconfig] |
; type should be static or zeroconf |
; zeroconf means the service first tries to contact a DHCP server |
; If dhcp is not available, it switches to link-local |
type = static |
ip = 192.168.1.150 |
gateway = 192.168.1.1 |
dns = 192.168.1.1 |
subnet = 255.255.255.0 |
/programs/network/zeroconf/trunk |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |
/programs/network/zeroconf |
---|
Property changes: |
Added: tsvn:logminsize |
+5 |
\ No newline at end of property |