Ubuntu下errno值

Ubuntu下errno值

每当一个Unix函数(如socket函数)中发生错误时,全局变量errno将被设置成一个指示错误类型的正整数,如果函数不返回错误,errno的值就没有定义,值为0不表示任何错误.且具有以E开头的全大写字母名字,并且通常在/usr/include/sys/errno.h中定义,在Ubuntu中存放在/usr/include/asm-generic/errno.h,

为了方便查找,我们先给出errno.h在Ubuntu里面的内容

#ifndef _ASM_GENERIC_ERRNO_H
#define _ASM_GENERIC_ERRNO_H

#include <asm-generic/errno-base.h>

#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 */
#define	ENOMSG		42	/* No message of desired type */
#define	EIDRM		43	/* Identifier removed */
#define	ECHRNG		44	/* Channel number out of range */
#define	EL2NSYNC	45	/* Level 2 not synchronized */
#define	EL3HLT		46	/* Level 3 halted */
#define	EL3RST		47	/* Level 3 reset */
#define	ELNRNG		48	/* Link number out of range */
#define	EUNATCH		49	/* Protocol driver not attached */
#define	ENOCSI		50	/* No CSI structure available */
#define	EL2HLT		51	/* Level 2 halted */
#define	EBADE		52	/* Invalid exchange */
#define	EBADR		53	/* Invalid request descriptor */
#define	EXFULL		54	/* Exchange full */
#define	ENOANO		55	/* No anode */
#define	EBADRQC		56	/* Invalid request code */
#define	EBADSLT		57	/* Invalid slot */

#define	EDEADLOCK	EDEADLK

#define	EBFONT		59	/* Bad font file format */
#define	ENOSTR		60	/* Device not a stream */
#define	ENODATA		61	/* No data available */
#define	ETIME		62	/* Timer expired */
#define	ENOSR		63	/* Out of streams resources */
#define	ENONET		64	/* Machine is not on the network */
#define	ENOPKG		65	/* Package not installed */
#define	EREMOTE		66	/* Object is remote */
#define	ENOLINK		67	/* Link has been severed */
#define	EADV		68	/* Advertise error */
#define	ESRMNT		69	/* Srmount error */
#define	ECOMM		70	/* Communication error on send */
#define	EPROTO		71	/* Protocol error */
#define	EMULTIHOP	72	/* Multihop attempted */
#define	EDOTDOT		73	/* RFS specific error */
#define	EBADMSG		74	/* Not a data message */
#define	EOVERFLOW	75	/* Value too large for defined data type */
#define	ENOTUNIQ	76	/* Name not unique on network */
#define	EBADFD		77	/* File descriptor in bad state */
#define	EREMCHG		78	/* Remote address changed */
#define	ELIBACC		79	/* Can not access a needed shared library */
#define	ELIBBAD		80	/* Accessing a corrupted shared library */
#define	ELIBSCN		81	/* .lib section in a.out corrupted */
#define	ELIBMAX		82	/* Attempting to link in too many shared libraries */
#define	ELIBEXEC	83	/* Cannot exec a shared library directly */
#define	EILSEQ		84	/* Illegal byte sequence */
#define	ERESTART	85	/* Interrupted system call should be restarted */
#define	ESTRPIPE	86	/* Streams pipe error */
#define	EUSERS		87	/* Too many users */
#define	ENOTSOCK	88	/* Socket operation on non-socket */
#define	EDESTADDRREQ	89	/* Destination address required */
#define	EMSGSIZE	90	/* Message too long */
#define	EPROTOTYPE	91	/* Protocol wrong type for socket */
#define	ENOPROTOOPT	92	/* Protocol not available */
#define	EPROTONOSUPPORT	93	/* Protocol not supported */
#define	ESOCKTNOSUPPORT	94	/* Socket type not supported */
#define	EOPNOTSUPP	95	/* Operation not supported on transport endpoint */
#define	EPFNOSUPPORT	96	/* Protocol family not supported */
#define	EAFNOSUPPORT	97	/* Address family not supported by protocol */
#define	EADDRINUSE	98	/* Address already in use */
#define	EADDRNOTAVAIL	99	/* Cannot assign requested address */
#define	ENETDOWN	100	/* Network is down */
#define	ENETUNREACH	101	/* Network is unreachable */
#define	ENETRESET	102	/* Network dropped connection because of reset */
#define	ECONNABORTED	103	/* Software caused connection abort */
#define	ECONNRESET	104	/* Connection reset by peer */
#define	ENOBUFS		105	/* No buffer space available */
#define	EISCONN		106	/* Transport endpoint is already connected */
#define	ENOTCONN	107	/* Transport endpoint is not connected */
#define	ESHUTDOWN	108	/* Cannot send after transport endpoint shutdown */
#define	ETOOMANYREFS	109	/* Too many references: cannot splice */
#define	ETIMEDOUT	110	/* Connection timed out */
#define	ECONNREFUSED	111	/* Connection refused */
#define	EHOSTDOWN	112	/* Host is down */
#define	EHOSTUNREACH	113	/* No route to host */
#define	EALREADY	114	/* Operation already in progress */
#define	EINPROGRESS	115	/* Operation now in progress */
#define	ESTALE		116	/* Stale NFS file handle */
#define	EUCLEAN		117	/* Structure needs cleaning */
#define	ENOTNAM		118	/* Not a XENIX named type file */
#define	ENAVAIL		119	/* No XENIX semaphores available */
#define	EISNAM		120	/* Is a named type file */
#define	EREMOTEIO	121	/* Remote I/O error */
#define	EDQUOT		122	/* Quota exceeded */

