Hey thanks for replying. I am using Ubuntu 8.04. And gcc 4.2.3
I managed to write the socket() call in _asm, I am next trying to write the ioctl call in _asm. I wrote the following code for socket
Code:
*__asm__("sub $12,%%esp\n" // increasing stack for Interrupt
"movl $2,(%%esp)\n" // AF_INET
"movl $1,4(%%esp)\n" // SOCK_STREAM
"movl $0,8(%%esp)\n" // third parameter to socket()
"movl $102,%%eax\n" // INT number for socket_CALL
"movl $1,%%ebx\n" // SYS_socketcall_socket
"movl %%esp,%%ecx\n"
"int $0x80\n"
"add $12,%%esp\n" // restoring stack
: "=a" (s)
);
This works perfectly. On trying to write similar code for ioctl, I am getting a return value of -9. Can someone help me out with this.
Code:
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
int main()
{
int i, res;
int s = 0;
s = socket(AF_INET,SOCK_STREAM,0);
struct ifreq ifr;
struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
char * ip;
ifr.ifr_ifindex = 1;
res = ioctl (s, SIOCGIFNAME, &ifr);
printf("\n first res %d", res);
res = ioctl(s, 35088, &ifr);
printf("\n second result %d", res);
__asm__("sub $12,%%esp\n"
"movl %%edx,(%%esp)\n"
"movl $35088,4(%%esp)\n"
"movl %%ecx,8(%%esp)\n"
"movl $54,%%eax\n" // IOCTL interrupt number
"movl %%esp,%%ebx\n" // Placing ESP for interrupt handler, is this a wrong register?
"int $0x80\n"
"add $12,%%esp\n"
:"=a" (res)
:"d" (s), "c" (&ifr)
);
printf(" \n new result was %d ", res);
return 0;
}
I am getting -9 as output. Am I passing the parameters wrong?
Thanks in advance.