`
jakielong
  • 浏览: 223323 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

unp.h文件内容

阅读更多
 /* Our own header. Tabs are set for 4 spaces, not 8 */
 
 #ifndef __unp_h
 #define __unp_h

 #include    "../config.h"      /* configuration options for current OS */
                            /* "../config.h" is generated by configure */

 /* If anything changes in the following list of #includes, must change
    acsite.m4 also, for configure's tests. */

 #include    <sys/types.h>       /* basic system data types */
 #include    <sys/socket.h>      /* basic socket definitions */
 #include    <sys/time.h>        /* timeval{} for select() */
 #include    <time.h>            /* timespec{} for pselect() */
 #include    <netinet/in.h>      /* sockaddr_in{} and other Internet defns */
 #include    <arpa/inet.h>       /* inet(3) functions */
 #include    <errno.h>
 #include    <fcntl.h>           /* for nonblocking */
 #include    <netdb.h>
 #include    <signal.h>
 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <string.h>
 #include    <sys/stat.h>        /* for S_xxx file mode constants */
 #include    <sys/uio.h>         /* for iovec{} and readv/writev */
 #include    <unistd.h>
 #include    <sys/wait.h>
 #include    <sys/un.h>          /* for Unix domain sockets */

 #ifdef  HAVE_SYS_SELECT_H
 # include   <sys/select.h>      /* for convenience */
 #endif

 #ifdef  HAVE_SYS_SYSCTL_H
 # include   <sys/sysctl.h>
 #endif

 #ifdef  HAVE_POLL_H
 # include  <poll.h>             /* for convenience */
 #endif

 #ifdef  HAVE_SYS_EVENT_H
 # include   <sys/event.h>       /* for kqueue */
 #endif

 #ifdef  HAVE_STRINGS_H
 # include   <strings.h>         /* for convenience */
 #endif

 /* Three headers are normally needed for socket/file ioctl's:
  * <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.
  */
 #ifdef  HAVE_SYS_IOCTL_H
 # include   <sys/ioctl.h>
 #endif
 #ifdef  HAVE_SYS_FILIO_H
 # include   <sys/filio.h>
 #endif
 #ifdef  HAVE_SYS_SOCKIO_H
 # include   <sys/sockio.h>
 #endif

 #ifdef  HAVE_PTHREAD_H
 # include   <pthread.h>
 #endif

 #ifdef  HAVE_NET_IF_DL_H
 # include    <net/if_dl.h>
 #endif

 #ifdef  HAVE_NETINET_SCTP_H
 #include     <netinet/sctp.h>
 #endif

 /* OSF/1 actually disables recv() and send() in <sys/socket.h> */
 #ifdef  __osf__
 #undef  recv
 #undef  send
 #define recv(a,b,c,d)   recvfrom(a,b,c,d,0,0)
 #define send(a,b,c,d)   sendto(a,b,c,d,0,0)
 #endif

 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff  /* should have been in <netinet/in.h> */
 #endif

 #ifndef SHUT_RD                 /* these three POSIX names are new */
 #define SHUT_RD     0           /* shutdown for reading */
 #define SHUT_WR     1           /* shutdown for writing */
 #define SHUT_RDWR   2           /* shutdown for reading and writing */
 #endif

 #ifndef INET_ADDRSTRLEN
 #define INET_ADDRSTRLEN     16  /* "ddd.ddd.ddd.ddd\0"
                                    1234567890123456 */
 #endif

 /* Define following even if IPv6 not supported, so we can always allocate
    an adequately sized buffer without #ifdefs in the code. */
 #ifndef INET6_ADDRSTRLEN
 #define INET6_ADDRSTRLEN    46  /* max size of IPv6 address string:
                    "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or
                    "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"
                     1234567890123456789012345678901234567890123456 */
 #endif

 /* Define bzero() as a macro if it's not in standard C library. */
 #ifndef HAVE_BZERO
 #define bzero(ptr,n)        memset (ptr, 0, n)
 #endif

 /* Older resolvers do not have gethostbyname2() */
 #ifndef HAVE_GETHOSTBYNAME2
 #define gethostbyname2(host,family)     gethostbyname((host))
 #endif

 /* The structure returned by recvfrom_flags() */
 struct unp_in_pktinfo {
     struct in_addr ipi_addr;    /* dst IPv4 address */
     int     ipi_ifindex;        /* received interface index */
 };

 /* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few
    implementations support them today. These two macros really need
     an ALIGN() macro, but each implementation does this differently. */
 #ifndef CMSG_LEN
 #define CMSG_LEN(size)      (sizeof(struct cmsghdr) + (size))
 #endif
 #ifndef CMSG_SPACE
 #define CMSG_SPACE(size)    (sizeof(struct cmsghdr) + (size))
 #endif

 /* POSIX requires the SUN_LEN() macro, but not all implementations define it (yet). Note that this 4.4BSD macro works regardless whether there is a length field or not. */
 #ifndef SUN_LEN
 # define    SUN_LEN (su) \
     (sizeof (*(su)) - sizeof ((su)->sun_path) + strlen((su)->sun_path))
 #endif

 /* POSIX renames "Unix domain" as "local IPC."
    Not all systems define AF_LOCAL and PF_LOCAL (yet). */
 #ifndef AF_LOCAL
 #define AF_LOCAL    AF_UNIX
 #endif
 #ifndef PF_LOCAL
 #define PF_LOCAL    PF_UNIX
 #endif

 /* POSIX requires that an #include of <poll.h> define INFTIM, but many
    systems still define it in <sys/stropts.h>. We don't want to include
    all the STREAMS stuff if it's not needed, so we just define INFTIM here.
    This is the standard value, but there's no guarantee it is -1. */
 #ifndef INFTIM
 #define INFTIM          (-1)     /* infinite poll timeout */
 #ifdef HAVE_POLL_H
 #define INFTIM_UNPH              /* tell unpxti.h we defined it */
 #endif
 #endif

 /* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
    kernels still #define it as 5, while actually supporting many more */
 #define LISTENQ     1024         /* 2nd argument to listen () */

 /* Miscellaneous constants */
 #define MAXLINE     4096         /* max text line length */
 #define BUFFSIZE    8192         /* buffer size for reads and writes */

 /* Define some port number that can be used for our examples */
 #define SERV_PORT        9877    /* TCP and UDP */
 #define SERV_PORT_STR   "9877"   /* TCP and UDP */
 #define UNIXSTR_PATH    "/tmp/unix.str" /* Unix domain stream */
 #define UNIXDG_PATH     "/tmp/unix.dg"  /* Unix domain datagram */

 /* Following shortens all the typecasts of pointer arguments: */
 #define SA struct sockaddr

 #define HAVE_STRUCT_SOCKADDR_STORAGE
 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
 /*
  * RFC 3493: protocol-independent placeholder for socket addresses
  */
 #define __SS_MAXSIZE    128
 #define __SS_ALIGNSIZE  (sizeof(int64_t))
 #ifdef HAVE_SOCKADDR_SA_LEN
 #define __SS_PAD1SIZE   (__SS_ALIGNSIZE - sizeof(u_char) - sizeof(sa_family_t))
 #else
 #define __SS_PAD1SIZE   (__SS_ALIGNSIZE - sizeof(sa_family_t))
 #endif
 #define __SS_PAD2SIZE   (__SS_MAXSIZE - 2*__SS_ALIGNSIZE)

 struct sockaddr_storage {
 #ifdef HAVE_SOCKADDR_SA_LEN
     u_char  ss_len;
 #endif
     sa_family_t ss_family;
     char    __ss_pad1[__SS_PAD1SIZE];
     int64_t __ss_align;
     char    __ss_pad2[__SS_PAD2SIZE];
 };
 #endif

 #define FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
                     /* default file access permissions for new files */
 #define DIR_MODE    (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
                     /* default permissions for new directories */

 typedef void Sigfunc (int);     /* for signal handlers */

 #define min(a,b)    ((a) < (b) ? (a) : (b))
 #define max(a,b)    ((a) > (b) ? (a) : (b))

 #ifndef HAVE_ADDRINFO_STRUCT
 # include   "../lib/addrinfo.h"
 #endif

 #ifndef HAVE_IF_NAMEINDEX_STRUCT
 struct if_nameindex {
     unsigned int if_index;      /* 1, 2, ... */
     char *if_name;              /* null-terminated name: "le0", ... */
 };
 #endif

 #ifndef HAVE_TIMESPEC_STRUCT
 struct timespec {
     time_t tv_sec;              /* seconds */
     long     tv_nsec;           /* and nanoseconds */
 };
 #endif
 
分享到:
评论

相关推荐

    unp.h源码(CentOS上可无错编译)

    修改过一些带有编译错误问题的unp.h源码,可在CentOS的服务器上编译,不需要再修改。编译过程如下: tar -zxvf unpv13e.tar.gz rm -y unpv13e.tar.gz cd unpv13e cd lib make cd ../libfree make cd .. cp ...

    unix网络编程 unp.h

    unp.h 兄弟自己一个字一个打进去的。 之前10分是在没有必要。 资源共享,共同享受编程的乐趣。 这部分代码比较新,可能SCTP有的系统不支持,需要修改一下源码。 如果你觉得还可以,那么给个评论吧。

    unp 64bit CentOS编译

    改压缩包包含了Unix网络编程卷1第三版所需的unp.h和对应的头文件。编译环境为x86_64 CentOS7 需要请下载。

    unp.tar.gz

    the source code of the book "UNIX Network Programming" UNIX Network Programming, Volume 1 This book is for people who want to write programs that communicate with each other using an application ...

    unp.rar_W. Richard Stevens_c/C++_unp

    W. Richard Stevens 的代码

    unpv13e-master.zip

    书中源代码作者发布在:www.unpbook.com,https://github.com/unpbook/unpv13e

    unpv13e.zip

    unpv13e 并附带了error.c文件,下载下来后,把error.c文件与unp.h和config.h文件一起放到/usr/include/目录下,就防止报err_sys()错误了。

    《UNIX网络编程》环境配置

    将文件解压到/usr/include/目录下,并根据自己的代码需要,更改unp.h文件中的#include "unp/xxx.c"行,使相应的*.c文件包含在内,别的不做任何更改就可以运行《UNIX网络编程》书里的程序了……

    unpv13e.tar.gz

    Unix网络编程中unp.h的环境,unpv13e.tar.gz。有些人动不动就20几个积分,像这种开源的资源,也要这么多,真垃圾的很。

    Python-unp一个用来方便解包归档文件的命令行工具

    unp:一个用来方便解包归档文件的命令行工具

    《Unix网络编程》环境搭建

    文章目录Ubuntu《Unix网络编程》环境搭建下载文件解压缩按照README 依次执行修改inet_ntop.c文件添加到共享库目录修改unp.h程序各文件相对位置case1:case 2:编译执行小问题 下载文件 为了方便获取,我上传到了github ...

    UNP 网络编程源代码

    W. Richard Stevens的原版代码,网络编程的经典巨著

    UNP学习笔记讲义

    Linux 网络编程修炼指南内功心法,这个是博主https://blog.csdn.net/q1007729991/article/details/69101159,大家可以互相学习

    unp unix网络编程

    unix network programming 源码 unix网络编程源码

    UNP源码 STEVEN

    全书不但介绍了基本编程内容,还涵盖了与套接字编程相关的高级主题,对于客户/服务器程序的各种设计方法也作了完整的探讨,最后还深入分析了流这种设备驱动机制。  本书内容详尽且具权威性,几乎每章都提供精选的...

    UNP v1:套接字联网API(第3版)中文PDF版

    《UNIX网络编程 卷1:套接字联网API(中文版 第3版)》...全书不但介绍了基本编程内容,还涵盖了与套接字编程相关的高级主题,对于客户/服务器程序的各种设计方法也作了完整的探讨,最后还深入分析了流这种设备驱动机制。

    unp library

    unp library and code,unp library and code,unp library and code,unp library and code,unp library and code,c

    unp源码_UNIX_

    UNP 源码,建议进阶程序员使用,用处很大

    UNIX Network Programming Volume 1, Third Edition (Unix网络编程卷1第3版英文版)

    Unix网络编程卷1,第三版,英文版。大名顶顶的Richard Stevens所写 目录: ... Addison-Wesley Professional Computing Series Foreword Preface Introduction Changes from the Second Edition ...

Global site tag (gtag.js) - Google Analytics