Regarding error numbers in Linux
Is there any link or material where I can learn more about the different error numbers in Linux ??
At present in man errno I get a single line for each error number but I would like to know the conditions or chances for which particular error occurs (A more detailed description in short words)
For e.g.
EADDRNOTAVAIL 99 /* Cannot assign request开发者_运维百科ed address */
Above error occurs when a socket tried to bind to ip-address which is not present locally in the machine .. Similarly for all other errors is there any wiki or material for detailed information ??
Well, since errors generally occur while doing something, your best bet is to look up the man
page for "something".
For example, if you get back an errno
of 34 from your fscanf()
call, you would first do:
grep 34 $(find /usr/include -name '*errno*h')
to figure out what the error was:
/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 ... */
Then, looking at the man
page for fscanf()
, you see:
ERANGE - The result of an integer conversion would exceed the size
that can be stored in the corresponding integer type.
and you would (hopefully) be able to figure it out from there.
If you want a list of the errors and (brief) description, modify the grep
above as follows:
grep define $(find /usr/include -name '*errno*h') | less
and browse the output.
And, if you still don't know about the error and what caused it (the descriptions are a little terse, I'll agree), I would just bung it (e.g., EADDRNOTAVAIL
) into that little dialog box in the top right corner of your browser1 and you'll get back something like this (or many other wonderful pages):
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)
Go ahead, try it with other error values as well, it's not too bad.
1 You are using Firefox, right? :-)
Error codes are fairly generic, and are meaningful only within the context of a particular function. So there isn't much advantage in learning all the error codes, as they may mean subtly different things for different functions and have to be handled differently anyway.
"ERRORS" section in the function's man page will tell you what codes are possible for its return values or errno
and why they occur.
If it's GLIBC, try using %m
in a printf() statement:
#include <errno.h>
...
int fh = fopen(...);
if (0 > fh) printf("Couldn't open the file: %d, %m\n", errno);
Very useful.
Its API specfic. I have not heard about a generic error list. However :
Many functions provide an error number in errno, which has type int
and is defined in <errno.h>.
So you can have a look at the header file errno.h. Similarly Glib has different codes for error reporting.
EDIT: Well if you already know the error code then you can always google to get more information on that error, if you find man page unsatisfactory.
As other posters have suggested, the best source for decoding what errors really mean in context is the appropriate man page. For networking protocols, the appropriate man page may be something other than the system call; for IP sockets, try ip(7), which gives a tiny bit more information:
EADDRNOTAVAIL
A nonexistent interface was requested or the requested source
address was not local.
More error codes are described in tcp(7) and udp(7).
this program can also do the trick..
#include<stdio.h>
#include<string.h>
int main()
{
int i= 0 ;
for ( i = 0 ; i<=132; i++ )
{
printf("no %d == %s \n", i , strerror(i));
}
}
no 0 == Success no 1 == Operation not permitted no 2 == No such file or directory no 3 == No such process no 4 == Interrupted system call no 5 == Input/output error no 6 == No such device or address no 7 == Argument list too long no 8 == Exec format error no 9 == Bad file descriptor no 10 == No child processes no 11 == Resource temporarily unavailable no 12 == Cannot allocate memory no 13 == Permission denied no 14 == Bad address no 15 == Block device required no 16 == Device or resource busy no 17 == File exists no 18 == Invalid cross-device link no 19 == No such device no 20 == Not a directory no 21 == Is a directory no 22 == Invalid argument no 23 == Too many open files in system no 24 == Too many open files no 25 == Inappropriate ioctl for device no 26 == Text file busy no 27 == File too large no 28 == No space left on device no 29 == Illegal seek no 30 == Read-only file system no 31 == Too many links no 32 == Broken pipe no 33 == Numerical argument out of domain no 34 == Numerical result out of range no 35 == Resource deadlock avoided no 36 == File name too long no 37 == No locks available no 38 == Function not implemented no 39 == Directory not empty no 40 == Too many levels of symbolic links no 41 == Unknown error 41 no 42 == No message of desired type no 43 == Identifier removed no 44 == Channel number out of range no 45 == Level 2 not synchronized no 46 == Level 3 halted no 47 == Level 3 reset no 48 == Link number out of range no 49 == Protocol driver not attached no 50 == No CSI structure available no 51 == Level 2 halted no 52 == Invalid exchange no 53 == Invalid request descriptor no 54 == Exchange full no 55 == No anode no 56 == Invalid request code no 57 == Invalid slot no 58 == Unknown error 58 no 59 == Bad font file format no 60 == Device not a stream no 61 == No data available no 62 == Timer expired no 63 == Out of streams resources no 64 == Machine is not on the network no 65 == Package not installed no 66 == Object is remote no 67 == Link has been severed no 68 == Advertise error no 69 == Srmount error no 70 == Communication error on send no 71 == Protocol error no 72 == Multihop attempted no 73 == RFS specific error no 74 == Bad message no 75 == Value too large for defined data type no 76 == Name not unique on network no 77 == File descriptor in bad state no 78 == Remote address changed no 79 == Can not access a needed shared library no 80 == Accessing a corrupted shared library no 81 == .lib section in a.out corrupted no 82 == Attempting to link in too many shared libraries no 83 == Cannot exec a shared library directly no 84 == Invalid or incomplete multibyte or wide character no 85 == Interrupted system call should be restarted no 86 == Streams pipe error no 87 == Too many users no 88 == Socket operation on non-socket no 89 == Destination address required no 90 == Message too long no 91 == Protocol wrong type for socket no 92 == Protocol not available no 93 == Protocol not supported no 94 == Socket type not supported no 95 == Operation not supported no 96 == Protocol family not supported no 97 == Address family not supported by protocol no 98 == Address already in use no 99 == Cannot assign requested address no 100 == Network is down no 101 == Network is unreachable no 102 == Network dropped connection on reset no 103 == Software caused connection abort no 104 == Connection reset by peer no 105 == No buffer space available no 106 == Transport endpoint is already connected no 107 == Transport endpoint is not connected no 108 == Cannot send after transport endpoint shutdown no 109 == Too many references: cannot splice no 110 == Connection timed out no 111 == Connection refused no 112 == Host is down no 113 == No route to host no 114 == Operation already in progress no 115 == Operation now in progress no 116 == Stale NFS file handle no 117 == Structure needs cleaning no 118 == Not a XENIX named type file no 119 == No XENIX semaphores available no 120 == Is a named type file no 121 == Remote I/O error no 122 == Disk quota exceeded no 123 == No medium found no 124 == Wrong medium type no 125 == Operation canceled no 126 == Required key not available no 127 == Key has expired no 128 == Key has been revoked no 129 == Key was rejected by service no 130 == Owner died no 131 == State not recoverable no 132 == Unknown error 132
精彩评论