是否有任何链接或 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 tobind(2)
to a local address that isn't local. For example if the IP addresses of a machine are127.0.0.1
and1.2.3.4
and you're trying to bind to1.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 toEADDRNOTAVAIL
:
- bind(2)
- connect(2)
- setsockopt(2)
- packet(7)
继续,尝试使用其他错误值,还不错。
1 您正在使用 Firefox,对吗? :-)
关于c - 关于 Linux 中的错误编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3296053/