Hello,
I'm new to assembly so I'm having a bit of trouble interfacing with the linux system call SYS_select. My problem is I can not seem to correctly build the fd_set structure, and then add the file descriptors to it (FD_SET(descriptor, &fds) in C).
Could someone please provide an example of working with file descriptors and select()?
Here is my current code:
mov %esp, %ebp
// allocate space for fd_set --
// this was taken from a disassemble of fd_set fd;
sub $0x94, %esp
// move socket descriptor into eax from previous
// connect call
mov %edi, %eax
// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)
// move server socket descriptor into eax from
// previous accept call
mov %esi, %eax
// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)
// store &fds into eax
lea 0xffffff7c(%ebp), %ecx
// argv[1] - number of fds+1
mov $0x3, %ebx
// argv[2] - argv[4]
xor %edx, %edx
xor %esi, %esi
xor %edi, %edi
// index into syscall table for select()
movb $142, %al
int $0x80
I'm new to assembly so I'm having a bit of trouble interfacing with the linux system call SYS_select. My problem is I can not seem to correctly build the fd_set structure, and then add the file descriptors to it (FD_SET(descriptor, &fds) in C).
Could someone please provide an example of working with file descriptors and select()?
Here is my current code:
mov %esp, %ebp
// allocate space for fd_set --
// this was taken from a disassemble of fd_set fd;
sub $0x94, %esp
// move socket descriptor into eax from previous
// connect call
mov %edi, %eax
// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)
// move server socket descriptor into eax from
// previous accept call
mov %esi, %eax
// assign the socket descriptor (FD_SET(eax, &fd))
bts %eax, 0xffffff7c(%ebp)
// store &fds into eax
lea 0xffffff7c(%ebp), %ecx
// argv[1] - number of fds+1
mov $0x3, %ebx
// argv[2] - argv[4]
xor %edx, %edx
xor %esi, %esi
xor %edi, %edi
// index into syscall table for select()
movb $142, %al
int $0x80