Commits

Paweł Wieczorek committed a8cc596 Draft

add sockaddr_in filler

  • Participants
  • Parent commits 96d5295

Comments (0)

Files changed (3)

 .endm
 
 .macro LOCAL_PROC name
+.local \name
 \name:
 .endm
 .text
 
 GLOBAL_PROC main
-    FRAME_ENTER
+    FRAME_ENTER size=16
     mov $0x40, %rdi
     call mem_alloc
     mov %rax, %rdi
 
-    call proof_of_concept
+    lea -4(%rbp),   %r15
+    call sock_create
 
     call mem_release
     mov $0x0, %rax
 ##########################################################################
 # SECTION TEXT
 ##########################################################################
-.text
+.section .text
 
 # SOCKET_T
 # [long sock] - 4bytes
 # sock_create(SOCKET_T &sock)
 GLOBAL_PROC sock_create
     FRAME_ENTER
-    mov %rdi,         %r15
-    mov $PF_INET,     %rdi
-    mov $SOCK_STREAM, %rsi
-    mov $IPPROTO_TCP, %rdx
-    call socket
-    mov %rax, (%r15)
+    mov     %rdi,           %r15
+    mov     $PF_INET,       %rdi
+    mov     $SOCK_STREAM,   %rsi
+    mov     $IPPROTO_TCP,   %rdx
+    call    socket
+    mov     %rax,           (%r15)
     FRAME_LEAVE
 
 GLOBAL_PROC sock_destroy
 
 GLOBAL_PROC sock_listen
     FRAME_ENTER
-    mov (%rdi),      %rdi
+    mov     (%rdi),      %rdi
     call listen
     FRAME_LEAVE
 
-# helper 
-GLOBAL_PROC sockaddr_in_create
+# helper
+# void fill_sockaddr(sockaddr_in *saddr, const char *addr, int port)
+GLOBAL_PROC fill_sockaddr_in
+    # sockaddr_in *%rdi  saddr
+    # const char  *%rsi  ipaddr
+    # int          %rdx  port
+    FRAME_ENTER
+    # Linux [sockaddr_in]
+    # { +0  [2b]    socket family]
+    #   +2  [2b]    port]
+    #   +4  [4b]    addr]
+    #   +8  [12b]   unused
+    # }
+
+    mov     %rdi,       %r15
+    mov     %rsi,       %rdi
+    movw    $PF_INET,   0x0(%r15)
+    movw    %rdx,       0x2(%r15)
+    call    inet_addr
+    mov     %rax,       0x4(%r15)
+    FRAME_LEAVE
 
 ##########################################################################
 # SECTION TEXT
 ##########################################################################
-.data
+.section .data
 
 # Linux
 .set PF_INET, 2
 .set SOCK_STREAM, 1
 .set IPPROTO_TCP, 6
+
+.set SOCKADDR_IN_SIZE, 16
+
+
+