Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/cslib.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* connect stream library implementation definitions
26
*/
27
28
#ifndef _CSLIB_H
29
#define _CSLIB_H
30
31
#define CS_INTERFACE 2 /* thread safe Cs_t* 1st arg */
32
33
#define CS_AUTH_MASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
34
#define CS_AUTH_MODE (S_ISUID|S_ISGID|S_IRUSR)
35
36
typedef struct
37
{
38
unsigned long addr;
39
unsigned long port;
40
} Inet_t;
41
42
struct Server_s;
43
typedef struct Server_s Server_t;
44
45
#define _CS_PRIVATE_ \
46
Inet_t proxy; /* proxy inet addr.port */ \
47
int db; /* csdb() state */ \
48
int interrupt; /* last interrupt */ \
49
int nostream; /* cspeek() state */ \
50
int nosocket; /* cspeek() state */ \
51
Server_t* server; /* csserve() state */ \
52
char full[4 * CS_NAME_MAX]; /* csname() full buffer */ \
53
char name[CS_NAME_MAX]; /* csname() short buffer */ \
54
char ntoa[16]; /* csntoa() buffer */ \
55
char path[PATH_MAX]; /* lib work buffer */ \
56
char temp[CS_NAME_MAX];/* lib work buffer */
57
58
#include <cs.h>
59
#include <debug.h>
60
#include <errno.h>
61
#include <sig.h>
62
#include <tok.h>
63
64
#include <ast_tty.h>
65
#include <cs_lib.h>
66
67
#if CS_LIB_V10
68
69
#include <sys/filio.h>
70
#include <sys/inio.h>
71
#include <sys/inet/in.h>
72
#include <sys/inet/tcp_user.h>
73
74
#define I_ACCEPT FIOACCEPT
75
#define I_RECVFD FIORCVFD
76
#define I_SENDFD FIOSNDFD
77
78
#define FDARG(f) (&(f))
79
80
#define strrecvfd passfd
81
82
extern int conn_ld;
83
84
#else
85
86
#if CS_LIB_SOCKET
87
88
#include <sys/socket.h>
89
90
#if CS_LIB_SOCKET_UN
91
92
#if _sys_sockio
93
#include <sys/sockio.h>
94
#else
95
#include <sys/ioctl.h>
96
#endif
97
#if _sys_uio && !defined(MAX_IOVEC)
98
#include <sys/uio.h>
99
#endif
100
#if _sys_un
101
#include <sys/un.h>
102
#endif
103
104
#endif
105
106
#if _hdr_netinet_in
107
#include <netinet/in.h>
108
#endif
109
#if _hdr_netinet_tcp
110
#include <netinet/tcp.h>
111
#endif
112
#if _hdr_netdb
113
#include <netdb.h>
114
#endif
115
116
#endif
117
118
#if CS_LIB_STREAM
119
120
#include <stropts.h>
121
122
#define FDARG(f) (f)
123
124
#endif
125
126
#endif
127
128
#if CS_LIB_STREAM || CS_LIB_V10
129
130
struct csfdhdr /* send/recv fd data header */
131
{
132
long count;
133
long pid;
134
};
135
136
#endif
137
138
#ifndef IPPORT_RESERVED
139
#define IPPORT_RESERVED 1024
140
#endif
141
#ifndef IPPORT_USERRESERVED
142
#define IPPORT_USERRESERVED 5000
143
#endif
144
145
#if !defined(htons) && !_lib_htons
146
#define htons(x) (x)
147
#endif
148
#if !defined(htonl) && !_lib_htonl
149
#define htonl(x) (x)
150
#endif
151
#if !defined(ntohs) && !_lib_ntohs
152
#define ntohs(x) (x)
153
#endif
154
#if !defined(ntohl) && !_lib_ntohl
155
#define ntohl(x) (x)
156
#endif
157
158
#if defined(F_GETFL) && defined(F_SETFL)
159
#if !defined(FAPPEND)
160
#if _sys_file
161
#include <sys/file.h>
162
#endif
163
#if !defined(FAPPEND) && defined(O_APPEND)
164
#define FAPPEND O_APPEND
165
#endif
166
#endif
167
#endif
168
#if defined(F_GETFL) && defined(F_SETFL) && defined(FAPPEND)
169
#define setauth(f,t) ((t=fcntl(f,F_GETFL,0))>=0&&fcntl(f,F_SETFL,t|FAPPEND)>=0)
170
#define getauth(f,t) ((t=fcntl(f,F_GETFL,0))>=0&&(t&FAPPEND))
171
#else
172
#define setauth(f,t) (0)
173
#define getauth(f,t) (0)
174
#endif
175
176
#if !defined(SIGCHLD) && defined(SIGCLD)
177
#define SIGCHLD SIGCLD
178
#endif
179
180
#ifdef SIGPIPE
181
#if _lib_sigblock
182
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { (h)->flags |= CS_PIPE_BLOCKED; sigblock(sigmask(SIGPIPE)); errorf((h)->id, NiL, -99, "protect"); } while (0)
183
#else
184
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { Handler_t f; (h)->flags |= CS_PIPE_BLOCKED; if ((f = signal(SIGPIPE, SIG_IGN)) != SIG_DFL) signal(SIGPIPE, f); errorf((h)->id, NiL, -99, "protect"); } while (0)
185
#endif
186
#else
187
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { (h)->flags |= CS_PIPE_BLOCKED; errorf((h)->id, NiL, -99, "protect"); } while (0)
188
#endif
189
190
#define CS_SVC_INET "inet."
191
192
#define CS_PROC_FD_TST "/proc/self/fd/."
193
#define CS_PROC_FD_FMT "/proc/%lu/fd/%u"
194
195
#define CS_KEY_SEND 0
196
#define CS_KEY_CLONE 1
197
#define CS_KEY_MAX 9
198
199
#ifndef ENOTDIR
200
#define ENOTDIR ENOENT
201
#endif
202
#ifndef EROFS
203
#define EROFS EACCES
204
#endif
205
206
#ifndef errno
207
extern int errno;
208
#endif
209
210
#if CS_LIB_SOCKET
211
#define csdb(h) do{if((h)->db<=0)cssetdb(h);}while(0)
212
#else
213
#define csdb(h)
214
#endif
215
#define cssetdb _cs_setdb
216
217
extern void cssetdb(Cs_t*);
218
219
#if CS_LIB_V10
220
extern int fmount(int, int, const char*, int);
221
#endif
222
#if CS_LIB_STREAM
223
extern int fattach(int, const char*);
224
#endif
225
226
#endif
227
228