sockets sprockects and widgets

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

sockets sprockects and widgets

Post by maboroshi »

ASM Socket code working :-)

Code: Select all

#most of the code here is borrowed from:
#http://jakash3.wordpress.com/2011/01/15/assembly-socket-example/
#minor changes by me
#but man figuring this shit out took a while hahah
#and the debugging I learned

.data
   host:
	.asciz "www.google.ca"
   
   message:
    .string "HELLO MOTHERFUCKING WORLD"

   size:
    .int 30

   unable_to_connect:
    .asciz "Unable to connect!"
   
   create_socket_fail:
    .asciz "Unable to create socket!"

    
.text
   .globl main
   main:
    
    nop
    pushl %ebp
    movl %esp,%ebp
    subl $20,%esp
    pushl $host
    call gethostbyname
    movl 16(%eax), %eax      
    movl (%eax), %eax       
    movl (%eax), %eax        
    movl %eax, -12(%ebp)     
    movw $2, -16(%ebp)       
    movl $0, %ecx				
    movw $80, %cx           
    movl %ecx, (%esp)
    call htons
    movw %ax,-14(%ebp)     
    movl $0,-8(%ebp)			
    movl $0,-4(%ebp)        
    subl $8,%esp             
              
    
    #socket 
    movl $2, (%esp)	    #First Value of stack pointer AF_INET
    movl $1, 4(%esp)    #SOCK_STREAM
    movl $6, 8(%esp)    #IPPROTO_TCP 
    call socket         #call socket
    cmpl $-1,%eax
    je create_fail      #return -1 on fail

    # save socket file descriptor
    movl %eax, -20(%ebp)     
    
    movl %eax, (%esp)   #mov sockfd into first value of our new stack pointer
    leal -16(%ebp),%ebx
    movl %ebx, 4(%esp)  #mov host as second arg into esp
    movl $16, 8(%esp)   #mov sock_len
    call connect
    cmpl $0, %eax
    jnz connect_fail	#return 0 if fail

    #send
    
    movl -20(%ebp), %ebx
    movl %ebx, (%esp)
    movl $message, 4(%esp)
    movl $size, 8(%esp)
    movl $0, 12(%esp)
    call send
    
    movl $0, %ebx
    movl $1, %eax       #exit
    int $0x80 
       
   connect_fail:
    pushl $unable_to_connect
    call puts
    pushl $1
    call exit 
    

   create_fail:
    pushl $create_socket_fail
    call puts
    pushl $1
    call exit

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: sockets sprockects and widgets

Post by ayu »

Awesome!! :D

Great job :D
"The best place to hide a tree, is in a forest"

User avatar
Broken Angel
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 432
Joined: 05 Jul 2010, 04:58
13
Contact:

Re: sockets sprockects and widgets

Post by Broken Angel »

w0w thas really nice but sorry what does it actually do?
God Blessed Me With Forgiveness And I Forgive You With My Revenge...!



-Broken Angel

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Re: sockets sprockects and widgets

Post by maboroshi »

Alls is it does is create a socket connect a socket and send a message :-)

Post Reply