- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
程序运行到getsockname
,返回-1,errno
为9(EBADF
,错误的文件描述符)。但是,Android 应用程序中检测的代码运行良好。
void sysLibCSendHookHandler(CPUState* env, int isStart){
if(isStart){
int fd = env->regs[0];
int buf = env->regs[1];
int len = env->regs[2];
int flags = env->regs[3];
DECAF_printf("xxxxx send(%d, %p, %d, %d)\n", fd, buf, len, flags);
extern int errno;
struct sockaddr_un sock_addr;
socklen_t sock_addr_len;
sock_addr_len = sizeof(sock_addr);
int t = getsockname(fd, (struct sockaddr*)&sock_addr, &sock_addr_len);
DECAF_printf("fd:%d",fd);}
最佳答案
此代码导致未定义的行为:
extern int errno;
根据 the C Standard 的 7.5 个错误
The header defines several macros, all relating to the reporting of error conditions.
The macros are
EDOM
EILSEQ
ERANGEwhich expand to integer constant expressions with type
int
, distinct positive values, and which are suitable for use in#if
preprocessing directives; anderrno
which expands to a modifiable lvalue that has type
int
and thread local storage duration, the value of which is set to a positive error number by several library functions. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the nameerrno
, the behavior is undefined.
根据Google Android source code , errno
是定义为的宏
extern int *__geterrno(void);
#define errno (*__geterrno())
既然如此,您在 extern int errno
中看到的值就没有意义了。
关于android - getsockname 返回-1,errno 是 EBADF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888482/
我使用 getpeername() 和 getsockname() 在服务器端打印出客户端套接字和服务器套接字的 IP 地址。但是,只指定了客户端套接字的IP地址,而服务器套接字的IP地址是0.0.0
我试图在不调用 bind() 的情况下获取套接字的端口号。代码如下。 #include #include #include int main() { int sock = socket(AF
我正在尝试获取用于建立连接的本地 IP。但是,出于某种原因,我无法使用 getsockname,因为它从不在我的 sockaddr 中设置任何数据。 int fd = socket(/* params
我最近在尝试运行 iperf3 时遇到了堆栈崩溃(= 缓冲区溢出)问题。我查明了 getsockname() 调用 ( https://github.com/esnet/iperf/blob/mast
如果我创建一个流套接字,并使其成为非阻塞的,我请求它连接到远程主机,并且 connect() 调用返回 EINPROGRESS,对其发出 getsockname() 调用并期望返回的本地地址是正确的是
这是一个使用 TCP 套接字的简单文件服务器文件, 当我运行它时,出现以下错误。 谁能告诉我这个问题的解决方案 import socket # Import socket
在带有套接字程序的C中,我尝试在服务器套接字中插入getpeername()和getsockname,以在服务器端打印服务器套接字和客户端套接字的IP地址。注意:我的服务器套接字使用 INADDR_A
在我的 Linux C++ 应用程序中,我使用了 getpeername 和 getsockname。当操作系统启用 IPv6 时,getpeername 和 getsockname 都只返回端口!
我可以得到返回的端口,但不能得到 IP。我应该使用 getsockname 以外的其他东西吗?谢谢 if ((sock = ::socket(AF_INET, SOCK_STREAM,
self._socket = socket(AF_INET, SOCK_DGRAM, 0); // create addr struct sockaddr_in addr; bzero(&addr,
这个问题在这里已经有了答案: Getting my own IP address by connect()ing using UDP socket? (1 个回答) 关闭 8 年前。 我试图通过尝试
我在使用 getsockname 函数时遇到问题。我有这段代码: struct sockaddr sa; int sa_len; sa_len = sizeof(sa); if (getsocknam
我在 Windows 中有调用 getsockname 的代码如下: getsockname(*x,NULL,0) 第三个参数(namelen)是IN\Out参数,包含名称缓冲区的大小,以字节为单位。
我通过cmd成功连接到服务器,但是在发送部署命令后出现错误 错误 getsockname 失败:不是套接字 从项目目录在 cmd 中运行命令调用 vendor/bin/dep deploy st1 部
我需要在 C++ 中获取系统的 IP 地址。我按照此处另一条评论的逻辑和建议创建了一个套接字,然后使用 getsockname 确定套接字绑定(bind)到的 IP 地址。 但是,这似乎不起作用(下面
程序运行到getsockname,返回-1,errno为9(EBADF,错误的文件描述符)。但是,Android 应用程序中检测的代码运行良好。 void sysLibCSendHookHandler
这是代码。它与这个类似问题的代码相同:http://monkey.org/freebsd/archive/freebsd-stable/200401/msg00032.html .当我运行它时,我总是
我想不通。谁能告诉我为什么会出现此错误: 警告:从不兼容的指针类型传递“getsockname”的参数 2 在下面的代码中: #include #include #include #includ
我是一名优秀的程序员,十分优秀!