试图理解sys_socketcall参数

时间:2013-06-11 18:00:34

标签: linux system-calls

任何人都可以解释这条线的确切作用:

socketcall(7,255);

我知道,该命令正在打开系统上的端口,但我不明白该参数。 该手册页说

int socketcall(int call, unsigned long *args);

DESCRIPTION
       socketcall()  is a common kernel entry point for the socket system calls.  call determines which socket function to invoke.  args points to a block con-
       taining the actual arguments, which are passed through to the appropriate call.

       User programs should call the appropriate functions by their usual names.  Only standard library implementors and kernel  hackers  need  to  know  about
       socketcall().

好的,调用7是sys_getpeername,但如果我看一下man-page:

int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

DESCRIPTION
       getpeername() returns the address of the peer connected to the socket sockfd, in the buffer pointed to by addr.  The addrlen argument should be initial-
       ized to indicate the amount of space pointed to by addr.  On return it contains the actual size of the name returned (in bytes).  The name is  truncated
       if the buffer provided is too small.

       The returned address is truncated if the buffer provided is too small; in this case, addrlen will return a value greater than was supplied to the call.

我真的不明白。该功能需要3个参数。该函数是如何获取参数的?什么意思255?有谁知道该功能如何打开一个端口?

1 个答案:

答案 0 :(得分:0)

虽然Linux的系统调用通常称为socketcall,但C库不会公开任何具有该名称的C函数。通常应该使用标准包装函数,例如socket()getpeername(),这将最终调用系统调用,但如果由于某种原因需要直接调用系统调用,那么可以完成使用syscall(SYS_socketcall, call, args)或使用程序集。

在这种情况下,应用程序或它使用的库(标准C库除外)很可能定义了自己的名为socketcall()的函数,该函数与系统调用无关。您应该检查该功能或其文档以查看它的作用。

相关问题