0

谁能解释这条线的确切作用:

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,但如果我查看手册页:

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是什么意思?有谁知道该功能如何打开端口?

4

1 回答 1

0

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

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

于 2013-06-11T20:57:23.950 回答