8 #ifdef HAVE_SYS_TIMEB_H
9 # include <sys/timeb.h>
15 #if !defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
16 extern gettimeofday(struct timeval * tv, struct timezone * tz);
26 ftime(&tb); /* FIXME: some versions are void return others int */
29 tv->tv_usec = ((long)tb.millitm)*1000;
32 tz->tz_minuteswest = 0;
41 extern void * memcpy(void * dest, void const * src, unsigned long n)
43 /* very slow, your fault for not having memcpy()*/
44 unsigned char * td=dest;
45 unsigned char * ts=src;
58 /* very slow, deal with it */
59 extern void * memset(void * dest, int c, unsigned long n)
61 unsigned char * temp=dest;
68 temp[i] = (unsigned char)c;
74 extern char * strdup(char const * str)
80 if (!(out = malloc(strlen(str)+1)))
88 extern char const * strerror(int errornum)
94 return "Operation not permitted";
98 return "No such file or directory";
102 return "No such process";
106 return "Interrupted system call";
114 return "No such device or address";
118 return "Bad file number";
121 if (errornum==EAGAIN)
125 if (errornum==ENOMEM)
126 return "Out of memory";
129 if (errornum==EACCES)
130 return "Permission denied";
133 if (errornum==EFAULT)
134 return "Bad address";
138 return "Device or resource busy";
141 if (errornum==EEXIST)
142 return "File exists";
146 return "Cross-device link";
150 return "Resource deadlock would occur";
153 if (errornum==EDEADLOCK)
154 return "Resource deadlock would occur";
157 if (errornum==ENODEV)
158 return "No such device";
161 if (errornum==ENOTDIR)
162 return "Not a directory";
165 if (errornum==EISDIR)
166 return "Is a directory";
169 if (errornum==EINVAL)
170 return "Invalid argument";
173 if (errornum==ENFILE)
174 return "Too many open files in system";
177 if (errornum==EMFILE)
178 return "Too many open files";
181 if (errornum==ENOTTY)
182 return "Not a typewriter";
185 if (errornum==ETXTBSY)
186 return "Text file busy";
190 return "File too large";
193 if (errornum==ENOSPC)
194 return "No space left on device";
197 if (errornum==ESPIPE)
198 return "Illegal seek";
202 return "Read-only file system";
205 if (errornum==EMLINK)
206 return "Too many links";
210 return "Broken pipe";
214 return "Math argument out of domain of func";
217 if (errornum==ERANGE)
218 return "Math result not representable";
221 if (errornum==ENAMETOOLONG)
222 return "File name too long";
225 if (errornum==ENOLCK)
226 return "No record locks avaliable";
229 if (errornum==ENOSYS)
230 return "Function not implemented";
233 if (errornum==ENOTEMPTY)
234 return "Directory not empty";
238 return "Too many symbolic links encountered";
241 if (errornum==EHOSTDOWN)
242 return "Host is down";
245 if (errornum==EHOSTUNREACH)
246 return "No route to host";
249 if (errornum==EALREADY)
250 return "Operation already in progress";
253 if (errornum==EINPROGRESS)
254 return "Operation now in progress";
257 if (errornum==ESTALE)
258 return "Stale NFS filehandle";
261 if (errornum==EDQUOT)
262 return "Quota exceeded";
265 if (errornum==EWOULDBLOCK)
266 return "Operation would block";
270 return "Communication error on send";
273 if (errornum==EPROTO)
274 return "Protocol error";
276 #ifdef EPROTONOSUPPORT
277 if (errornum==EPROTONOSUPPORT)
278 return "Protocol not supported";
280 #ifdef ESOCKTNOSUPPORT
281 if (errornum==ESOCKTNOSUPPORT)
282 return "Socket type not supported";
284 #ifdef ESOCKTNOSUPPORT
285 if (errornum==EOPNOTSUPP)
286 return "Operation not supported";
289 if (errornum==EPFNOSUPPORT)
290 return "Protocol family not supported";
293 if (errornum==EAFNOSUPPORT)
294 return "Address family not supported by protocol family";
297 if (errornum==EADDRINUSE)
298 return "Address already in use";
301 if (errornum==EADDRNOTAVAIL)
302 return "Cannot assign requested address";
305 if (errornum==ENETDOWN)
306 return "Network is down";
309 if (errornum==ENETUNREACH)
310 return "Network is unreachable";
313 if (errornum==ENETRESET)
314 return "Network dropped connection on reset";
317 if (errornum==ECONNABORTED)
318 return "Software caused connection abort";
321 if (errornum==ECONNRESET)
322 return " Connection reset by peer";
325 if (errornum==ENOBUFS)
326 return "No buffer space available";
329 if (errornum==EISCONN)
330 return "Socket is already connected";
333 if (errornum==ENOTCONN)
334 return "Socket is not connected";
337 if (errornum==ESHUTDOWN)
338 return " Cannot send after socket shutdown";
341 if (errornum==ETIMEDOUT)
342 return "Connection timed out";
345 if (errornum==ECONNREFUSED)
346 return "Connection refused";
348 return "Unknown error";
352 #ifndef HAVE_GETADDRINFO
354 int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
356 /* Only support IPv4 if OS doesn't provide this function. */
357 struct sockaddr_in sin;
359 if (hints && hints->ai_family != AF_INET)
361 memset(&sin, 0, sizeof(sin));
362 sin.sin_family = AF_INET;
365 if (hints && hints->ai_flags & AI_NUMERICHOST) {
366 if (!inet_aton(node, &sin.sin_addr))
370 he = gethostbyname(node);
373 memcpy(&sin.sin_addr, he->h_addr, he->h_length);
375 } else if (hints && hints->ai_flags & AI_PASSIVE) {
376 /* leave it unspecifed */
378 inet_aton("127.0.0.1", &sin.sin_addr);
382 sin.sin_port = ntohs(0);
383 else if (!(sin.sin_port = ntohs(atoi(service))))
386 *res = calloc(1, sizeof(**res) + sizeof(sin));
387 (*res)->ai_family = sin.sin_family;
388 (*res)->ai_socktype = hints && hints->ai_socktype ? hints->ai_socktype : SOCK_STREAM;
389 (*res)->ai_protocol = hints && hints->ai_socktype ? hints->ai_socktype : 0;
390 (*res)->ai_addrlen = sizeof(sin);
391 (*res)->ai_addr = (struct sockaddr*)(*res + 1);
392 memcpy((*res)->ai_addr, &sin, (*res)->ai_addrlen);
393 (*res)->ai_canonname = 0;
398 /* TODO: implement fallback getnameinfo() */
400 void freeaddrinfo(struct addrinfo *res)
402 struct addrinfo *next;
403 for (; res; res = next) {