linux udp bind 返回值-1分析

在linux socket通信中,我们通常用到open/bind/read/write等内部函数,那么当这些函数返回值为-1的时候,我们怎么进一步定位呢!

(1)怎么打印出返回值出错的原因呢!系统调用的错误都会存放在errno中

errno需要的头文件:

#include<errno.h>

strerror头文件,将错误信息errno转换为字符串信息,方便定位,strerror(eerno)

 #include<string.h>

printf("err = %d, eer_str = %s\r\n",  errno, strerror(errno));

返回值说明:

    #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 c

猜你喜欢

转载自blog.csdn.net/qq_40008325/article/details/129992354