⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unp.lh

📁 unix网络编程卷1:套接口API的全书源码
💻 LH
📖 第 1 页 / 共 2 页
字号:
/* include unph *//* Our own header.  Tabs are set for 4 spaces, not 8 */##  1 ##src/lib/unp.h###ifndef __unp_h##  2 ##src/lib/unp.h###define __unp_h##  3 ##src/lib/unp.h###include    "../config.h"       /* configuration options for current OS */##  4 ##src/lib/unp.h##                            /* "../config.h" is generated by configure */##  5 ##src/lib/unp.h##/* If anything changes in the following list of #includes, must change##  6 ##src/lib/unp.h##   acsite.m4 also, for configure's tests. */##  7 ##src/lib/unp.h###include    <sys/types.h>       /* basic system data types */##  8 ##src/lib/unp.h###include    <sys/socket.h>      /* basic socket definitions */##  9 ##src/lib/unp.h###include    <sys/time.h>        /* timeval{} for select() */## 10 ##src/lib/unp.h###include    <time.h>            /* timespec{} for pselect() */## 11 ##src/lib/unp.h###include    <netinet/in.h>      /* sockaddr_in{} and other Internet defns */## 12 ##src/lib/unp.h###include    <arpa/inet.h>       /* inet(3) functions */## 13 ##src/lib/unp.h###include    <errno.h>## 14 ##src/lib/unp.h###include    <fcntl.h>           /* for nonblocking */## 15 ##src/lib/unp.h###include    <netdb.h>## 16 ##src/lib/unp.h###include    <signal.h>## 17 ##src/lib/unp.h###include    <stdio.h>## 18 ##src/lib/unp.h###include    <stdlib.h>## 19 ##src/lib/unp.h###include    <string.h>## 20 ##src/lib/unp.h###include    <sys/stat.h>        /* for S_xxx file mode constants */## 21 ##src/lib/unp.h###include    <sys/uio.h>         /* for iovec{} and readv/writev */## 22 ##src/lib/unp.h###include    <unistd.h>## 23 ##src/lib/unp.h###include    <sys/wait.h>## 24 ##src/lib/unp.h###include    <sys/un.h>          /* for Unix domain sockets */## 25 ##src/lib/unp.h###ifdef  HAVE_SYS_SELECT_H## 26 ##src/lib/unp.h###include    <sys/select.h>      /* for convenience */## 27 ##src/lib/unp.h###endif## 28 ##src/lib/unp.h###ifdef  HAVE_POLL_H## 29 ##src/lib/unp.h###include    <poll.h>            /* for convenience */## 30 ##src/lib/unp.h###endif## 31 ##src/lib/unp.h###ifdef  HAVE_STRINGS_H## 32 ##src/lib/unp.h###include    <strings.h>         /* for convenience */## 33 ##src/lib/unp.h###endif## 34 ##src/lib/unp.h##/* Three headers are normally needed for socket/file ioctl's:## 35 ##src/lib/unp.h## * <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.## 36 ##src/lib/unp.h## */## 37 ##src/lib/unp.h###ifdef  HAVE_SYS_IOCTL_H## 38 ##src/lib/unp.h###include    <sys/ioctl.h>## 39 ##src/lib/unp.h###endif## 40 ##src/lib/unp.h###ifdef  HAVE_SYS_FILIO_H## 41 ##src/lib/unp.h###include    <sys/filio.h>## 42 ##src/lib/unp.h###endif## 43 ##src/lib/unp.h###ifdef  HAVE_SYS_SOCKIO_H## 44 ##src/lib/unp.h###include    <sys/sockio.h>## 45 ##src/lib/unp.h###endif## 46 ##src/lib/unp.h###ifdef  HAVE_PTHREAD_H## 47 ##src/lib/unp.h###include    <pthread.h>## 48 ##src/lib/unp.h###endif## 49 ##src/lib/unp.h##/* OSF/1 actually disables recv() and send() in <sys/socket.h> */## 50 ##src/lib/unp.h###ifdef  __osf__## 51 ##src/lib/unp.h###undef  recv## 52 ##src/lib/unp.h###undef  send## 53 ##src/lib/unp.h###define recv(a,b,c,d)   recvfrom(a,b,c,d,0,0)## 54 ##src/lib/unp.h###define send(a,b,c,d)   sendto(a,b,c,d,0,0)## 55 ##src/lib/unp.h###endif## 56 ##src/lib/unp.h###ifndef INADDR_NONE## 57 ##src/lib/unp.h##/* $$.Ic INADDR_NONE$$ */#define INADDR_NONE 0xffffffff  /* should have been in <netinet/in.h> */## 58 ##src/lib/unp.h###endif## 59 ##src/lib/unp.h###ifndef SHUT_RD                 /* these three Posix.1g names are quite new */## 60 ##src/lib/unp.h###define SHUT_RD     0           /* shutdown for reading */## 61 ##src/lib/unp.h###define SHUT_WR     1           /* shutdown for writing */## 62 ##src/lib/unp.h###define SHUT_RDWR   2           /* shutdown for reading and writing */## 63 ##src/lib/unp.h##/* $$.Ic SHUT_RD$$ *//* $$.Ic SHUT_WR$$ *//* $$.Ic SHUT_RDWR$$ */#endif## 64 ##src/lib/unp.h###ifndef INET_ADDRSTRLEN## 65 ##src/lib/unp.h##/* $$.Ic INET_ADDRSTRLEN$$ */#define INET_ADDRSTRLEN     16  /* "ddd.ddd.ddd.ddd\0"## 66 ##src/lib/unp.h##                                    1234567890123456 */## 67 ##src/lib/unp.h###endif## 68 ##src/lib/unp.h##/* Define following even if IPv6 not supported, so we can always allocate## 69 ##src/lib/unp.h##   an adequately-sized buffer, without #ifdefs in the code. */## 70 ##src/lib/unp.h###ifndef INET6_ADDRSTRLEN## 71 ##src/lib/unp.h##/* $$.Ic INET6_ADDRSTRLEN$$ */#define INET6_ADDRSTRLEN    46  /* max size of IPv6 address string:## 72 ##src/lib/unp.h##                   "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or## 73 ##src/lib/unp.h##                   "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"## 74 ##src/lib/unp.h##                    1234567890123456789012345678901234567890123456 */## 75 ##src/lib/unp.h###endif## 76 ##src/lib/unp.h##/* Define bzero() as a macro if it's not in standard C library. */## 77 ##src/lib/unp.h###ifndef HAVE_BZERO## 78 ##src/lib/unp.h###define bzero(ptr,n)        memset(ptr, 0, n)## 79 ##src/lib/unp.h##/* $$.If bzero$$ *//* $$.If memset$$ */#endif## 80 ##src/lib/unp.h##/* Older resolvers do not have gethostbyname2() */## 81 ##src/lib/unp.h###ifndef HAVE_GETHOSTBYNAME2## 82 ##src/lib/unp.h###define gethostbyname2(host,family)     gethostbyname((host))## 83 ##src/lib/unp.h###endif## 84 ##src/lib/unp.h##/* The structure returned by recvfrom_flags() */## 85 ##src/lib/unp.h##struct in_pktinfo {## 86 ##src/lib/unp.h##    struct in_addr ipi_addr;    /* dst IPv4 address */## 87 ##src/lib/unp.h##    int     ipi_ifindex;        /* received interface index */## 88 ##src/lib/unp.h##};## 89 ##src/lib/unp.h##/* $$.It in_pktinfo$$ *//* $$.Ib ipi_addr$$ *//* $$.Ib ipi_ifindex$$ *//* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few## 90 ##src/lib/unp.h##   implementations support them today.  These two macros really need## 91 ##src/lib/unp.h##   an ALIGN() macro, but each implementation does this differently. */## 92 ##src/lib/unp.h###ifndef CMSG_LEN## 93 ##src/lib/unp.h##/* $$.Ic CMSG_LEN$$ */#define CMSG_LEN(size)      (sizeof(struct cmsghdr) + (size))## 94 ##src/lib/unp.h###endif## 95 ##src/lib/unp.h###ifndef CMSG_SPACE## 96 ##src/lib/unp.h##/* $$.Ic CMSG_SPACE$$ */#define CMSG_SPACE(size)    (sizeof(struct cmsghdr) + (size))## 97 ##src/lib/unp.h###endif## 98 ##src/lib/unp.h##/* Posix.1g requires the SUN_LEN() macro but not all implementations define## 99 ##src/lib/unp.h##   it (yet).  Note that this 4.4BSD macro works regardless whether there is##100 ##src/lib/unp.h##   a length field or not. */##101 ##src/lib/unp.h###ifndef SUN_LEN##102 ##src/lib/unp.h##/* $$.Im SUN_LEN$$ */#define SUN_LEN(su) \##103 ##src/lib/unp.h##    (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))##104 ##src/lib/unp.h###endif##105 ##src/lib/unp.h##/* Posix.1g renames "Unix domain" as "local IPC".##106 ##src/lib/unp.h##   But not all systems define AF_LOCAL and PF_LOCAL (yet). */##107 ##src/lib/unp.h###ifndef AF_LOCAL##108 ##src/lib/unp.h###define AF_LOCAL    AF_UNIX##109 ##src/lib/unp.h###endif##110 ##src/lib/unp.h###ifndef PF_LOCAL##111 ##src/lib/unp.h###define PF_LOCAL    PF_UNIX##112 ##src/lib/unp.h###endif##113 ##src/lib/unp.h##/* Posix.1g requires that an #include of <poll.h> define INFTIM, but many##114 ##src/lib/unp.h##   systems still define it in <sys/stropts.h>.  We don't want to include##115 ##src/lib/unp.h##   all the streams stuff if it's not needed, so we just define INFTIM here.##116 ##src/lib/unp.h##   This is the standard value, but there's no guarantee it is -1. */##117 ##src/lib/unp.h###ifndef INFTIM##118 ##src/lib/unp.h###define INFTIM          (-1)    /* infinite poll timeout */##119 ##src/lib/unp.h##/* $$.Ic INFTIM$$ */#ifdef  HAVE_POLL_H##120 ##src/lib/unp.h###define INFTIM_UNPH             /* tell unpxti.h we defined it */##121 ##src/lib/unp.h###endif##122 ##src/lib/unp.h###endif##123 ##src/lib/unp.h##/* Following could be derived from SOMAXCONN in <sys/socket.h>, but many##124 ##src/lib/unp.h##   kernels still #define it as 5, while actually supporting many more */##125 ##src/lib/unp.h###define LISTENQ     1024        /* 2nd argument to listen() */##126 ##src/lib/unp.h##/* Miscellaneous constants */##127 ##src/lib/unp.h###define MAXLINE     4096        /* max text line length */##128 ##src/lib/unp.h###define MAXSOCKADDR  128        /* max socket address structure size */##129 ##src/lib/unp.h###define BUFFSIZE    8192        /* buffer size for reads and writes */##130 ##src/lib/unp.h##/* Define some port number that can be used for client-servers */##131 ##src/lib/unp.h###define SERV_PORT        9877   /* TCP and UDP client-servers */##132 ##src/lib/unp.h###define SERV_PORT_STR   "9877"  /* TCP and UDP client-servers */##133 ##src/lib/unp.h###define UNIXSTR_PATH    "/tmp/unix.str"     /* Unix domain stream cli-serv */##134 ##src/lib/unp.h###define UNIXDG_PATH     "/tmp/unix.dg"  /* Unix domain datagram cli-serv */##135 ##src/lib/unp.h##/* $$.ix [LISTENQ]~constant,~definition~of$$ *//* $$.ix [MAXLINE]~constant,~definition~of$$ *//* $$.ix [MAXSOCKADDR]~constant,~definition~of$$ *//* $$.ix [BUFFSIZE]~constant,~definition~of$$ *//* $$.ix [SERV_PORT]~constant,~definition~of$$ *//* $$.ix [UNIXSTR_PATH]~constant,~definition~of$$ *//* $$.ix [UNIXDG_PATH]~constant,~definition~of$$ *//* Following shortens all the type casts of pointer arguments */##136 ##src/lib/unp.h###define SA  struct sockaddr##137 ##src/lib/unp.h###define FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)##138 ##src/lib/unp.h##                    /* default file access permissions for new files */##139 ##src/lib/unp.h###define DIR_MODE    (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)##140 ##src/lib/unp.h##                    /* default permissions for new directories */##141 ##src/lib/unp.h##typedef void Sigfunc (int);     /* for signal handlers */##142 ##src/lib/unp.h###define min(a,b)    ((a) < (b) ? (a) : (b))##143 ##src/lib/unp.h###define max(a,b)    ((a) > (b) ? (a) : (b))##144 ##src/lib/unp.h###ifndef HAVE_ADDRINFO_STRUCT##145 ##src/lib/unp.h###include    "../lib/addrinfo.h"##146 ##src/lib/unp.h###endif##147 ##src/lib/unp.h###ifndef HAVE_IF_NAMEINDEX_STRUCT##148 ##src/lib/unp.h##struct if_nameindex {##149 ##src/lib/unp.h##    unsigned int if_index;      /* 1, 2, ... */##150 ##src/lib/unp.h##    char   *if_name;            /* null terminated name: "le0", ... */##151 ##src/lib/unp.h##};##152 ##src/lib/unp.h##/* $$.It if_nameindex$$ *//* $$.Ib if_index$$ *//* $$.Ib if_name$$ */#endif##153 ##src/lib/unp.h###ifndef HAVE_TIMESPEC_STRUCT##154 ##src/lib/unp.h##struct timespec {##155 ##src/lib/unp.h##    time_t  tv_sec;             /* seconds */##156 ##src/lib/unp.h##    long    tv_nsec;            /* and nanoseconds */##157 ##src/lib/unp.h##};##158 ##src/lib/unp.h##/* $$.It timespec$$ *//* $$.Ib tv_sec$$ *//* $$.Ib tv_nsec$$ */#endif##159 ##src/lib/unp.h##/* end unph */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -