c - 关于 Linux 中的错误编号

标签 c linux

是否有任何链接或 Material 可以让我了解更多关于 Linux 中不同错误号的信息??

目前在 man errno 中,我为每个错误号得到一行,但我想知道发生特定错误的条件或机会(更详细的简短描述)

例如

EADDRNOTAVAIL 99 /* Cannot assign requested address */

当套接字试图绑定(bind)到机器本地不存在的 ip 地址时,会发生上述错误。类似地,对于所有其他错误,是否有任何 wiki 或资料提供详细信息??

最佳答案

好吧,由于错误通常是在做某事时发生的,所以最好的办法是在 man 页面上查找“某事”。

例如,如果您从 fscanf() 调用中返回 34 的 errno,您首先要执行以下操作:

grep 34 $(find /usr/include -name '*errno*h')

找出错误是什么:

/usr/include/bits/errno.h:#define ERANGE 34 /* Math result not representable. */
/usr/include/asm-generic/errno-base.h:#define ERANGE 34 /* Math result not ... */

然后,查看 fscanf()man 页面,您会看到:

ERANGE - The result of an integer conversion would exceed the size
         that can be stored in the corresponding integer type.

并且您(希望)能够从那里弄清楚。

如果您想要错误列表和(简要)描述,请按如下方式修改上面的 grep:

grep define $(find /usr/include -name '*errno*h') | less

并浏览输出。

而且,如果您仍然不知道该错误及其原因(描述有点简洁,我同意),我会把它塞进去(例如,EADDRNOTAVAIL)进入浏览器右上角的那个小对话框1,你会得到类似于this的信息。 (或许多其他精彩页面):

Cannot assign requested address
You are attempting to bind(2) to a local address that isn't local. For example if the IP addresses of a machine are 127.0.0.1 and 1.2.3.4 and you're trying to bind to 1.2.3.5, you are going to get this error. Check to make sure the address you are trying to bind to exists on the machine you are trying to bind it from.
This error can also come up if you're doing a "pre-bound connect", where you're first binding to a local port, then doing an outbound connect with a socket. If the local port is already connected to the given remote IP and port (i.e., there's already an identical socketpair), you'll receive this error (value = 99 on Linux).
4 pages link to EADDRNOTAVAIL:
     - bind(2)
     - connect(2)
     - setsockopt(2)
     - packet(7)

继续,尝试使用其他错误值,还不错。


1正在使用 Firefox,对吗? :-)

关于c - 关于 Linux 中的错误编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3296053/

相关文章:

android - 索尼 Z3 平板电脑紧凑型内核编译错误 - board-8974-gpiomux.c - 'gpio_spi_config'

c - 在 C 中使用 getaddrinfo() 的 Unix 套接字

android - 如何通过 ADB 杀死 android 中的持久系统进程?

linux - 如何为世界地图创建不同的缩放级别

linux - 压缩一个文件多次。在 Linux 中使用 gzip 命令的次数

windows - maven 301 永久移动

c - 在 Eclipse CDT 构建过程中使用 git 哈希代码

c - 将重音字母存储在 C 变量中

c++ - 旧包中的 C/C++ 静态字符串

python - 找不到mkvirtualenv,但是可以执行