flat assembler
Message board for the users of flat assembler.

Index > MenuetOS > Convert INTERNETBYTEORDER to dotted-decimal notation

Author
Thread Post new topic Reply to topic
crisher



Joined: 12 Oct 2018
Posts: 3
crisher 12 Oct 2018, 22:03
HI, i would like to know how to do this pls.

Get Local IP Address
--------------------
rax = 52
rbx = 1

IP address returned in rax ( in internet byte order )

I want to return string ip, for then to display on window-terminal

thanx in advance.
Post 12 Oct 2018, 22:03
View user's profile Send private message Reply with quote
crisher



Joined: 12 Oct 2018
Posts: 3
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]


Description:
Filesize: 205.09 KB
Viewed: 10403 Time(s)

Screenshot_20181017_213409.png


Post 17 Oct 2018, 20:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
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"    
Post 18 Oct 2018, 01:05
View user's profile Send private message Visit poster's website Reply with quote
Ville



Joined: 17 Jun 2003
Posts: 308
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.
Post 18 Oct 2018, 08:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.