flat assembler
Message board for the users of flat assembler.
Index
> MenuetOS > Convert INTERNETBYTEORDER to dotted-decimal notation |
Author |
|
crisher 17 Oct 2018, 20:40
Code: server_loop: call get_local_port ; from syscall mov [lport], rax mov rax, 53; open socket-passive mov rbx, 5 mov rcx, [lport] ; previously done xor rdx, rdx ; any remote port to xor rsi, rsi ; any remote ip to xor rdi, rdi; rdi=0=passive cmp eax, 0xffffffff je error_open_sock ; print error while opening socket .... print: listening on <IP> on port <port> mov rdx, mode_listen mov r8 , mle - mode_listen call print_to_terminal mov rax, 52 mov rbx, 1 int 0x60 mov [local_ip], rax mov rsi, [local_ip] mov rsi, [local_ip] mov rdi, str_local_ip call i2a ; fucntion integer to ascii mov rdx, str_local_ip mov r8 , 9 call print_to_terminal mov [rdx], dword ' on ' mov [rdx+4], dword ' port' mov [rdx+8], byte 32 mov r8 , 9 call print_to_terminal mov rsi, [lport] mov rdi, str_lport call i2a mov rdx, str_lport mov r8 , 6 call print_to_terminal ret ; i2a( rdi=buffer, rsi=integer) ; print_to_terminal( rdx=str_buffer, r8=len_str_buffer) [img] [/img] the troubleis, i dont know how convert this IP number to 'standard' IP like: a.b.c.d[/code]
|
||||||||||
17 Oct 2018, 20:40 |
|
revolution 18 Oct 2018, 01:05
Do you mean you want to convert 0xc0a80001 to "192.168.0.1"?
If so then you can take each of the four bytes and convert to an unsigned decimal string. If you have access to a printf function then something like this pseudo code might work Code: mov rax,0xc0a80001 ;192.168.0.1 ror eax,8 movzx r9,al ;r9=0x00 shr eax,8 movzx r8,al ;r8=0xa8 shr eax,8 movzx rdx,al ;rdx=0xc0 shr eax,8 ;rax=0x01 fastcall printf,"%u.%u.%u.%u",rdx,r8,r9,rax ;print "192.168.0.1" |
|||
18 Oct 2018, 01:05 |
|
Ville 18 Oct 2018, 08:59
The IP address is saved to the register in reversed byte order. The most significant byte of the IP is saved to the least significant byte of the register. So for example 192.168.0.1 would be 0x0100a8c0 in the register.
|
|||
18 Oct 2018, 08:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.