roken.h.in revision 90926
1248619Sdes/* -*- C -*- */ 2224638Sbrooks/* 376259Sgreen * Copyright (c) 1995 - 2001 Kungliga Tekniska H�gskolan 465668Skris * (Royal Institute of Technology, Stockholm, Sweden). 565668Skris * All rights reserved. 665668Skris * 765668Skris * Redistribution and use in source and binary forms, with or without 865668Skris * modification, are permitted provided that the following conditions 965668Skris * are met: 1065668Skris * 1165668Skris * 1. Redistributions of source code must retain the above copyright 1265668Skris * notice, this list of conditions and the following disclaimer. 1365668Skris * 1465668Skris * 2. Redistributions in binary form must reproduce the above copyright 1565668Skris * notice, this list of conditions and the following disclaimer in the 1665668Skris * documentation and/or other materials provided with the distribution. 1765668Skris * 1865668Skris * 3. Neither the name of the Institute nor the names of its contributors 1965668Skris * may be used to endorse or promote products derived from this software 2065668Skris * without specific prior written permission. 2165668Skris * 2265668Skris * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2365668Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2465668Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2565668Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2665668Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27162856Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28162856Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29162856Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30255767Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31255767Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32221420Sdes * SUCH DAMAGE. 33221420Sdes */ 34221420Sdes 35221420Sdes/* $Id: roken.h.in,v 1.162 2001/10/21 23:24:33 assar Exp $ */ 36221420Sdes 37221420Sdes#include <stdio.h> 38221420Sdes#include <stdlib.h> 39221420Sdes#include <stdarg.h> 40221420Sdes#include <string.h> 41221420Sdes#include <signal.h> 42221420Sdes 43221420Sdes#ifdef _AIX 44221420Sdesstruct ether_addr; 45221420Sdesstruct sockaddr_dl; 46221420Sdes#endif 47221420Sdes#ifdef HAVE_SYS_PARAM_H 48221420Sdes#include <sys/param.h> 49221420Sdes#endif 50221420Sdes#ifdef HAVE_INTTYPES_H 51255767Sdes#include <inttypes.h> 52255767Sdes#endif 53255767Sdes#ifdef HAVE_SYS_TYPES_H 54255767Sdes#include <sys/types.h> 55255767Sdes#endif 56255767Sdes#ifdef HAVE_SYS_BITYPES_H 57255767Sdes#include <sys/bitypes.h> 58255767Sdes#endif 59221420Sdes#ifdef HAVE_BIND_BITYPES_H 60221420Sdes#include <bind/bitypes.h> 61255767Sdes#endif 62255767Sdes#ifdef HAVE_NETINET_IN6_MACHTYPES_H 63255767Sdes#include <netinet/in6_machtypes.h> 64162856Sdes#endif 65221420Sdes#ifdef HAVE_UNISTD_H 66255767Sdes#include <unistd.h> 67221420Sdes#endif 68221420Sdes#ifdef HAVE_SYS_SOCKET_H 69221420Sdes#include <sys/socket.h> 70221420Sdes#endif 71221420Sdes#ifdef HAVE_SYS_UIO_H 72162856Sdes#include <sys/uio.h> 73162856Sdes#endif 74162856Sdes#ifdef HAVE_GRP_H 75162856Sdes#include <grp.h> 76215116Sdes#endif 77221420Sdes#ifdef HAVE_SYS_STAT_H 78221420Sdes#include <sys/stat.h> 79221420Sdes#endif 80221420Sdes#ifdef HAVE_NETINET_IN_H 81221420Sdes#include <netinet/in.h> 82221420Sdes#endif 83221420Sdes#ifdef HAVE_NETINET_IN6_H 84221420Sdes#include <netinet/in6.h> 85192595Sdes#endif 86255767Sdes#ifdef HAVE_NETINET6_IN6_H 87255767Sdes#include <netinet6/in6.h> 8869587Sgreen#endif 89192595Sdes#ifdef HAVE_ARPA_INET_H 90192595Sdes#include <arpa/inet.h> 91255767Sdes#endif 92149753Sdes#ifdef HAVE_NETDB_H 93192595Sdes#include <netdb.h> 94224638Sbrooks#endif 95224638Sbrooks#ifdef HAVE_ARPA_NAMESER_H 96224638Sbrooks#include <arpa/nameser.h> 97224638Sbrooks#endif 98255767Sdes#ifdef HAVE_RESOLV_H 9976259Sgreen#include <resolv.h> 100248619Sdes#endif 101248619Sdes#ifdef HAVE_SYSLOG_H 102248619Sdes#include <syslog.h> 103248619Sdes#endif 104248619Sdes#ifdef HAVE_FCNTL_H 105248619Sdes#include <fcntl.h> 106248619Sdes#endif 107248619Sdes#ifdef HAVE_ERRNO_H 108248619Sdes#include <errno.h> 109226046Sdes#endif 110226046Sdes#ifdef HAVE_ERR_H 111226046Sdes#include <err.h> 112248619Sdes#endif 113226046Sdes#ifdef HAVE_TERMIOS_H 114226046Sdes#include <termios.h> 11576259Sgreen#endif 116226046Sdes#if defined(HAVE_SYS_IOCTL_H) && SunOS != 40 117226046Sdes#include <sys/ioctl.h> 118226046Sdes#endif 119149753Sdes#ifdef TIME_WITH_SYS_TIME 12060573Skris#include <sys/time.h> 12160573Skris#include <time.h> 12260573Skris#elif defined(HAVE_SYS_TIME_H) 12361209Skris#include <sys/time.h> 12460573Skris#else 12560573Skris#include <time.h> 12660573Skris#endif 12760573Skris 12860573Skris#ifdef HAVE_PATHS_H 12960573Skris#include <paths.h> 13060573Skris#endif 13160573Skris 13260573Skris 13360573Skris#ifndef ROKEN_LIB_FUNCTION 13460573Skris#if defined(__BORLANDC__) 135#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet */ 136#elif defined(_MSC_VER) 137#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet2 */ 138#else 139#define ROKEN_LIB_FUNCTION 140#endif 141#endif 142 143#include <roken-common.h> 144 145ROKEN_CPP_START 146 147#if !defined(HAVE_SETSID) && defined(HAVE__SETSID) 148#define setsid _setsid 149#endif 150 151#ifndef HAVE_PUTENV 152int putenv(const char *string); 153#endif 154 155#if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO) 156int setenv(const char *var, const char *val, int rewrite); 157#endif 158 159#if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO) 160void unsetenv(const char *name); 161#endif 162 163#if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO) 164char *getusershell(void); 165void endusershell(void); 166#endif 167 168#if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO) 169int snprintf (char *str, size_t sz, const char *format, ...) 170 __attribute__ ((format (printf, 3, 4))); 171#endif 172 173#if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO) 174int vsnprintf (char *str, size_t sz, const char *format, va_list ap) 175 __attribute__((format (printf, 3, 0))); 176#endif 177 178#if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO) 179int asprintf (char **ret, const char *format, ...) 180 __attribute__ ((format (printf, 2, 3))); 181#endif 182 183#if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO) 184int vasprintf (char **ret, const char *format, va_list ap) 185 __attribute__((format (printf, 2, 0))); 186#endif 187 188#if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO) 189int asnprintf (char **ret, size_t max_sz, const char *format, ...) 190 __attribute__ ((format (printf, 3, 4))); 191#endif 192 193#if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO) 194int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap) 195 __attribute__((format (printf, 3, 0))); 196#endif 197 198#ifndef HAVE_STRDUP 199char * strdup(const char *old); 200#endif 201 202#ifndef HAVE_STRNDUP 203char * strndup(const char *old, size_t sz); 204#endif 205 206#ifndef HAVE_STRLWR 207char * strlwr(char *); 208#endif 209 210#ifndef HAVE_STRNLEN 211size_t strnlen(const char*, size_t); 212#endif 213 214#if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO) 215char *strsep(char**, const char*); 216#endif 217 218#if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO) 219ssize_t strsep_copy(const char**, const char*, char*, size_t); 220#endif 221 222#ifndef HAVE_STRCASECMP 223int strcasecmp(const char *s1, const char *s2); 224#endif 225 226#ifdef NEED_FCLOSE_PROTO 227int fclose(FILE *); 228#endif 229 230#ifdef NEED_STRTOK_R_PROTO 231char *strtok_r(char *s1, const char *s2, char **lasts); 232#endif 233 234#ifndef HAVE_STRUPR 235char * strupr(char *); 236#endif 237 238#ifndef HAVE_STRLCPY 239size_t strlcpy (char *dst, const char *src, size_t dst_sz); 240#endif 241 242#ifndef HAVE_STRLCAT 243size_t strlcat (char *dst, const char *src, size_t dst_sz); 244#endif 245 246#ifndef HAVE_GETDTABLESIZE 247int getdtablesize(void); 248#endif 249 250#if !defined(HAVE_STRERROR) && !defined(strerror) 251char *strerror(int eno); 252#endif 253 254#if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO) 255/* This causes a fatal error under Psoriasis */ 256#if !(defined(SunOS) && (SunOS >= 50)) 257const char *hstrerror(int herr); 258#endif 259#endif 260 261#ifndef HAVE_H_ERRNO_DECLARATION 262extern int h_errno; 263#endif 264 265#if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO) 266int inet_aton(const char *cp, struct in_addr *adr); 267#endif 268 269#ifndef HAVE_INET_NTOP 270const char * 271inet_ntop(int af, const void *src, char *dst, size_t size); 272#endif 273 274#ifndef HAVE_INET_PTON 275int 276inet_pton(int af, const char *src, void *dst); 277#endif 278 279#if !defined(HAVE_GETCWD) 280char* getcwd(char *path, size_t size); 281#endif 282 283#ifdef HAVE_PWD_H 284#include <pwd.h> 285struct passwd *k_getpwnam (const char *user); 286struct passwd *k_getpwuid (uid_t uid); 287#endif 288 289const char *get_default_username (void); 290 291#ifndef HAVE_SETEUID 292int seteuid(uid_t euid); 293#endif 294 295#ifndef HAVE_SETEGID 296int setegid(gid_t egid); 297#endif 298 299#ifndef HAVE_LSTAT 300int lstat(const char *path, struct stat *buf); 301#endif 302 303#if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO) 304int mkstemp(char *); 305#endif 306 307#ifndef HAVE_CGETENT 308int cgetent(char **buf, char **db_array, const char *name); 309int cgetstr(char *buf, const char *cap, char **str); 310#endif 311 312#ifndef HAVE_INITGROUPS 313int initgroups(const char *name, gid_t basegid); 314#endif 315 316#ifndef HAVE_FCHOWN 317int fchown(int fd, uid_t owner, gid_t group); 318#endif 319 320#ifndef HAVE_DAEMON 321int daemon(int nochdir, int noclose); 322#endif 323 324#ifndef HAVE_INNETGR 325int innetgr(const char *netgroup, const char *machine, 326 const char *user, const char *domain); 327#endif 328 329#ifndef HAVE_CHOWN 330int chown(const char *path, uid_t owner, gid_t group); 331#endif 332 333#ifndef HAVE_RCMD 334int rcmd(char **ahost, unsigned short inport, const char *locuser, 335 const char *remuser, const char *cmd, int *fd2p); 336#endif 337 338#if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO) 339int innetgr(const char*, const char*, const char*, const char*); 340#endif 341 342#ifndef HAVE_IRUSEROK 343int iruserok(unsigned raddr, int superuser, const char *ruser, 344 const char *luser); 345#endif 346 347#if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO) 348int gethostname(char *name, int namelen); 349#endif 350 351#ifndef HAVE_WRITEV 352ssize_t 353writev(int d, const struct iovec *iov, int iovcnt); 354#endif 355 356#ifndef HAVE_READV 357ssize_t 358readv(int d, const struct iovec *iov, int iovcnt); 359#endif 360 361#ifndef HAVE_MKSTEMP 362int 363mkstemp(char *template); 364#endif 365 366#ifndef HAVE_PIDFILE 367void pidfile (const char*); 368#endif 369 370#ifndef HAVE_BSWAP32 371unsigned int bswap32(unsigned int); 372#endif 373 374#ifndef HAVE_BSWAP16 375unsigned short bswap16(unsigned short); 376#endif 377 378#ifndef HAVE_FLOCK 379#ifndef LOCK_SH 380#define LOCK_SH 1 /* Shared lock */ 381#endif 382#ifndef LOCK_EX 383#define LOCK_EX 2 /* Exclusive lock */ 384#endif 385#ifndef LOCK_NB 386#define LOCK_NB 4 /* Don't block when locking */ 387#endif 388#ifndef LOCK_UN 389#define LOCK_UN 8 /* Unlock */ 390#endif 391 392int flock(int fd, int operation); 393#endif /* HAVE_FLOCK */ 394 395time_t tm2time (struct tm tm, int local); 396 397int unix_verify_user(char *user, char *password); 398 399void mini_inetd (int port); 400 401int roken_concat (char *s, size_t len, ...); 402 403size_t roken_mconcat (char **s, size_t max_len, ...); 404 405int roken_vconcat (char *s, size_t len, va_list args); 406 407size_t roken_vmconcat (char **s, size_t max_len, va_list args); 408 409ssize_t net_write (int fd, const void *buf, size_t nbytes); 410 411ssize_t net_read (int fd, void *buf, size_t nbytes); 412 413int issuid(void); 414 415#ifndef HAVE_STRUCT_WINSIZE 416struct winsize { 417 unsigned short ws_row, ws_col; 418 unsigned short ws_xpixel, ws_ypixel; 419}; 420#endif 421 422int get_window_size(int fd, struct winsize *); 423 424#ifndef HAVE_VSYSLOG 425void vsyslog(int pri, const char *fmt, va_list ap); 426#endif 427 428#ifndef HAVE_OPTARG_DECLARATION 429extern char *optarg; 430#endif 431#ifndef HAVE_OPTIND_DECLARATION 432extern int optind; 433#endif 434#ifndef HAVE_OPTERR_DECLARATION 435extern int opterr; 436#endif 437 438#ifndef HAVE___PROGNAME_DECLARATION 439extern const char *__progname; 440#endif 441 442#ifndef HAVE_ENVIRON_DECLARATION 443extern char **environ; 444#endif 445 446#ifndef HAVE_GETIPNODEBYNAME 447struct hostent * 448getipnodebyname (const char *name, int af, int flags, int *error_num); 449#endif 450 451#ifndef HAVE_GETIPNODEBYADDR 452struct hostent * 453getipnodebyaddr (const void *src, size_t len, int af, int *error_num); 454#endif 455 456#ifndef HAVE_FREEHOSTENT 457void 458freehostent (struct hostent *h); 459#endif 460 461#ifndef HAVE_COPYHOSTENT 462struct hostent * 463copyhostent (const struct hostent *h); 464#endif 465 466#ifndef HAVE_SOCKLEN_T 467typedef int socklen_t; 468#endif 469 470#ifndef HAVE_STRUCT_SOCKADDR_STORAGE 471 472#ifndef HAVE_SA_FAMILY_T 473typedef unsigned short sa_family_t; 474#endif 475 476#ifdef HAVE_IPV6 477#define _SS_MAXSIZE sizeof(struct sockaddr_in6) 478#else 479#define _SS_MAXSIZE sizeof(struct sockaddr_in) 480#endif 481 482#define _SS_ALIGNSIZE sizeof(unsigned long) 483 484#if HAVE_STRUCT_SOCKADDR_SA_LEN 485 486typedef unsigned char roken_sa_family_t; 487 488#define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE) 489#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) 490 491struct sockaddr_storage { 492 unsigned char ss_len; 493 roken_sa_family_t ss_family; 494 char __ss_pad1[_SS_PAD1SIZE]; 495 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; 496}; 497 498#else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */ 499 500typedef unsigned short roken_sa_family_t; 501 502#define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE) 503#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) 504 505struct sockaddr_storage { 506 roken_sa_family_t ss_family; 507 char __ss_pad1[_SS_PAD1SIZE]; 508 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; 509}; 510 511#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ 512 513#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */ 514 515#ifndef HAVE_STRUCT_ADDRINFO 516struct addrinfo { 517 int ai_flags; 518 int ai_family; 519 int ai_socktype; 520 int ai_protocol; 521 size_t ai_addrlen; 522 char *ai_canonname; 523 struct sockaddr *ai_addr; 524 struct addrinfo *ai_next; 525}; 526#endif 527 528#ifndef HAVE_GETADDRINFO 529int 530getaddrinfo(const char *nodename, 531 const char *servname, 532 const struct addrinfo *hints, 533 struct addrinfo **res); 534#endif 535 536#ifndef HAVE_GETNAMEINFO 537int getnameinfo(const struct sockaddr *sa, socklen_t salen, 538 char *host, size_t hostlen, 539 char *serv, size_t servlen, 540 int flags); 541#endif 542 543#ifndef HAVE_FREEADDRINFO 544void 545freeaddrinfo(struct addrinfo *ai); 546#endif 547 548#ifndef HAVE_GAI_STRERROR 549char * 550gai_strerror(int ecode); 551#endif 552 553int 554getnameinfo_verified(const struct sockaddr *sa, socklen_t salen, 555 char *host, size_t hostlen, 556 char *serv, size_t servlen, 557 int flags); 558 559int roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **); 560int roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **); 561 562#ifndef HAVE_STRFTIME 563size_t 564strftime (char *buf, size_t maxsize, const char *format, 565 const struct tm *tm); 566#endif 567 568#ifndef HAVE_STRPTIME 569char * 570strptime (const char *buf, const char *format, struct tm *timeptr); 571#endif 572 573#ifndef HAVE_EMALLOC 574void *emalloc (size_t); 575#endif 576#ifndef HAVE_ECALLOC 577void *ecalloc(size_t num, size_t sz); 578#endif 579#ifndef HAVE_EREALLOC 580void *erealloc (void *, size_t); 581#endif 582#ifndef HAVE_ESTRDUP 583char *estrdup (const char *); 584#endif 585 586/* 587 * kludges and such 588 */ 589 590#if 1 591int roken_gethostby_setup(const char*, const char*); 592struct hostent* roken_gethostbyname(const char*); 593struct hostent* roken_gethostbyaddr(const void*, size_t, int); 594#else 595#ifdef GETHOSTBYNAME_PROTO_COMPATIBLE 596#define roken_gethostbyname(x) gethostbyname(x) 597#else 598#define roken_gethostbyname(x) gethostbyname((char *)x) 599#endif 600 601#ifdef GETHOSTBYADDR_PROTO_COMPATIBLE 602#define roken_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t) 603#else 604#define roken_gethostbyaddr(a, l, t) gethostbyaddr((char *)a, l, t) 605#endif 606#endif 607 608#ifdef GETSERVBYNAME_PROTO_COMPATIBLE 609#define roken_getservbyname(x,y) getservbyname(x,y) 610#else 611#define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y) 612#endif 613 614#ifdef OPENLOG_PROTO_COMPATIBLE 615#define roken_openlog(a,b,c) openlog(a,b,c) 616#else 617#define roken_openlog(a,b,c) openlog((char *)a,b,c) 618#endif 619 620#ifdef GETSOCKNAME_PROTO_COMPATIBLE 621#define roken_getsockname(a,b,c) getsockname(a,b,c) 622#else 623#define roken_getsockname(a,b,c) getsockname(a, b, (void*)c) 624#endif 625 626#ifndef HAVE_SETPROGNAME 627void setprogname(const char *argv0); 628#endif 629 630#ifndef HAVE_GETPROGNAME 631const char *getprogname(void); 632#endif 633 634void set_progname(char *argv0); 635const char *get_progname(void); 636 637#ifndef HAVE_LOCALTIME_R 638struct tm * 639localtime_r(const time_t *timer, struct tm *result); 640#endif 641 642ROKEN_CPP_END 643