Re: How to print out socket related data in the kernel?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found the error in my code.

I have been trying to print out some of the information in the kernel
just to see if I understand correctly but without much luck so far.
So in sys_socketcall() function, when the user calls, for example,
getsockname(), then I want to print out IP address. So here is what I
did.

    case SYS_GETSOCKNAME:
           err = sys_getsockname(a0,(struct sockaddr __user *)a1, (int
__user *)a[2]);
           {
#define ILHO_IP_NUMS(x)  (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, (x)>>24
                struct sockaddr *name = (struct sockaddr __user*)a1;
                struct in_addr ip = ((struct sockaddr_in *)&name)->sin_addr;
                Printk("GETSOCKNAME - %d.%d.%d.%d\n", ILHO_IP_NUMS(ip.s_addr));
           }
           break;

However, I did not get the value in the way I expected so I was just
wondering if I have to do anything here. Please kindly give me some
advice. Thank you.


I realized that I did not use the struct sockaddr_in. After I used it,
things were sorted out clearly. Sorry for the spams. Here is the
changed code.

    case SYS_GETSOCKNAME:
           err = sys_getsockname(a0,(struct sockaddr __user *)a1, (int
__user *)a[2]);
           {
#define ILHO_IP_NUMS(x)  (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, (x)>>24
                struct sockaddr_in *name = (struct sockaddr __user*)a1;
                struct in_addr ip = name->sin_addr;
                Printk("GETSOCKNAME - %d.%d.%d.%d\n", ILHO_IP_NUMS(ip.s_addr));
           }
           break;

Thanks.

Ilho <><
--
YES, JESUS LOVES YOU, TOO.
- Come for Eng. Christian Fellowship on Friday 6pm!
For God so loved the world that he gave his one and only Son, that
whoever believes in him shall not perish but have eternal life(John
3:16).

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux