我正在尝试为交换数据创建一个tcp客户端。客户端应首先发送消息。如果消息正确,并且用户已获得财产授权,系统将回复消息“确认”,确认会话已成功绑定。
;; yasm -g dwarf2 -f elf64 -a x86 message.asm -o msg.o
;; ld -o msg msg.o
segment .bss
listen_socket: resq 1
read_fdset: resb 2
segment .data
packet istruc message
at message.length_mes, dw 0x2800
at message.message_id, dw 0x0100
at message.scheme_id, dw 0x0100
at message.version, dw 0x0100
at message.timestamp, dq 0
at message.keeepaliveinterval, dd 0xe8030000
at message.credentials, dq 0
at message.ext, dw 0
iend
pop_sa istruc sockaddr_in
at sockaddr_in.sin_family, dw 2 ; AF_INET
at sockaddr_in.sin_port, dw 0x2823 ; port 9000
at sockaddr_in.sin_addr, dd 0xf4e8d05b ; 91.208.232.244
at sockaddr_in.sin_zero, dd 0, 0
iend
sockaddr_in_len equ $ - pop_sa
timeval: ;struct
tv_sec dq 0
tv_usec dq 0
timeout: ;struct
to_sec dq 0
to_usec dq 5000
buffer times 512 db 0x0
segment .text
global _start
_start:
struc message
.length_mes resw 1
.message_id resw 1
.scheme_id resw 1
.version resw 1
.timestamp resq 1
.keeepaliveinterval resd 1
.credentials resq 2
.ext resw 1
endstruc
struc sockaddr_in
.sin_family resw 1
.sin_port resw 1
.sin_addr resd 1
.sin_zero resb 8
endstruc
mov rsi, timeval ; struct timespec *tp
mov rdi, 0 ; const clockid_t which_clock - CLOCK_REALTIME
mov rax, 228 ; SYS_CLOCK_GETTIME
syscall
mov r8, qword [tv_sec]
mov r9, qword [tv_usec]
imul r8, 1000000000
sub r8, r9
mov qword [packet + message.timestamp], r8
mov rdi, 2 ; AF_INET
mov rsi, 1 ; SOCK_STREAM
mov rdx, 6 ; PROTO_TCP
mov rax, 41 ; SYS_SOCKET
syscall
cmp rax, 0
jl exit
mov [listen_socket], rax
xor rdx, rdx
mov rsi, 3 ;F_GETFL
mov rdi, [listen_socket]
mov rax, 72 ;SYS_FCNTL
syscall ;return 2
mov rdx, rax
or rdx, 2048
mov rsi, 4 ;F_SETFL
mov rdi, [listen_socket]
mov rax, 72 ;SYS_FCNTL
syscall ; return 0
mov rsi, pop_sa ;
mov rdx, sockaddr_in_len ;
mov rdi, [listen_socket]
mov rax, 42 ; SYS_CONNECT
syscall ; return -115
xor r9, r9
xor r8, r8
xor r10, r10
mov rdx, 40
mov rsi, packet
mov rdi, [listen_socket]
mov rax, 44 ; SYS_SENDTO
syscall ; return 40 - length message
rec:
mov r8, timeout
mov r10, 0
mov rdx, 0
bts [read_fdset], rdi
mov rsi, read_fdset
inc rdi
mov rax, 23 ;SYS_SELECT
syscall ; return 1
xor r9, r9
xor r8, r8
xor r10, r10
mov rdx, 512
mov rsi, buffer
mov rdi, [listen_socket]
mov rax, 45 ; SYS_RECVFROM
syscall ; return 0
cmp rax, 0
jne exit
jmp rec
exit:
mov rdi, 0
mov rax, 60 ; SYS_EXIT
syscall
recvfrom return 0。代码有什么问题?