- 论坛徽章:
- 0
|
Linux内核版本2.6.18
socket函数的系统调用函数如下:
我在其中对发送的数据和接收的数据试图进行输出操作,如带有注释的两行代码所示。结果是,可以输出发送数据,但是无法输出接收的数据(是直接没有输出任何的数据,不是输出乱码)。- asmlinkage long sys_socketcall(int call, unsigned long __user *args)
- {
- unsigned long a[6];
- unsigned long a0, a1;
- int err;
-
- if (call < 1 || call > SYS_RECVMSG)
- return -EINVAL;
-
- /* copy_from_user should be SMP safe. */
- if (copy_from_user(a, args, nargs[call]))
- return -EFAULT;
-
- err = audit_socketcall(nargs[call] / sizeof(unsigned long), a);
- if (err)
- return err;
-
- a0 = a[0];
- a1 = a[1];
-
- switch (call) {
- case SYS_SOCKET:
- err = sys_socket(a0, a1, a[2]);
- break;
- case SYS_BIND:
- err = sys_bind(a0, (struct sockaddr __user *)a1, a[2]);
- break;
- case SYS_CONNECT:
- err = sys_connect(a0, (struct sockaddr __user *)a1, a[2]);
- break;
- case SYS_LISTEN:
- err = sys_listen(a0, a1);
- break;
- case SYS_ACCEPT:
- err =
- sys_accept(a0, (struct sockaddr __user *)a1,
- (int __user *)a[2]);
- break;
- case SYS_GETSOCKNAME:
- err =
- sys_getsockname(a0, (struct sockaddr __user *)a1,
- (int __user *)a[2]);
- break;
- case SYS_GETPEERNAME:
- err =
- sys_getpeername(a0, (struct sockaddr __user *)a1,
- (int __user *)a[2]);
- break;
- case SYS_SOCKETPAIR:
- err = sys_socketpair(a0, a1, a[2], (int __user *)a[3]);
- break;
- case SYS_SEND:
- err = sys_send(a0, (void __user *)a1, a[2], a[3]);
- break;
- case SYS_SENDTO:
- printk("sendto a1=%s\n",(char *)a1);//a1是指向要发送的用户数据的指针,可以打印
- err = sys_sendto(a0, (void __user *)a1, a[2], a[3],
- (struct sockaddr __user *)a[4], a[5]);
- break;
- case SYS_RECV:
- err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
- break;
- case SYS_RECVFROM:
- printk("recvfrom a1=%s\n",(char *)a1);//a1是指向要接收的用户数据的指针,不能打印???
- err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
- (struct sockaddr __user *)a[4],
- (int __user *)a[5]);
- break;
复制代码 从sys_sendto和sys_recvfrom的参数a1,我们知道,
a1 是一个指针,当发送时,指向要发送的数据,当接收时,指向要接收的数据
各位大牛,给点看法,思路。在此先谢过了! |
|