#define	ENOMEDIUM	123	/* No medium found */
#define	EMEDIUMTYPE	124	/* Wrong medium type */
#define	ECANCELED	125	/* Operation Canceled */
#define	ENOKEY		126	/* Required key not available */
#define	EKEYEXPIRED	127	/* Key has expired */
#define	EKEYREVOKED	128	/* Key has been revoked */
#define	EKEYREJECTED	129	/* Key was rejected by service */

/* for robust mutexes */
#define	EOWNERDEAD	130	/* Owner died */
#define	ENOTRECOVERABLE	131	/* State not recoverable */

#define ERFKILL		132	/* Operation not possible due to RF-kill */

#endif

在实际操作中,怎么在系统中实时查询errno.h的值呢?举一个用TCP协议获取服务器时间的例子。注意socket函数的第一参数已经由AF_INET改为9999.

#include	"unp.h"

int main(int argc, char **argv)
{
	int					sockfd, n;
	char				recvline[MAXLINE + 1];
	struct sockaddr_in	servaddr;

	if (argc != 2)
		err_quit("usage: a.out <IPaddress>");

	if ( (sockfd = socket(9999, SOCK_STREAM, 0)) < 0)
		err_sys("socket error");

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port   = htons(13);	/* daytime server */
	if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
		err_quit("inet_pton error for %s", argv[1]);

	if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
		err_sys("connect error");

	while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
		recvline[n] = 0;	/* null terminate */
		if (fputs(recvline, stdout) == EOF)
			err_sys("fputs error");
	}
	if (n < 0)
		err_sys("read error");

	exit(0);
}

运行

make daytimetcpcli
./daytimetcpcli 127.0.0.1

要找出有关这个错误的详细信息,我们首先在errno.h头文件中使用grep查找字符串Address family not supported by protocol

grep 'Address family not supported by protocol' /usr/include/asm-generic/errno.h
#define	EAFNOSUPPORT	97	/* Address family not supported by protocol */

这就是由socket返回的errno.h值,我们然后查看手册页面.

man socket

大多数手册在最下面的Errors标题给出额外的信息,不过一般都很简洁

意思就是不支持指定的地址家族,就是说AF_INET那个地方改成了9999,不支持这个地址家族。应该改成AF_INET或者AF_INET6等等.

时间: 2024-08-10 17:20:47

Ubuntu下errno值的相关文章

mongodb在ubuntu下的couldn‘t remove fs lock errno:9 Bad file descriptor的错误

按照官网上的安装方法: 在ubuntu系统下有可能出现如下错误: couldn't remove fs lock errno:9 Bad file descriptor 此时需要修改文件所有者 $ sudo mkdir -p /data/db/ $ sudo chown ’USERNAME‘ /data/db 其中第一句是建立你的数据库文件夹,第二句修改该文件夹的所有者 之后就可以成功启动mongodb了 参考:stackoverflow.com/questions/15229412/unabl

