Where can I find a list of all types of bsd style socket errors?
In the documentation? For instance, for connect(), see:
% man connect
...
ECONNREFUSED
No-one listening on the remote address.
EISCONN
The socket is already connected.
ENETUNREACH
Network is unreachable.
Of you want to know all possible errno's or some comments on them you could take a look at the header files, on a Linux system there are located in
- /usr/include/asm-generic/errno-base.h
#ifndef _ASM_GENERIC_ERRNO_BASE_H #define _ASM_GENERIC_ERRNO_BASE_H #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Argument list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ ...
- /usr/include/asm-generic/errno.h
#ifndef _ASM_GENERIC_ERRNO_H #define _ASM_GENERIC_ERRNO_H #include #define EDEADLK 35 /* Resource deadlock would occur */ #define ENAMETOOLONG 36 /* File name too long */ #define ENOLCK 37 /* No record locks available */ #define ENOSYS 38 /* Function not implemented */ #define ENOTEMPTY 39 /* Directory not empty */ #define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ ...
If you want to know what errno a call, e.g. socket() or connect() can return, when install the development manpages and try man socket or man connect
Many functions will set errno
on failure, and instead of going through errno.h
yourself and converting the error number to strings, you are much better off calling perror
.
perror
will print the current errno
's corresponding message to stderr
with an optional prefix.
Example usage:
if (connect())
{
perror("connect() failed in function foo");
...
}
perror
has friends called strerror
and strerror_r
who might prove useful if you want to capture the string for use in places other than stderr
.