-1
bits 32

section .text

    global _start

_start:

    ;socket
    mov eax, 0x66
    mov ebx, 0x1
    push 0x0
    push 0x1
    push 0x2
    mov ecx, esp
    int 0x80

    ;bind
    mov edx, eax
    xor eax, eax
    mov eax, 0x66
    mov ebx, 0x2
    push word 0x0
    push word 0x5c11
    push word 0x2
    mov ecx, esp
    push 0x16
    push ecx
    push edx
    int 0x80

    ;listen
    push eax
    mov eax, 0x66
    mov ebx, 0x4
    push edx
    mov ecx, esp
    int 0x80

    ;accept
    push eax
    push eax
    push edx
    mov ecx, esp
    int 0x80
$ nasm -f elf32 socket.asm ; ld -m elf_i386 -o socket socket.o

$ ./socket 

Segmentation fault (core dumped)

I have compiled the binary on Ubuntu 16.04 Desktop x86_64.

Any idea?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
wrynux
  • 23
  • 5

1 Answers1

2

I have added an exit at the end, and now I do not receive a segmentation fault error.

mov eax, 0x1
mov ebx, 0x0
int 0x80
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
wrynux
  • 23
  • 5
  • 2
    Yes, that's correct. +1 for solving your own problem. Two tips: (1) when posting code on Stack Overflow, select the entire block and press Ctrl+K (or click the `{}` button on the toolbar) to format it as code. (2) `mov reg, 0` is more commonly and more efficiently written as `xor reg, reg`. So in this case, the second line could just be `xor ebx, ebx`. – Cody Gray - on strike Jun 11 '17 at 12:50