Ubuntu下配置tftp服务和NFS服务

Ubuntu下配置tftp服务和NFS服务 配置tftp 方法一:(推荐方法)Ubuntu10.04 测试通过 1.安装TFTP软件 sudo apt-get install tftp-hpa tftpd-hpa tftp-hpa是客户端,tftpd-hpa是服务器端 2.建立tftpboot目录,作为服务器的目录sudo mkdir ~/tftpboot释放权限:(服务器目录,需要设置权限为777,chomd 777)sudo chmod 777 ~/tftpboot 3.配置TFTP服务器

ubuntu下搭建android开发环境核心篇安装AndroidStudio、sdk、jdk

本文系转载http://blog.csdn.net/lsyz0021/article/details/52215996 一.安装前的准备 1.1.如果你还没有安装ubuntu 14.04 LTS系统,请参考下面的文章安装 http://blog.csdn.net/lsyz0021/article/details/52187026 这里需要说明的是:在ubuntu下google官方测试的Android studio支持版本是ubuntu 12.04 LTS.jdk1.8.推荐电脑内存8GB 其实u

ubuntu下设置数据库字符集

就linux环境下出现的数据库乱码的问题,以ubuntu为例进行的总结 ubuntu环境设置的字符集utf8,windows默认字符集是GBK,Ubuntu的默认字符集为utf-8,这使 得在用telnet登录远程服务器或查看windows文件时出现乱码.需要将ubuntu环境设置为GBK或GB2312,或设置软件使其正确显示汉 字.下面以GBK字符集为例进行说明: 一.修改Ubuntu默认字符集为GBK 1.首先设置sudo vi /var/lib/locales/supported.d/lo

在Ubuntu下安装imx6linux系统的交叉编译环境遇到的问题总结

这段时间一直忙于手上的嵌入式项目,可以说自己从嵌入式的菜鸟一点点的入门了,关于嵌入式和imx6核心板的开发有了一点的了解,尤其是对于板子环境的搭建.硬件的开发,搭建环境,是一个很大的工程量,也是很重要的一步,环境没有搭好就无法进行下一步.当然这个前提是对项目所使用的硬件有一定的了解.对于嵌入式开发,项目进行到现在,从一个什么都不懂的到现在可以和大家讨论v4l2,framebuffer,讨论linux的视频开发,虽然还是菜鸟级别的,但这个月确实让自己掌握了一们知识. 关于嵌入式的开发,网上有很多的

Ubuntu 下开发 Android 环境变量设置

-----------------------------------------------------ANDROID_SDK_HOME:/home/cmm/avds PATH:/home/cmm/android-sdk-linux/tools;/home/cmm/android-sdk-linux/platform-tools CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib ---------------------------------------

C++链接库的使用,二维向量,三维向量,Ubuntu下C++测试向量库

1.#include<iostream> using namespace std; int main() { cout<<"Hello Woeld"<<endl; return 0; } 2.vector.cxx #include<iostream> int main() {int k; char x; cout<<"请输入向量的维度:"<<endl; cin>>k; vector

ubuntu 下修改文件访问权限chmod 777 -R *

本文转自: 个人建议 Ubuntu下修改目录权限命令如下:chmod 600 name (只有所有者有读和写的权限)chmod 644 name (所有者有读和写的权限,组用户只有读的权限)chmod 700 name (只有所有者有读和写以及执行的权限)chmod 666 name (每个人都有读和写的权限)chmod 777 name (每个人都有读和写以及执行的权限) 其中 name 指文件名,也可以是目录名. 整个命令的形式是chmod ×××(所有者)×××(组用户)×××(其他用户)

Ubuntu 下ftp服务器的安装配置

Ubuntu 下ftp服务器的安装配置 FTP服务器是平时应用最为广泛的服务之一.VSFTP是Very Secure FTP的缩写,意指非常安全的FTP服务.VSFTP功能强大,通过结合本地系统的用户认证模块及其多功能的配置项目,可以快速有效的搭建强大的多用户FTP服务. 首先我们考虑搭建FTP服务需要关注的都有哪些方面?比如我们最经常关注的有: 1.如何添加FTP用户?  2.如何临时冻结某FTP用户?  3.FTP用户登入后的默认目录?是否可以改变?  4.如何锁定FTP用户可访问的目录范围