diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-10-07 15:10:20 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-01-10 09:53:31 +0100 |
commit | c40e45b75eb76d79a05c7fa85c1fa9b5c728a12f (patch) | |
tree | ad4f2519067709f00ab98b3c591186c26dc3a21f /freebsd/lib | |
parent | userspace-header-gen.py: Simplify program ports (diff) | |
download | rtems-libbsd-c40e45b75eb76d79a05c7fa85c1fa9b5c728a12f.tar.bz2 |
Update to FreeBSD head 2016-08-23
Git mirror commit 9fe7c416e6abb28b1398fd3e5687099846800cfd.
Diffstat (limited to 'freebsd/lib')
152 files changed, 2571 insertions, 2551 deletions
diff --git a/freebsd/lib/libc/db/btree/bt_open.c b/freebsd/lib/libc/db/btree/bt_open.c index b249f5cd..ce393bbb 100644 --- a/freebsd/lib/libc/db/btree/bt_open.c +++ b/freebsd/lib/libc/db/btree/bt_open.c @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" #include <db.h> #include "btree.h" @@ -198,7 +199,7 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, int goto einval; } - if ((t->bt_fd = _open(fname, flags, mode)) < 0) + if ((t->bt_fd = _open(fname, flags | O_CLOEXEC, mode)) < 0) goto err; } else { @@ -209,9 +210,6 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, int F_SET(t, B_INMEM); } - if (_fcntl(t->bt_fd, F_SETFD, 1) == -1) - goto err; - if (_fstat(t->bt_fd, &sb)) goto err; if (sb.st_size) { @@ -281,7 +279,7 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, int b.cachesize = b.psize * MINCACHE; /* Calculate number of pages to cache. */ - ncache = (b.cachesize + t->bt_psize - 1) / t->bt_psize; + ncache = howmany(b.cachesize, t->bt_psize); /* * The btree data structure requires that at least two keys can fit on @@ -406,10 +404,10 @@ tmp(void) } (void)sigfillset(&set); - (void)_sigprocmask(SIG_BLOCK, &set, &oset); - if ((fd = mkstemp(path)) != -1) + (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset); + if ((fd = mkostemp(path, O_CLOEXEC)) != -1) (void)unlink(path); - (void)_sigprocmask(SIG_SETMASK, &oset, NULL); + (void)__libc_sigprocmask(SIG_SETMASK, &oset, NULL); return(fd); } diff --git a/freebsd/lib/libc/db/btree/bt_put.c b/freebsd/lib/libc/db/btree/bt_put.c index 885562b3..d0b54cf4 100644 --- a/freebsd/lib/libc/db/btree/bt_put.c +++ b/freebsd/lib/libc/db/btree/bt_put.c @@ -57,7 +57,7 @@ static EPG *bt_fast(BTREE *, const DBT *, const DBT *, int *); * dbp: pointer to access method * key: key * data: data - * flag: R_NOOVERWRITE + * flag: R_NOOVERWRITE, R_SETCURSOR, R_CURSOR * * Returns: * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the @@ -93,6 +93,7 @@ __bt_put(const DB *dbp, DBT *key, const DBT *data, u_int flags) switch (flags) { case 0: case R_NOOVERWRITE: + case R_SETCURSOR: break; case R_CURSOR: /* diff --git a/freebsd/lib/libc/db/btree/bt_split.c b/freebsd/lib/libc/db/btree/bt_split.c index 5ea902dd..7d47d660 100644 --- a/freebsd/lib/libc/db/btree/bt_split.c +++ b/freebsd/lib/libc/db/btree/bt_split.c @@ -38,7 +38,6 @@ static char sccsid[] = "@(#)bt_split.c 8.10 (Berkeley) 1/9/95"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <limits.h> @@ -238,9 +237,12 @@ __bt_split(BTREE *t, PAGE *sp, const DBT *key, const DBT *data, int flags, WR_BINTERNAL(dest, nksize ? nksize : bl->ksize, rchild->pgno, bl->flags & P_BIGKEY); memmove(dest, bl->bytes, nksize ? nksize : bl->ksize); - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - goto err1; + if (bl->flags & P_BIGKEY) { + pgno_t pgno; + memcpy(&pgno, bl->bytes, sizeof(pgno)); + if (bt_preserve(t, pgno) == RET_ERROR) + goto err1; + } break; case P_RINTERNAL: /* @@ -546,9 +548,12 @@ bt_broot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) * If the key is on an overflow page, mark the overflow chain * so it isn't deleted when the leaf copy of the key is deleted. */ - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)bl->bytes) == RET_ERROR) - return (RET_ERROR); + if (bl->flags & P_BIGKEY) { + pgno_t pgno; + memcpy(&pgno, bl->bytes, sizeof(pgno)); + if (bt_preserve(t, pgno) == RET_ERROR) + return (RET_ERROR); + } break; case P_BINTERNAL: bi = GETBINTERNAL(r, 0); diff --git a/freebsd/lib/libc/db/db/db.c b/freebsd/lib/libc/db/db/db.c index ffd083c7..06b45935 100644 --- a/freebsd/lib/libc/db/db/db.c +++ b/freebsd/lib/libc/db/db/db.c @@ -46,6 +46,10 @@ __FBSDID("$FreeBSD$"); static int __dberr(void); +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + DB * dbopen(const char *fname, int flags, int mode, DBTYPE type, const void *openinfo) { @@ -53,7 +57,7 @@ dbopen(const char *fname, int flags, int mode, DBTYPE type, const void *openinfo #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) #define USE_OPEN_FLAGS \ (O_CREAT | O_EXCL | O_EXLOCK | O_NOFOLLOW | O_NONBLOCK | \ - O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC) + O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC | O_CLOEXEC) if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) switch (type) { diff --git a/freebsd/lib/libc/db/recno/rec_open.c b/freebsd/lib/libc/db/recno/rec_open.c index 81945fea..1ad0bb6a 100644 --- a/freebsd/lib/libc/db/recno/rec_open.c +++ b/freebsd/lib/libc/db/recno/rec_open.c @@ -66,7 +66,7 @@ __rec_open(const char *fname, int flags, int mode, const RECNOINFO *openinfo, int rfd, sverrno; /* Open the user's file -- if this fails, we're done. */ - if (fname != NULL && (rfd = _open(fname, flags, mode)) < 0) + if (fname != NULL && (rfd = _open(fname, flags | O_CLOEXEC, mode)) < 0) return (NULL); /* Create a btree in memory (backed by disk). */ diff --git a/freebsd/lib/libc/db/recno/rec_put.c b/freebsd/lib/libc/db/recno/rec_put.c index a667022e..f8253aa7 100644 --- a/freebsd/lib/libc/db/recno/rec_put.c +++ b/freebsd/lib/libc/db/recno/rec_put.c @@ -142,8 +142,7 @@ einval: errno = EINVAL; return (RET_ERROR); if (nrec > t->bt_nrecs + 1) { if (F_ISSET(t, R_FIXLEN)) { - if ((tdata.data = - (void *)malloc(t->bt_reclen)) == NULL) + if ((tdata.data = malloc(t->bt_reclen)) == NULL) return (RET_ERROR); tdata.size = t->bt_reclen; memset(tdata.data, t->bt_bval, tdata.size); @@ -210,7 +209,7 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) return (RET_ERROR); tdata.data = db; tdata.size = NOVFLSIZE; - *(pgno_t *)db = pg; + memcpy(db, &pg, sizeof(pg)); *(u_int32_t *)(db + sizeof(pgno_t)) = data->size; dflags = P_BIGDATA; data = &tdata; diff --git a/freebsd/lib/libc/gen/err.c b/freebsd/lib/libc/gen/err.c index b83a86ed..d41d43f7 100644 --- a/freebsd/lib/libc/gen/err.c +++ b/freebsd/lib/libc/gen/err.c @@ -98,10 +98,7 @@ _err(int eval, const char *fmt, ...) } void -verr(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; +verr(int eval, const char *fmt, va_list ap) { verrc(eval, errno, fmt, ap); } @@ -118,7 +115,7 @@ errc(int eval, int code, const char *fmt, ...) void verrc(int eval, int code, const char *fmt, va_list ap) { - if (err_file == 0) + if (err_file == NULL) err_set_file((FILE *)0); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { @@ -145,7 +142,7 @@ errx(int eval, const char *fmt, ...) void verrx(int eval, const char *fmt, va_list ap) { - if (err_file == 0) + if (err_file == NULL) err_set_file((FILE *)0); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) @@ -187,7 +184,7 @@ warnc(int code, const char *fmt, ...) void vwarnc(int code, const char *fmt, va_list ap) { - if (err_file == 0) + if (err_file == NULL) err_set_file((FILE *)0); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { @@ -209,7 +206,7 @@ warnx(const char *fmt, ...) void vwarnx(const char *fmt, va_list ap) { - if (err_file == 0) + if (err_file == NULL) err_set_file((FILE *)0); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) diff --git a/freebsd/lib/libc/gen/feature_present.c b/freebsd/lib/libc/gen/feature_present.c index 9404a063..6eb44887 100644 --- a/freebsd/lib/libc/gen/feature_present.c +++ b/freebsd/lib/libc/gen/feature_present.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> /* * Returns true if the named feature is present in the currently diff --git a/freebsd/lib/libc/gen/getdomainname.c b/freebsd/lib/libc/gen/getdomainname.c index 39234deb..8aebb257 100644 --- a/freebsd/lib/libc/gen/getdomainname.c +++ b/freebsd/lib/libc/gen/getdomainname.c @@ -41,12 +41,10 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> int -getdomainname(name, namelen) - char *name; #ifndef __rtems__ - int namelen; +getdomainname(char *name, int namelen) #else /* __rtems__ */ - size_t namelen; +getdomainname(char *name, size_t namelen) #endif /* __rtems__ */ { int mib[2]; diff --git a/freebsd/lib/libc/gen/gethostname.c b/freebsd/lib/libc/gen/gethostname.c index ea0532ea..bd236852 100644 --- a/freebsd/lib/libc/gen/gethostname.c +++ b/freebsd/lib/libc/gen/gethostname.c @@ -42,9 +42,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> int -gethostname(name, namelen) - char *name; - size_t namelen; +gethostname(char *name, size_t namelen) { int mib[2]; diff --git a/freebsd/lib/libc/include/libc_private.h b/freebsd/lib/libc/include/libc_private.h index cebc035e..9fe6ab01 100644 --- a/freebsd/lib/libc/include/libc_private.h +++ b/freebsd/lib/libc/include/libc_private.h @@ -87,7 +87,7 @@ void _rtld_error(const char *fmt, ...); #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) struct _spinlock; -extern struct _spinlock __stdio_thread_lock; +extern struct _spinlock __stdio_thread_lock __hidden; #define STDIO_THREAD_LOCK() \ do { \ if (__isthreaded) \ @@ -99,6 +99,9 @@ do { \ _SPINUNLOCK(&__stdio_thread_lock); \ } while (0) +void __libc_spinlock_stub(struct _spinlock *); +void __libc_spinunlock_stub(struct _spinlock *); + /* * Indexes into the pthread jump table. * @@ -169,6 +172,9 @@ typedef enum { PJT_CLEANUP_PUSH_IMP, PJT_CANCEL_ENTER, PJT_CANCEL_LEAVE, + PJT_MUTEX_CONSISTENT, + PJT_MUTEXATTR_GETROBUST, + PJT_MUTEXATTR_SETROBUST, PJT_MAX } pjt_index_t; @@ -177,6 +183,59 @@ typedef pthread_func_t pthread_func_entry_t[2]; extern pthread_func_entry_t __thr_jtable[]; +void __set_error_selector(int *(*arg)(void)); +int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, + void *(calloc_cb)(__size_t, __size_t)); + +typedef int (*interpos_func_t)(void); +interpos_func_t *__libc_interposing_slot(int interposno); +extern interpos_func_t __libc_interposing[] __hidden; + +enum { + INTERPOS_accept, + INTERPOS_accept4, + INTERPOS_aio_suspend, + INTERPOS_close, + INTERPOS_connect, + INTERPOS_fcntl, + INTERPOS_fsync, + INTERPOS_fork, + INTERPOS_msync, + INTERPOS_nanosleep, + INTERPOS_openat, + INTERPOS_poll, + INTERPOS_pselect, + INTERPOS_recvfrom, + INTERPOS_recvmsg, + INTERPOS_select, + INTERPOS_sendmsg, + INTERPOS_sendto, + INTERPOS_setcontext, + INTERPOS_sigaction, + INTERPOS_sigprocmask, + INTERPOS_sigsuspend, + INTERPOS_sigwait, + INTERPOS_sigtimedwait, + INTERPOS_sigwaitinfo, + INTERPOS_swapcontext, + INTERPOS_system, + INTERPOS_tcdrain, + INTERPOS_read, + INTERPOS_readv, + INTERPOS_wait4, + INTERPOS_write, + INTERPOS_writev, + INTERPOS__pthread_mutex_init_calloc_cb, + INTERPOS_spinlock, + INTERPOS_spinunlock, + INTERPOS_kevent, + INTERPOS_wait6, + INTERPOS_ppoll, + INTERPOS_map_stacks_exec, + INTERPOS_fdatasync, + INTERPOS_MAX +}; + /* * yplib internal interfaces */ @@ -213,48 +272,123 @@ extern const char *__progname; void _malloc_thread_cleanup(void); /* + * This function is used by the threading libraries to notify libc that a + * thread is exiting, so its thread-local dtors should be called. + */ +void __cxa_thread_call_dtors(void); + +/* * These functions are used by the threading libraries in order to protect * malloc across fork(). */ void _malloc_prefork(void); void _malloc_postfork(void); +void _malloc_first_thread(void); + /* * Function to clean up streams, called from abort() and exit(). */ -extern void (*__cleanup)(void); +extern void (*__cleanup)(void) __hidden; /* * Get kern.osreldate to detect ABI revisions. Explicitly - * ignores value of $OSVERSION and caches result. Prototypes - * for the wrapped "new" pad-less syscalls are here for now. + * ignores value of $OSVERSION and caches result. */ -extern int __getosreldate(void); +int __getosreldate(void); #include <sys/_types.h> -/* Without pad */ -extern __off_t __sys_lseek(int, __off_t, int); -extern int __sys_ftruncate(int, __off_t); -extern int __sys_truncate(const char *, __off_t); -extern __ssize_t __sys_pread(int, void *, __size_t, __off_t); -extern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); -extern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); - -/* With pad */ -extern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); -extern int __sys_freebsd6_ftruncate(int, int, __off_t); -extern int __sys_freebsd6_truncate(const char *, int, __off_t); -extern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); -extern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); -extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); - -/* Without back-compat translation */ -extern int __sys_fcntl(int, int, ...); +#include <sys/_sigset.h> +struct aiocb; +struct fd_set; +struct iovec; +struct kevent; +struct msghdr; +struct pollfd; +struct rusage; +struct sigaction; +struct sockaddr; struct timespec; struct timeval; struct timezone; -int __sys_gettimeofday(struct timeval *, struct timezone *); -int __sys_clock_gettime(__clockid_t, struct timespec *ts); +struct __siginfo; +struct __ucontext; +struct __wrusage; +enum idtype; +int __sys_aio_suspend(const struct aiocb * const[], int, + const struct timespec *); +int __sys_accept(int, struct sockaddr *, __socklen_t *); +int __sys_accept4(int, struct sockaddr *, __socklen_t *, int); +int __sys_clock_gettime(__clockid_t, struct timespec *ts); +int __sys_close(int); +int __sys_connect(int, const struct sockaddr *, __socklen_t); +int __sys_fcntl(int, int, ...); +int __sys_fdatasync(int); +int __sys_fsync(int); +__pid_t __sys_fork(void); +int __sys_ftruncate(int, __off_t); +int __sys_gettimeofday(struct timeval *, struct timezone *); +int __sys_kevent(int, const struct kevent *, int, struct kevent *, + int, const struct timespec *); +__off_t __sys_lseek(int, __off_t, int); +void *__sys_mmap(void *, __size_t, int, int, int, __off_t); +int __sys_msync(void *, __size_t, int); +int __sys_nanosleep(const struct timespec *, struct timespec *); +int __sys_open(const char *, int, ...); +int __sys_openat(int, const char *, int, ...); +int __sys_pselect(int, struct fd_set *, struct fd_set *, + struct fd_set *, const struct timespec *, + const __sigset_t *); +int __sys_poll(struct pollfd *, unsigned, int); +int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *, + const __sigset_t *); +__ssize_t __sys_pread(int, void *, __size_t, __off_t); +__ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); +__ssize_t __sys_read(int, void *, __size_t); +__ssize_t __sys_readv(int, const struct iovec *, int); +__ssize_t __sys_recv(int, void *, __size_t, int); +__ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *, + __socklen_t *); +__ssize_t __sys_recvmsg(int, struct msghdr *, int); +int __sys_select(int, struct fd_set *, struct fd_set *, + struct fd_set *, struct timeval *); +__ssize_t __sys_sendmsg(int, const struct msghdr *, int); +__ssize_t __sys_sendto(int, const void *, __size_t, int, + const struct sockaddr *, __socklen_t); +int __sys_setcontext(const struct __ucontext *); +int __sys_sigaction(int, const struct sigaction *, + struct sigaction *); +int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *); +int __sys_sigsuspend(const __sigset_t *); +int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *, + const struct timespec *); +int __sys_sigwait(const __sigset_t *, int *); +int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *); +int __sys_swapcontext(struct __ucontext *, + const struct __ucontext *); +int __sys_thr_kill(long, int); +int __sys_thr_self(long *); +int __sys_truncate(const char *, __off_t); +__pid_t __sys_wait4(__pid_t, int *, int, struct rusage *); +__pid_t __sys_wait6(enum idtype, __id_t, int *, int, + struct __wrusage *, struct __siginfo *); +__ssize_t __sys_write(int, const void *, __size_t); +__ssize_t __sys_writev(int, const struct iovec *, int); + +int __libc_sigaction(int, const struct sigaction *, + struct sigaction *) __hidden; +int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *) + __hidden; +int __libc_sigsuspend(const __sigset_t *) __hidden; +int __libc_sigwait(const __sigset_t * __restrict, + int * restrict sig); +int __libc_system(const char *); +int __libc_tcdrain(int); +int __fcntl_compat(int fd, int cmd, ...); + +int __sys_futimens(int fd, const struct timespec *times) __hidden; +int __sys_utimensat(int fd, const char *path, + const struct timespec *times, int flag) __hidden; /* execve() with PATH processing to implement posix_spawnp() */ int _execvpe(const char *, char * const *, char * const *); @@ -263,6 +397,7 @@ int _elf_aux_info(int aux, void *buf, int buflen); struct dl_phdr_info; int __elf_phdr_match_addr(struct dl_phdr_info *, void *); void __init_elf_aux_vector(void); +void __libc_map_stacks_exec(void); void _pthread_cancel_enter(int); void _pthread_cancel_leave(int); diff --git a/freebsd/lib/libc/include/namespace.h b/freebsd/lib/libc/include/namespace.h index 8b2f04b1..8af80817 100644 --- a/freebsd/lib/libc/include/namespace.h +++ b/freebsd/lib/libc/include/namespace.h @@ -35,16 +35,199 @@ */ -#define _pthread_getspecific pthread_getspecific -#define _pthread_key_create pthread_key_create -#define _pthread_main_np pthread_main_np -#define _pthread_once pthread_once -#define _pthread_setspecific pthread_setspecific -#define _pthread_mutex_trylock pthread_mutex_trylock -#define _pthread_mutex_unlock pthread_mutex_unlock -#define _pthread_rwlock_rdlock pthread_rwlock_rdlock -#define _pthread_rwlock_unlock pthread_rwlock_unlock -#define _pthread_rwlock_wrlock pthread_rwlock_wrlock +/* + * Prototypes for syscalls/functions that need to be overridden + * in libc_r/libpthread. + */ +#ifndef __rtems__ +#define accept _accept +#define __acl_aclcheck_fd ___acl_aclcheck_fd +#define __acl_delete_fd ___acl_delete_fd +#define __acl_get_fd ___acl_get_fd +#define __acl_set_fd ___acl_set_fd +#define bind _bind +#define __cap_get_fd ___cap_get_fd +#define __cap_set_fd ___cap_set_fd +#define close _close +#define connect _connect +#define dup _dup +#define dup2 _dup2 +#define execve _execve +#define fcntl _fcntl +/*#define flock _flock */ +#define flockfile _flockfile +#define fpathconf _fpathconf +#define fstat _fstat +#define fstatfs _fstatfs +#define fsync _fsync +#define funlockfile _funlockfile +#define getdirentries _getdirentries +#define getlogin _getlogin +#define getpeername _getpeername +#define getprogname _getprogname +#define getsockname _getsockname +#define getsockopt _getsockopt +#define ioctl _ioctl +/* #define kevent _kevent */ +#define listen _listen +#define nanosleep _nanosleep +#define open _open +#define openat _openat +#define poll _poll +#define pthread_atfork _pthread_atfork +#define pthread_attr_destroy _pthread_attr_destroy +#define pthread_attr_get_np _pthread_attr_get_np +#define pthread_attr_getaffinity_np _pthread_attr_getaffinity_np +#define pthread_attr_getdetachstate _pthread_attr_getdetachstate +#define pthread_attr_getguardsize _pthread_attr_getguardsize +#define pthread_attr_getinheritsched _pthread_attr_getinheritsched +#define pthread_attr_getschedparam _pthread_attr_getschedparam +#define pthread_attr_getschedpolicy _pthread_attr_getschedpolicy +#define pthread_attr_getscope _pthread_attr_getscope +#define pthread_attr_getstack _pthread_attr_getstack +#define pthread_attr_getstackaddr _pthread_attr_getstackaddr +#define pthread_attr_getstacksize _pthread_attr_getstacksize +#define pthread_attr_init _pthread_attr_init +#define pthread_attr_setaffinity_np _pthread_attr_setaffinity_np +#define pthread_attr_setcreatesuspend_np _pthread_attr_setcreatesuspend_np +#define pthread_attr_setdetachstate _pthread_attr_setdetachstate +#define pthread_attr_setguardsize _pthread_attr_setguardsize +#define pthread_attr_setinheritsched _pthread_attr_setinheritsched +#define pthread_attr_setschedparam _pthread_attr_setschedparam +#define pthread_attr_setschedpolicy _pthread_attr_setschedpolicy +#define pthread_attr_setscope _pthread_attr_setscope +#define pthread_attr_setstack _pthread_attr_setstack +#define pthread_attr_setstackaddr _pthread_attr_setstackaddr +#define pthread_attr_setstacksize _pthread_attr_setstacksize +#define pthread_barrier_destroy _pthread_barrier_destroy +#define pthread_barrier_init _pthread_barrier_init +#define pthread_barrier_wait _pthread_barrier_wait +#define pthread_barrierattr_destroy _pthread_barrierattr_destroy +#define pthread_barrierattr_getpshared _pthread_barrierattr_getpshared +#define pthread_barrierattr_init _pthread_barrierattr_init +#define pthread_barrierattr_setpshared _pthread_barrierattr_setpshared +#define pthread_cancel _pthread_cancel +#define pthread_cond_broadcast _pthread_cond_broadcast +#define pthread_cond_destroy _pthread_cond_destroy +#define pthread_cond_init _pthread_cond_init +#define pthread_cond_signal _pthread_cond_signal +#define pthread_cond_timedwait _pthread_cond_timedwait +#define pthread_cond_wait _pthread_cond_wait +#define pthread_condattr_destroy _pthread_condattr_destroy +#define pthread_condattr_getclock _pthread_condattr_getclock +#define pthread_condattr_getpshared _pthread_condattr_getpshared +#define pthread_condattr_init _pthread_condattr_init +#define pthread_condattr_setclock _pthread_condattr_setclock +#define pthread_condattr_setpshared _pthread_condattr_setpshared +#define pthread_create _pthread_create +#define pthread_detach _pthread_detach +#define pthread_equal _pthread_equal +#define pthread_exit _pthread_exit +#define pthread_getaffinity_np _pthread_getaffinity_np +#define pthread_getconcurrency _pthread_getconcurrency +#define pthread_getcpuclockid _pthread_getcpuclockid +#define pthread_getprio _pthread_getprio +#define pthread_getschedparam _pthread_getschedparam +#define pthread_getspecific _pthread_getspecific +#define pthread_getthreadid_np _pthread_getthreadid_np +#define pthread_join _pthread_join +#define pthread_key_create _pthread_key_create +#define pthread_key_delete _pthread_key_delete +#define pthread_kill _pthread_kill +#define pthread_main_np _pthread_main_np +#define pthread_multi_np _pthread_multi_np +#define pthread_mutex_destroy _pthread_mutex_destroy +#define pthread_mutex_getprioceiling _pthread_mutex_getprioceiling +#define pthread_mutex_init _pthread_mutex_init +#define pthread_mutex_isowned_np _pthread_mutex_isowned_np +#define pthread_mutex_lock _pthread_mutex_lock +#define pthread_mutex_setprioceiling _pthread_mutex_setprioceiling +#define pthread_mutex_timedlock _pthread_mutex_timedlock +#define pthread_mutex_trylock _pthread_mutex_trylock +#define pthread_mutex_unlock _pthread_mutex_unlock +#define pthread_mutexattr_destroy _pthread_mutexattr_destroy +#define pthread_mutexattr_getkind_np _pthread_mutexattr_getkind_np +#define pthread_mutexattr_getprioceiling _pthread_mutexattr_getprioceiling +#define pthread_mutexattr_getprotocol _pthread_mutexattr_getprotocol +#define pthread_mutexattr_getpshared _pthread_mutexattr_getpshared +#define pthread_mutexattr_gettype _pthread_mutexattr_gettype +#define pthread_mutexattr_init _pthread_mutexattr_init +#define pthread_mutexattr_setkind_np _pthread_mutexattr_setkind_np +#define pthread_mutexattr_setprioceiling _pthread_mutexattr_setprioceiling +#define pthread_mutexattr_setprotocol _pthread_mutexattr_setprotocol +#define pthread_mutexattr_setpshared _pthread_mutexattr_setpshared +#define pthread_mutexattr_settype _pthread_mutexattr_settype +#define pthread_once _pthread_once +#define pthread_resume_all_np _pthread_resume_all_np +#define pthread_resume_np _pthread_resume_np +#define pthread_rwlock_destroy _pthread_rwlock_destroy +#define pthread_rwlock_init _pthread_rwlock_init +#define pthread_rwlock_rdlock _pthread_rwlock_rdlock +#define pthread_rwlock_timedrdlock _pthread_rwlock_timedrdlock +#define pthread_rwlock_timedwrlock _pthread_rwlock_timedwrlock +#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock +#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock +#define pthread_rwlock_unlock _pthread_rwlock_unlock +#define pthread_rwlock_wrlock _pthread_rwlock_wrlock +#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy +#define pthread_rwlockattr_getpshared _pthread_rwlockattr_getpshared +#define pthread_rwlockattr_init _pthread_rwlockattr_init +#define pthread_rwlockattr_setpshared _pthread_rwlockattr_setpshared +#define pthread_self _pthread_self +#define pthread_set_name_np _pthread_set_name_np +#define pthread_setaffinity_np _pthread_setaffinity_np +#define pthread_setcancelstate _pthread_setcancelstate +#define pthread_setcanceltype _pthread_setcanceltype +#define pthread_setconcurrency _pthread_setconcurrency +#define pthread_setprio _pthread_setprio +#define pthread_setschedparam _pthread_setschedparam +#define pthread_setspecific _pthread_setspecific +#define pthread_sigmask _pthread_sigmask +#define pthread_single_np _pthread_single_np +#define pthread_spin_destroy _pthread_spin_destroy +#define pthread_spin_init _pthread_spin_init +#define pthread_spin_lock _pthread_spin_lock +#define pthread_spin_trylock _pthread_spin_trylock +#define pthread_spin_unlock _pthread_spin_unlock +#define pthread_suspend_all_np _pthread_suspend_all_np +#define pthread_suspend_np _pthread_suspend_np +#define pthread_switch_add_np _pthread_switch_add_np +#define pthread_switch_delete_np _pthread_switch_delete_np +#define pthread_testcancel _pthread_testcancel +#define pthread_timedjoin_np _pthread_timedjoin_np +#define pthread_yield _pthread_yield +#define read _read +#define readv _readv +#define recvfrom _recvfrom +#define recvmsg _recvmsg +#define recvmmsg _recvmmsg +#define select _select +#define sem_close _sem_close +#define sem_destroy _sem_destroy +#define sem_getvalue _sem_getvalue +#define sem_init _sem_init +#define sem_open _sem_open +#define sem_post _sem_post +#define sem_timedwait _sem_timedwait +#define sem_trywait _sem_trywait +#define sem_unlink _sem_unlink +#define sem_wait _sem_wait +#define sendmsg _sendmsg +#define sendmmsg _sendmmsg +#define sendto _sendto +#define setsockopt _setsockopt +/*#define sigaction _sigaction*/ +#define sigprocmask _sigprocmask +#define sigsuspend _sigsuspend +#define socket _socket +#define socketpair _socketpair +#define usleep _usleep +#define wait4 _wait4 +#define wait6 _wait6 +#define waitpid _waitpid +#define write _write +#define writev _writev +#endif /* __rtems__ */ #define _open open #define _close close @@ -68,9 +251,18 @@ #define _getprogname getprogname #define _getsockname getsockname #ifdef __rtems__ -#define _pthread_mutex_lock pthread_mutex_lock -#define _getsockopt getsockopt #define _bind bind +#define _getsockopt getsockopt +#define _poll poll +#define _pthread_getspecific pthread_getspecific +#define _pthread_key_create pthread_key_create +#define _pthread_mutex_lock pthread_mutex_lock +#define _pthread_mutex_unlock pthread_mutex_unlock +#define _pthread_once pthread_once +#define _pthread_rwlock_rdlock pthread_rwlock_rdlock +#define _pthread_rwlock_unlock pthread_rwlock_unlock +#define _pthread_rwlock_wrlock pthread_rwlock_wrlock +#define _pthread_setspecific pthread_setspecific #endif /* __rtems__ */ #endif /* _NAMESPACE_H_ */ diff --git a/freebsd/lib/libc/include/port_before.h b/freebsd/lib/libc/include/port_before.h index 4b6e3590..430d2336 100644 --- a/freebsd/lib/libc/include/port_before.h +++ b/freebsd/lib/libc/include/port_before.h @@ -5,7 +5,7 @@ #define _LIBC 1 #define DO_PTHREADS 1 -#define USE_KQUEUE 1 +#define USE_POLL 1 #define HAVE_MD5 1 #define ISC_SOCKLEN_T socklen_t diff --git a/freebsd/lib/libc/include/reentrant.h b/freebsd/lib/libc/include/reentrant.h index 5debcf1a..8e0b90f5 100644 --- a/freebsd/lib/libc/include/reentrant.h +++ b/freebsd/lib/libc/include/reentrant.h @@ -49,7 +49,7 @@ * One approach for thread safety is to provide discrete versions of the * library: one thread safe, the other not. The disadvantage of this is * that libc is rather large, and two copies of a library which are 99%+ - * identical is not an efficent use of resources. + * identical is not an efficient use of resources. * * Another approach is to provide a single thread safe library. However, * it should not add significant run time or code size overhead to non- diff --git a/freebsd/lib/libc/include/un-namespace.h b/freebsd/lib/libc/include/un-namespace.h index 287a2382..6cfb4ef0 100644 --- a/freebsd/lib/libc/include/un-namespace.h +++ b/freebsd/lib/libc/include/un-namespace.h @@ -29,4 +29,232 @@ #ifndef _UN_NAMESPACE_H_ #define _UN_NAMESPACE_H_ +#ifdef __rtems__ +#undef accept +#undef __acl_aclcheck_fd +#undef __acl_delete_fd +#undef __acl_get_fd +#undef __acl_set_fd +#undef bind +#undef __cap_get_fd +#undef __cap_set_fd +#undef close +#undef connect +#undef dup +#undef dup2 +#undef execve +#undef fcntl +#undef flock +#undef flockfile +#undef fpathconf +#undef fstat +#undef fstatfs +#undef fsync +#undef funlockfile +#undef getdirentries +#undef getlogin +#undef getpeername +#undef getprogname +#undef getsockname +#undef getsockopt +#undef ioctl +#undef kevent +#undef listen +#undef nanosleep +#undef open +#undef openat +#undef poll +#undef pthread_atfork +#undef pthread_attr_destroy +#undef pthread_attr_get_np +#undef pthread_attr_getaffinity_np +#undef pthread_attr_getdetachstate +#undef pthread_attr_getguardsize +#undef pthread_attr_getinheritsched +#undef pthread_attr_getschedparam +#undef pthread_attr_getschedpolicy +#undef pthread_attr_getscope +#undef pthread_attr_getstack +#undef pthread_attr_getstackaddr +#undef pthread_attr_getstacksize +#undef pthread_attr_init +#undef pthread_attr_setaffinity_np +#undef pthread_attr_setcreatesuspend_np +#undef pthread_attr_setdetachstate +#undef pthread_attr_setguardsize +#undef pthread_attr_setinheritsched +#undef pthread_attr_setschedparam +#undef pthread_attr_setschedpolicy +#undef pthread_attr_setscope +#undef pthread_attr_setstack +#undef pthread_attr_setstackaddr +#undef pthread_attr_setstacksize +#undef pthread_barrier_destroy +#undef pthread_barrier_init +#undef pthread_barrier_wait +#undef pthread_barrierattr_destroy +#undef pthread_barrierattr_getpshared +#undef pthread_barrierattr_init +#undef pthread_barrierattr_setpshared +#undef pthread_cancel +#undef pthread_cond_broadcast +#undef pthread_cond_destroy +#undef pthread_cond_init +#undef pthread_cond_signal +#undef pthread_cond_timedwait +#undef pthread_cond_wait +#undef pthread_condattr_destroy +#undef pthread_condattr_getclock +#undef pthread_condattr_getpshared +#undef pthread_condattr_init +#undef pthread_condattr_setclock +#undef pthread_condattr_setpshared +#undef pthread_create +#undef pthread_detach +#undef pthread_equal +#undef pthread_exit +#undef pthread_getaffinity_np +#undef pthread_getconcurrency +#undef pthread_getcpuclockid +#undef pthread_getprio +#undef pthread_getschedparam +#undef pthread_getspecific +#undef pthread_getthreadid_np +#undef pthread_join +#undef pthread_key_create +#undef pthread_key_delete +#undef pthread_kill +#undef pthread_main_np +#undef pthread_multi_np +#undef pthread_mutex_destroy +#undef pthread_mutex_getprioceiling +#undef pthread_mutex_init +#undef pthread_mutex_isowned_np +#undef pthread_mutex_lock +#undef pthread_mutex_setprioceiling +#undef pthread_mutex_timedlock +#undef pthread_mutex_trylock +#undef pthread_mutex_unlock +#undef pthread_mutexattr_destroy +#undef pthread_mutexattr_getkind_np +#undef pthread_mutexattr_getprioceiling +#undef pthread_mutexattr_getprotocol +#undef pthread_mutexattr_getpshared +#undef pthread_mutexattr_gettype +#undef pthread_mutexattr_init +#undef pthread_mutexattr_setkind_np +#undef pthread_mutexattr_setprioceiling +#undef pthread_mutexattr_setprotocol +#undef pthread_mutexattr_setpshared +#undef pthread_mutexattr_settype +#undef pthread_once +#undef pthread_resume_all_np +#undef pthread_resume_np +#undef pthread_rwlock_destroy +#undef pthread_rwlock_init +#undef pthread_rwlock_rdlock +#undef pthread_rwlock_timedrdlock +#undef pthread_rwlock_timedwrlock +#undef pthread_rwlock_tryrdlock +#undef pthread_rwlock_trywrlock +#undef pthread_rwlock_unlock +#undef pthread_rwlock_wrlock +#undef pthread_rwlockattr_destroy +#undef pthread_rwlockattr_getpshared +#undef pthread_rwlockattr_init +#undef pthread_rwlockattr_setpshared +#undef pthread_self +#undef pthread_set_name_np +#undef pthread_setaffinity_np +#undef pthread_setcancelstate +#undef pthread_setcanceltype +#undef pthread_setconcurrency +#undef pthread_setprio +#undef pthread_setschedparam +#undef pthread_setspecific +#undef pthread_sigmask +#undef pthread_single_np +#undef pthread_spin_destroy +#undef pthread_spin_init +#undef pthread_spin_lock +#undef pthread_spin_trylock +#undef pthread_spin_unlock +#undef pthread_suspend_all_np +#undef pthread_suspend_np +#undef pthread_switch_add_np +#undef pthread_switch_delete_np +#undef pthread_testcancel +#undef pthread_timedjoin_np +#undef pthread_yield +#undef read +#undef readv +#undef recvfrom +#undef recvmsg +#undef recvmmsg +#undef select +#undef sem_close +#undef sem_destroy +#undef sem_getvalue +#undef sem_init +#undef sem_open +#undef sem_post +#undef sem_timedwait +#undef sem_trywait +#undef sem_unlink +#undef sem_wait +#undef sendmsg +#undef sendmmsg +#undef sendto +#undef setsockopt +#undef sigaction +#undef sigprocmask +#undef sigsuspend +#undef socket +#undef socketpair +#undef usleep +#undef wait4 +#undef wait6 +#undef waitpid +#undef write +#undef writev + +#if 0 +#undef creat +#undef fchflags +#undef fchmod +#undef ftrylockfile +#undef msync +#undef nfssvc +#undef pause +#undef sched_yield +#undef sendfile +#undef shutdown +#undef sigaltstack +#undef sigpending +#undef sigreturn +#undef sigsetmask +#undef sleep +#undef system +#undef tcdrain +#undef wait +#endif /* 0 */ + +#ifdef _SIGNAL_H_ +int _sigaction(int, const struct sigaction *, struct sigaction *); +#endif + +#ifdef _SYS_EVENT_H_ +int _kevent(int, const struct kevent *, int, struct kevent *, + int, const struct timespec *); +#endif + +#ifdef _SYS_FCNTL_H_ +int _flock(int, int); +#endif + +#undef err +#undef warn +#undef nsdispatch +#endif /* __rtems__ */ + #endif /* _UN_NAMESPACE_H_ */ diff --git a/freebsd/lib/libc/inet/inet_addr.c b/freebsd/lib/libc/inet/inet_addr.c index e0980f6c..3df3b0c0 100644 --- a/freebsd/lib/libc/inet/inet_addr.c +++ b/freebsd/lib/libc/inet/inet_addr.c @@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <netinet/in.h> diff --git a/freebsd/lib/libc/inet/inet_lnaof.c b/freebsd/lib/libc/inet/inet_lnaof.c index 13699bed..868570bf 100644 --- a/freebsd/lib/libc/inet/inet_lnaof.c +++ b/freebsd/lib/libc/inet/inet_lnaof.c @@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$"); * number formats. */ in_addr_t -inet_lnaof(in) - struct in_addr in; +inet_lnaof(struct in_addr in) { in_addr_t i = ntohl(in.s_addr); diff --git a/freebsd/lib/libc/inet/inet_makeaddr.c b/freebsd/lib/libc/inet/inet_makeaddr.c index 8c60363d..f2637342 100644 --- a/freebsd/lib/libc/inet/inet_makeaddr.c +++ b/freebsd/lib/libc/inet/inet_makeaddr.c @@ -48,8 +48,7 @@ __FBSDID("$FreeBSD$"); * building addresses stored in the ifnet structure. */ struct in_addr -inet_makeaddr(net, host) - in_addr_t net, host; +inet_makeaddr(in_addr_t net, in_addr_t host) { struct in_addr a; diff --git a/freebsd/lib/libc/inet/inet_net_ntop.c b/freebsd/lib/libc/inet/inet_net_ntop.c index 49e20fb8..31c04aba 100644 --- a/freebsd/lib/libc/inet/inet_net_ntop.c +++ b/freebsd/lib/libc/inet/inet_net_ntop.c @@ -59,12 +59,7 @@ static char * inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, * Paul Vixie (ISC), July 1996 */ char * -inet_net_ntop(af, src, bits, dst, size) - int af; - const void *src; - int bits; - char *dst; - size_t size; +inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { case AF_INET: @@ -91,11 +86,7 @@ inet_net_ntop(af, src, bits, dst, size) * Paul Vixie (ISC), July 1996 */ static char * -inet_net_ntop_ipv4(src, bits, dst, size) - const u_char *src; - int bits; - char *dst; - size_t size; +inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { char *odst = dst; char *t; diff --git a/freebsd/lib/libc/inet/inet_neta.c b/freebsd/lib/libc/inet/inet_neta.c index 14b75c18..2cab5934 100644 --- a/freebsd/lib/libc/inet/inet_neta.c +++ b/freebsd/lib/libc/inet/inet_neta.c @@ -54,10 +54,7 @@ __FBSDID("$FreeBSD$"); * Paul Vixie (ISC), July 1996 */ char * -inet_neta(src, dst, size) - in_addr_t src; - char *dst; - size_t size; +inet_neta(in_addr_t src, char *dst, size_t size) { char *odst = dst; char *tp; diff --git a/freebsd/lib/libc/inet/inet_netof.c b/freebsd/lib/libc/inet/inet_netof.c index b782395e..6dda5b1b 100644 --- a/freebsd/lib/libc/inet/inet_netof.c +++ b/freebsd/lib/libc/inet/inet_netof.c @@ -48,8 +48,7 @@ __FBSDID("$FreeBSD$"); * address; handles class a/b/c network #'s. */ in_addr_t -inet_netof(in) - struct in_addr in; +inet_netof(struct in_addr in) { in_addr_t i = ntohl(in.s_addr); diff --git a/freebsd/lib/libc/inet/inet_network.c b/freebsd/lib/libc/inet/inet_network.c index 88a760c4..3c087ec4 100644 --- a/freebsd/lib/libc/inet/inet_network.c +++ b/freebsd/lib/libc/inet/inet_network.c @@ -50,8 +50,7 @@ __FBSDID("$FreeBSD$"); * network numbers. */ in_addr_t -inet_network(cp) - const char *cp; +inet_network(const char *cp) { in_addr_t val, base, n; char c; diff --git a/freebsd/lib/libc/inet/inet_ntop.c b/freebsd/lib/libc/inet/inet_ntop.c index 5cd6a7e0..a3f49d2f 100644 --- a/freebsd/lib/libc/inet/inet_ntop.c +++ b/freebsd/lib/libc/inet/inet_ntop.c @@ -26,7 +26,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -47,7 +46,7 @@ __FBSDID("$FreeBSD$"); static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size); static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); -/* char * +/* const char * * inet_ntop(af, src, dst, size) * convert a network format address to presentation format. * return: @@ -171,8 +170,10 @@ inet_ntop6(const u_char *src, char *dst, socklen_t size) if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) + if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) { + errno = ENOSPC; return (NULL); + } tp += strlen(tp); break; } diff --git a/freebsd/lib/libc/inet/inet_pton.c b/freebsd/lib/libc/inet/inet_pton.c index 738b9b50..605076e5 100644 --- a/freebsd/lib/libc/inet/inet_pton.c +++ b/freebsd/lib/libc/inet/inet_pton.c @@ -25,7 +25,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> diff --git a/freebsd/lib/libc/inet/nsap_addr.c b/freebsd/lib/libc/inet/nsap_addr.c index 5489f983..e46d8848 100644 --- a/freebsd/lib/libc/inet/nsap_addr.c +++ b/freebsd/lib/libc/inet/nsap_addr.c @@ -25,7 +25,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> diff --git a/freebsd/lib/libc/isc/ev_timers.c b/freebsd/lib/libc/isc/ev_timers.c index 74dda8ea..56efe06f 100644 --- a/freebsd/lib/libc/isc/ev_timers.c +++ b/freebsd/lib/libc/isc/ev_timers.c @@ -119,7 +119,7 @@ evCmpTime(struct timespec a, struct timespec b) { } struct timespec -evNowTime() { +evNowTime(void) { struct timeval now; #ifdef CLOCK_REALTIME struct timespec tsnow; @@ -138,7 +138,7 @@ evNowTime() { } struct timespec -evUTCTime() { +evUTCTime(void) { struct timeval now; #ifdef CLOCK_REALTIME struct timespec tsnow; diff --git a/freebsd/lib/libc/isc/eventlib_p.h b/freebsd/lib/libc/isc/eventlib_p.h index 678f5ee7..495e8d1e 100644 --- a/freebsd/lib/libc/isc/eventlib_p.h +++ b/freebsd/lib/libc/isc/eventlib_p.h @@ -27,7 +27,6 @@ #define _EVENTLIB_P_H #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/un.h> diff --git a/freebsd/lib/libc/nameser/ns_samedomain.c b/freebsd/lib/libc/nameser/ns_samedomain.c index 6bfe42d2..754e23b9 100644 --- a/freebsd/lib/libc/nameser/ns_samedomain.c +++ b/freebsd/lib/libc/nameser/ns_samedomain.c @@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$"); * Check whether a name belongs to a domain. * * Inputs: - *\li a - the domain whose ancestory is being verified + *\li a - the domain whose ancestry is being verified *\li b - the potential ancestor we're checking against * * Return: diff --git a/freebsd/lib/libc/net/base64.c b/freebsd/lib/libc/net/base64.c index 227dc68e..86366ec2 100644 --- a/freebsd/lib/libc/net/base64.c +++ b/freebsd/lib/libc/net/base64.c @@ -45,7 +45,6 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> @@ -195,12 +194,10 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { */ int -b64_pton(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; +b64_pton(const char *src, u_char *target, size_t targsize) { int tarindex, state, ch; + u_char nextbyte; char *pos; state = 0; @@ -214,7 +211,7 @@ b64_pton(src, target, targsize) break; pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ + if (pos == NULL) /* A non-base64 character. */ return (-1); switch (state) { @@ -228,22 +225,28 @@ b64_pton(src, target, targsize) break; case 1: if (target) { - if ((size_t)tarindex + 1 >= targsize) + if ((size_t)tarindex >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; + nextbyte = ((pos - Base64) & 0x0f) << 4; + if ((size_t)tarindex + 1 < targsize) + target[tarindex + 1] = nextbyte; + else if (nextbyte) + return (-1); } tarindex++; state = 2; break; case 2: if (target) { - if ((size_t)tarindex + 1 >= targsize) + if ((size_t)tarindex >= targsize) return (-1); target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; + nextbyte = ((pos - Base64) & 0x03) << 6; + if ((size_t)tarindex + 1 < targsize) + target[tarindex + 1] = nextbyte; + else if (nextbyte) + return (-1); } tarindex++; state = 3; @@ -301,7 +304,8 @@ b64_pton(src, target, targsize) * zeros. If we don't check them, they become a * subliminal channel. */ - if (target && target[tarindex] != 0) + if (target && (size_t)tarindex < targsize && + target[tarindex] != 0) return (-1); } } else { diff --git a/freebsd/lib/libc/net/ether_addr.c b/freebsd/lib/libc/net/ether_addr.c index d5a35de2..ad2449c6 100644 --- a/freebsd/lib/libc/net/ether_addr.c +++ b/freebsd/lib/libc/net/ether_addr.c @@ -42,7 +42,6 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> @@ -74,11 +73,13 @@ ether_line(const char *l, struct ether_addr *e, char *hostname) i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2], &o[3], &o[4], &o[5], hostname); - if (i != 7) - return (i); - for (i=0; i<6; i++) - e->octet[i] = o[i]; - return (0); + if (i == 7) { + for (i = 0; i < 6; i++) + e->octet[i] = o[i]; + return (0); + } else { + return (-1); + } } /* @@ -150,7 +151,7 @@ ether_ntohost(char *hostname, const struct ether_addr *e) char *yp_domain; #endif - if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) + if ((fp = fopen(_PATH_ETHERS, "re")) == NULL) return (1); while (fgets(buf,BUFSIZ,fp)) { if (buf[0] == '#') @@ -199,7 +200,7 @@ ether_hostton(const char *hostname, struct ether_addr *e) char *yp_domain; #endif - if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) + if ((fp = fopen(_PATH_ETHERS, "re")) == NULL) return (1); while (fgets(buf,BUFSIZ,fp)) { if (buf[0] == '#') diff --git a/freebsd/lib/libc/net/getaddrinfo.c b/freebsd/lib/libc/net/getaddrinfo.c index 65e905c3..0fe1b5d8 100644 --- a/freebsd/lib/libc/net/getaddrinfo.c +++ b/freebsd/lib/libc/net/getaddrinfo.c @@ -32,8 +32,6 @@ */ /* - * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator. - * * Issues to be discussed: * - Return values. There are nonstandard return values defined and used * in the source code. This is because RFC2553 is silent about which error @@ -59,7 +57,6 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> #include <net/if.h> @@ -68,7 +65,6 @@ __FBSDID("$FreeBSD$"); #include <ifaddrs.h> #include <sys/queue.h> #ifdef INET6 -#include <net/if_var.h> #include <sys/sysctl.h> #include <sys/ioctl.h> #include <netinet6/in6_var.h> @@ -98,15 +94,12 @@ __FBSDID("$FreeBSD$"); #include <stdarg.h> #include <nsswitch.h> #include "un-namespace.h" +#include "netdb_private.h" #include "libc_private.h" #ifdef NS_CACHING #include "nscache.h" #endif -#if defined(__KAME__) && defined(INET6) -# define FAITH -#endif - #define ANY 0 #define YES 1 #define NO 0 @@ -146,13 +139,20 @@ static const struct afd { offsetof(struct sockaddr_in6, sin6_addr), in6_addrany, in6_loopback, 1}, #define N_INET 1 +#define N_LOCAL 2 #else #define N_INET 0 +#define N_LOCAL 1 #endif {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), offsetof(struct sockaddr_in, sin_addr), in_addrany, in_loopback, 0}, +#define sizeofmember(type, member) (sizeof(((type *)0)->member)) + {PF_LOCAL, sizeofmember(struct sockaddr_un, sun_path), + sizeof(struct sockaddr_un), + offsetof(struct sockaddr_un, sun_path), + NULL, NULL, 0}, {0, 0, 0, 0, NULL, NULL, 0}, }; @@ -160,30 +160,49 @@ struct explore { int e_af; int e_socktype; int e_protocol; - const char *e_protostr; int e_wild; -#define WILD_AF(ex) ((ex)->e_wild & 0x01) -#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) -#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) +#define AF_ANY 0x01 +#define SOCKTYPE_ANY 0x02 +#define PROTOCOL_ANY 0x04 +#define WILD_AF(ex) ((ex)->e_wild & AF_ANY) +#define WILD_SOCKTYPE(ex) ((ex)->e_wild & SOCKTYPE_ANY) +#define WILD_PROTOCOL(ex) ((ex)->e_wild & PROTOCOL_ANY) }; static const struct explore explore[] = { -#if 0 - { PF_LOCAL, ANY, ANY, NULL, 0x01 }, -#endif #ifdef INET6 - { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET6, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 }, - { PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 }, - { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, + { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET6, SOCK_STREAM, IPPROTO_TCP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET6, SOCK_STREAM, IPPROTO_SCTP, + AF_ANY | SOCKTYPE_ANY }, + { PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET6, SOCK_DGRAM, IPPROTO_UDPLITE, + AF_ANY | SOCKTYPE_ANY }, + { PF_INET6, SOCK_RAW, ANY, + AF_ANY | PROTOCOL_ANY }, #endif - { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 }, - { PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 }, - { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, - { -1, 0, 0, NULL, 0 }, + { PF_INET, SOCK_DGRAM, IPPROTO_UDP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET, SOCK_STREAM, IPPROTO_TCP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET, SOCK_STREAM, IPPROTO_SCTP, + AF_ANY | SOCKTYPE_ANY }, + { PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_INET, SOCK_DGRAM, IPPROTO_UDPLITE, + AF_ANY | SOCKTYPE_ANY }, + { PF_INET, SOCK_RAW, ANY, + AF_ANY | PROTOCOL_ANY }, + { PF_LOCAL, SOCK_DGRAM, ANY, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_LOCAL, SOCK_STREAM, ANY, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { PF_LOCAL, SOCK_SEQPACKET, ANY, + AF_ANY | SOCKTYPE_ANY | PROTOCOL_ANY }, + { -1, 0, 0, 0 }, }; #ifdef INET6 @@ -380,7 +399,7 @@ getaddrinfo(const char *hostname, const char *servname, struct addrinfo *pai; const struct afd *afd; const struct explore *ex; - struct addrinfo *afailist[sizeof(afdl)/sizeof(afdl[0])]; + struct addrinfo *afailist[nitems(afdl)]; struct addrinfo *afai_unspec; int found; int numeric = 0; @@ -416,6 +435,7 @@ getaddrinfo(const char *hostname, const char *servname, ERR(EAI_BADFLAGS); switch (hints->ai_family) { case PF_UNSPEC: + case PF_LOCAL: case PF_INET: #ifdef INET6 case PF_INET6: @@ -452,6 +472,24 @@ getaddrinfo(const char *hostname, const char *servname, } /* + * RFC 3493: AI_ALL and AI_V4MAPPED are effective only against + * AF_INET6 query. They need to be ignored if specified in other + * occasions. + */ + switch (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) { + case AI_V4MAPPED: + case AI_ALL | AI_V4MAPPED: +#ifdef INET6 + if (pai->ai_family != AF_INET6) + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); + break; +#endif + case AI_ALL: + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); + break; + } + + /* * check for special cases. (1) numeric servname is disallowed if * socktype/protocol are left unspecified. (2) servname is disallowed * for raw and other inet{,6} sockets. @@ -699,13 +737,13 @@ get_addrselectpolicy(struct policyhead *head) char *buf; struct in6_addrpolicy *pol, *ep; - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) + if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) return (0); if (l == 0) return (0); if ((buf = malloc(l)) == NULL) return (0); - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) { free(buf); return (0); } @@ -760,10 +798,9 @@ match_addrselectpolicy(struct sockaddr *addr, struct policyhead *head) memset(&key, 0, sizeof(key)); key.sin6_family = AF_INET6; key.sin6_len = sizeof(key); - key.sin6_addr.s6_addr[10] = 0xff; - key.sin6_addr.s6_addr[11] = 0xff; - memcpy(&key.sin6_addr.s6_addr[12], - &((struct sockaddr_in *)addr)->sin_addr, 4); + _map_v4v6_address( + (char *)&((struct sockaddr_in *)addr)->sin_addr, + (char *)&key.sin6_addr); break; default: return(NULL); @@ -840,8 +877,19 @@ set_source(struct ai_order *aio, struct policyhead *ph) get_port(&ai, "1", 0); /* open a socket to get the source address for the given dst */ - if ((s = _socket(ai.ai_family, ai.ai_socktype, ai.ai_protocol)) < 0) + if ((s = _socket(ai.ai_family, ai.ai_socktype | SOCK_CLOEXEC, + ai.ai_protocol)) < 0) return; /* give up */ +#ifdef INET6 + if (ai.ai_family == AF_INET6) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai.ai_addr; + int off = 0; + + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) + (void)_setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, + (char *)&off, sizeof(off)); + } +#endif if (_connect(s, ai.ai_addr, ai.ai_addrlen) < 0) goto cleanup; srclen = ai.ai_addrlen; @@ -1137,11 +1185,14 @@ explore_null(const struct addrinfo *pai, const char *servname, *res = NULL; ai = NULL; + if (pai->ai_family == PF_LOCAL) + return (0); + /* * filter out AFs that are not supported by the kernel * XXX errno? */ - s = _socket(pai->ai_family, SOCK_DGRAM, 0); + s = _socket(pai->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (s < 0) { if (errno != EMFILE) return 0; @@ -1177,10 +1228,13 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, const char *servname, struct addrinfo **res, const char *canonname) { const struct afd *afd; - struct addrinfo *ai; + struct addrinfo *ai, ai0; int error; - char pton[PTON_MAX]; + char pton[PTON_MAX], path[PATH_MAX], *p; +#ifdef CTASSERT + CTASSERT(sizeofmember(struct sockaddr_un, sun_path) <= PATH_MAX); +#endif *res = NULL; ai = NULL; @@ -1189,6 +1243,15 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, return 0; switch (afd->a_af) { + case AF_LOCAL: + if (hostname[0] != '/') + ERR(EAI_NONAME); + if (strlen(hostname) > afd->a_addrlen) + ERR(EAI_MEMORY); + /* NUL-termination does not need to be guaranteed. */ + strncpy(path, hostname, afd->a_addrlen); + p = &path[0]; + break; case AF_INET: /* * RFC3493 requires getaddrinfo() to accept AF_INET formats @@ -1199,17 +1262,30 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, */ if (inet_aton(hostname, (struct in_addr *)pton) != 1) return 0; + p = pton; break; default: - if (inet_pton(afd->a_af, hostname, pton) != 1) - return 0; + if (inet_pton(afd->a_af, hostname, pton) != 1) { + if (pai->ai_family != AF_INET6 || + (pai->ai_flags & AI_V4MAPPED) != AI_V4MAPPED) + return 0; + if (inet_aton(hostname, (struct in_addr *)pton) != 1) + return 0; + afd = &afdl[N_INET]; + ai0 = *pai; + ai0.ai_family = AF_INET; + pai = &ai0; + } + p = pton; break; } if (pai->ai_family == afd->a_af) { - GET_AI(ai, afd, pton); + GET_AI(ai, afd, p); GET_PORT(ai, servname); - if ((pai->ai_flags & AI_CANONNAME)) { + if ((pai->ai_family == AF_INET || + pai->ai_family == AF_INET6) && + (pai->ai_flags & AI_CANONNAME)) { /* * Set the numeric address itself as the canonical * name, based on a clarification in RFC3493. @@ -1316,45 +1392,13 @@ get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr) { char *p; struct addrinfo *ai; -#ifdef FAITH - struct in6_addr faith_prefix; - char *fp_str; - int translate = 0; -#endif +#ifdef INET6 + struct in6_addr mapaddr; -#ifdef FAITH - /* - * Transfrom an IPv4 addr into a special IPv6 addr format for - * IPv6->IPv4 translation gateway. (only TCP is supported now) - * - * +-----------------------------------+------------+ - * | faith prefix part (12 bytes) | embedded | - * | | IPv4 addr part (4 bytes) - * +-----------------------------------+------------+ - * - * faith prefix part is specified as ascii IPv6 addr format - * in environmental variable GAI. - * For FAITH to work correctly, routing to faith prefix must be - * setup toward a machine where a FAITH daemon operates. - * Also, the machine must enable some mechanizm - * (e.g. faith interface hack) to divert those packet with - * faith prefixed destination addr to user-land FAITH daemon. - */ - fp_str = getenv("GAI"); - if (fp_str && inet_pton(AF_INET6, fp_str, &faith_prefix) == 1 && - afd->a_af == AF_INET && pai->ai_socktype == SOCK_STREAM) { - u_int32_t v4a; - u_int8_t v4a_top; - - memcpy(&v4a, addr, sizeof v4a); - v4a_top = v4a >> IN_CLASSA_NSHIFT; - if (!IN_MULTICAST(v4a) && !IN_EXPERIMENTAL(v4a) && - v4a_top != 0 && v4a != IN_LOOPBACKNET) { - afd = &afdl[N_INET6]; - memcpy(&faith_prefix.s6_addr[12], addr, - sizeof(struct in_addr)); - translate = 1; - } + if (afd->a_af == AF_INET && (pai->ai_flags & AI_V4MAPPED) != 0) { + afd = &afdl[N_INET6]; + _map_v4v6_address(addr, (char *)&mapaddr); + addr = (char *)&mapaddr; } #endif @@ -1368,13 +1412,14 @@ get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr) memset(ai->ai_addr, 0, (size_t)afd->a_socklen); ai->ai_addr->sa_len = afd->a_socklen; ai->ai_addrlen = afd->a_socklen; + if (ai->ai_family == PF_LOCAL) { + size_t n = strnlen(addr, afd->a_addrlen); + + ai->ai_addrlen -= afd->a_addrlen - n; + ai->ai_addr->sa_len -= afd->a_addrlen - n; + } ai->ai_addr->sa_family = ai->ai_family = afd->a_af; p = (char *)(void *)(ai->ai_addr); -#ifdef FAITH - if (translate == 1) - memcpy(p + afd->a_off, &faith_prefix, (size_t)afd->a_addrlen); - else -#endif memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen); return ai; } @@ -1431,6 +1476,9 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly) if (servname == NULL) return 0; switch (ai->ai_family) { + case AF_LOCAL: + /* AF_LOCAL ignores servname silently. */ + return (0); case AF_INET: #ifdef AF_INET6 case AF_INET6: @@ -1486,6 +1534,9 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly) case IPPROTO_SCTP: proto = "sctp"; break; + case IPPROTO_UDPLITE: + proto = "udplite"; + break; default: proto = NULL; break; @@ -1559,7 +1610,7 @@ addrconfig(struct addrinfo *pai) if (seen_inet) continue; sin = (struct sockaddr_in *)(ifa->ifa_addr); - if (IN_LOOPBACK(htonl(sin->sin_addr.s_addr))) + if (htonl(sin->sin_addr.s_addr) == INADDR_LOOPBACK) continue; seen_inet = 1; break; @@ -1603,7 +1654,7 @@ is_ifdisabled(char *name) struct in6_ndireq nd; int fd; - if ((fd = _socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + if ((fd = _socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) return (-1); memset(&nd, 0, sizeof(nd)); strlcpy(nd.ifname, name, sizeof(nd.ifname)); @@ -2114,7 +2165,11 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, return sentinel.ai_next; } - RES_SET_H_ERRNO(res, NO_RECOVERY); + /* + * We could have walked a CNAME chain, but the ultimate target + * may not have what we looked for. + */ + RES_SET_H_ERRNO(res, ntohs(hp->ancount) > 0 ? NO_DATA : NO_RECOVERY); return NULL; } @@ -2188,7 +2243,7 @@ addr4sort(struct addrinfo *sentinel, res_state res) static int _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) { - struct addrinfo *ai; + struct addrinfo *ai, ai0; querybuf *buf, *buf2; const char *hostname; const struct addrinfo *pai; @@ -2196,6 +2251,8 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) struct res_target q, q2; res_state res; + ai = NULL; + hostname = va_arg(ap, char *); pai = va_arg(ap, const struct addrinfo *); @@ -2204,6 +2261,8 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) memset(&sentinel, 0, sizeof(sentinel)); cur = &sentinel; + res = __res_state(); + buf = malloc(sizeof(*buf)); if (!buf) { RES_SET_H_ERRNO(res, NETDB_INTERNAL); @@ -2216,6 +2275,13 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) return NS_NOTFOUND; } + if (pai->ai_family == AF_INET6 && + (pai->ai_flags & AI_V4MAPPED) == AI_V4MAPPED) { + ai0 = *pai; + ai0.ai_family = AF_UNSPEC; + pai = &ai0; + } + switch (pai->ai_family) { case AF_UNSPEC: q.name = hostname; @@ -2250,7 +2316,6 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) return NS_UNAVAIL; } - res = __res_state(); if ((res->options & RES_INIT) == 0 && res_ninit(res) == -1) { RES_SET_H_ERRNO(res, NETDB_INTERNAL); free(buf); @@ -2266,20 +2331,24 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) /* prefer IPv6 */ if (q.next) { ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai, res); - if (ai) { + if (ai != NULL) { cur->ai_next = ai; while (cur && cur->ai_next) cur = cur->ai_next; } } - ai = getanswer(buf, q.n, q.name, q.qtype, pai, res); - if (ai) - cur->ai_next = ai; + if (ai == NULL || pai->ai_family != AF_UNSPEC || + (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) != AI_V4MAPPED) { + ai = getanswer(buf, q.n, q.name, q.qtype, pai, res); + if (ai != NULL) + cur->ai_next = ai; + } free(buf); free(buf2); if (sentinel.ai_next == NULL) switch (res->res_h_errno) { case HOST_NOT_FOUND: + case NO_DATA: return NS_NOTFOUND; case TRY_AGAIN: return NS_TRYAGAIN; @@ -2294,7 +2363,7 @@ static void _sethtent(FILE **hostf) { if (!*hostf) - *hostf = fopen(_PATH_HOSTS, "r"); + *hostf = fopen(_PATH_HOSTS, "re"); else rewind(*hostf); } @@ -2318,7 +2387,7 @@ _gethtent(FILE **hostf, const char *name, const struct addrinfo *pai) const char *addr; char hostbuf[8*1024]; - if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r"))) + if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "re"))) return (NULL); again: if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf))) @@ -2356,6 +2425,9 @@ found: hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = 0; hints.ai_flags = AI_NUMERICHOST; + if (pai->ai_family == AF_INET6 && + (pai->ai_flags & AI_V4MAPPED) == AI_V4MAPPED) + hints.ai_flags |= AI_V4MAPPED; error = getaddrinfo(addr, "0", &hints, &res0); if (error) goto again; @@ -2383,6 +2455,20 @@ found: return res0; } +static struct addrinfo * +_getht(FILE **hostf, const char *name, const struct addrinfo *pai, + struct addrinfo *cur) +{ + struct addrinfo *p; + + while ((p = _gethtent(hostf, name, pai)) != NULL) { + cur->ai_next = p; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + return (cur); +} + /*ARGSUSED*/ static int _files_getaddrinfo(void *rv, void *cb_data, va_list ap) @@ -2390,7 +2476,6 @@ _files_getaddrinfo(void *rv, void *cb_data, va_list ap) const char *name; const struct addrinfo *pai; struct addrinfo sentinel, *cur; - struct addrinfo *p; FILE *hostf = NULL; name = va_arg(ap, char *); @@ -2400,11 +2485,19 @@ _files_getaddrinfo(void *rv, void *cb_data, va_list ap) cur = &sentinel; _sethtent(&hostf); - while ((p = _gethtent(&hostf, name, pai)) != NULL) { - cur->ai_next = p; - while (cur && cur->ai_next) - cur = cur->ai_next; - } + if (pai->ai_family == AF_INET6 && + (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) == AI_V4MAPPED) { + struct addrinfo ai0 = *pai; + + ai0.ai_flags &= ~AI_V4MAPPED; + cur = _getht(&hostf, name, &ai0, cur); + if (sentinel.ai_next == NULL) { + _sethtent(&hostf); + ai0.ai_flags |= AI_V4MAPPED; + cur = _getht(&hostf, name, &ai0, cur); + } + } else + cur = _getht(&hostf, name, pai, cur); _endhtent(&hostf); *((struct addrinfo **)rv) = sentinel.ai_next; @@ -2464,6 +2557,9 @@ nextline: hints = *pai; hints.ai_flags = AI_NUMERICHOST; + if (pai->ai_family == AF_INET6 && + (pai->ai_flags & AI_V4MAPPED) == AI_V4MAPPED) + hints.ai_flags |= AI_V4MAPPED; error = getaddrinfo(addr, NULL, &hints, &res0); if (error == 0) { for (res = res0; res; res = res->ai_next) { @@ -2511,15 +2607,46 @@ _yp_getaddrinfo(void *rv, void *cb_data, va_list ap) memset(&sentinel, 0, sizeof(sentinel)); cur = &sentinel; + /* ipnodes.byname can hold both IPv4/v6 */ + r = yp_match(ypdomain, "ipnodes.byname", name, + (int)strlen(name), &ypbuf, &ypbuflen); + if (r == 0) { + ai = _yphostent(ypbuf, pai); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + free(ypbuf); + } + + if (ai != NULL) { + struct sockaddr_in6 *sin6; + + switch (ai->ai_family) { + case AF_INET: + goto done; + case AF_INET6: + sin6 = (struct sockaddr_in6 *)ai->ai_addr; + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) + goto done; + break; + } + } + /* hosts.byname is only for IPv4 (Solaris8) */ - if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) { + if (pai->ai_family == AF_UNSPEC || pai->ai_family == AF_INET || + ((pai->ai_family == AF_INET6 && + (pai->ai_flags & AI_V4MAPPED) == AI_V4MAPPED) && + (ai == NULL || (pai->ai_flags & AI_ALL) == AI_ALL))) { r = yp_match(ypdomain, "hosts.byname", name, (int)strlen(name), &ypbuf, &ypbuflen); if (r == 0) { struct addrinfo ai4; ai4 = *pai; - ai4.ai_family = AF_INET; + if (pai->ai_family == AF_UNSPEC) + ai4.ai_family = AF_INET; ai = _yphostent(ypbuf, &ai4); if (ai) { cur->ai_next = ai; @@ -2530,16 +2657,7 @@ _yp_getaddrinfo(void *rv, void *cb_data, va_list ap) } } - /* ipnodes.byname can hold both IPv4/v6 */ - r = yp_match(ypdomain, "ipnodes.byname", name, - (int)strlen(name), &ypbuf, &ypbuflen); - if (r == 0) { - ai = _yphostent(ypbuf, pai); - if (ai) - cur->ai_next = ai; - free(ypbuf); - } - +done: if (sentinel.ai_next == NULL) { RES_SET_H_ERRNO(__res_state(), HOST_NOT_FOUND); return NS_NOTFOUND; diff --git a/freebsd/lib/libc/net/gethostbydns.c b/freebsd/lib/libc/net/gethostbydns.c index 764ec311..bae4d166 100644 --- a/freebsd/lib/libc/net/gethostbydns.c +++ b/freebsd/lib/libc/net/gethostbydns.c @@ -58,7 +58,6 @@ static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vi #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> #include <netinet/in.h> @@ -90,7 +89,7 @@ static void addrsort(char **, int, res_state); #endif #ifdef DEBUG -static void dprintf(char *, int, res_state) __printflike(1, 0); +static void dbg_printf(char *, int, res_state) __printflike(1, 0); #endif #define MAXPACKET (64*1024) @@ -109,10 +108,7 @@ int _dns_ttl_; #ifdef DEBUG static void -dprintf(msg, num, res) - char *msg; - int num; - res_state res; +dbg_printf(char *msg, int num, res_state res) { if (res->options & RES_DEBUG) { int save = errno; @@ -122,7 +118,7 @@ dprintf(msg, num, res) } } #else -# define dprintf(msg, num, res) /*nada*/ +# define dbg_printf(msg, num, res) /*nada*/ #endif #define BOUNDED_INCR(x) \ @@ -375,13 +371,13 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, bp += sizeof(align) - ((u_long)bp % sizeof(align)); if (bp + n >= ep) { - dprintf("size (%d) too big\n", n, statp); + dbg_printf("size (%d) too big\n", n, statp); had_error++; continue; } if (hap >= &hed->h_addr_ptrs[_MAXADDRS-1]) { if (!toobig++) - dprintf("Too many addresses (%d)\n", + dbg_printf("Too many addresses (%d)\n", _MAXADDRS, statp); cp += n; continue; @@ -395,7 +391,7 @@ gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, } break; default: - dprintf("Impossible condition (type=%d)\n", type, + dbg_printf("Impossible condition (type=%d)\n", type, statp); RES_SET_H_ERRNO(statp, NO_RECOVERY); return (-1); @@ -522,12 +518,12 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) n = res_nsearch(statp, name, C_IN, type, buf->buf, sizeof(buf->buf)); if (n < 0) { free(buf); - dprintf("res_nsearch failed (%d)\n", n, statp); + dbg_printf("res_nsearch failed (%d)\n", n, statp); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } else if (n > sizeof(buf->buf)) { free(buf); - dprintf("static buffer is too small (%d)\n", n, statp); + dbg_printf("static buffer is too small (%d)\n", n, statp); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } @@ -629,13 +625,13 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) sizeof buf->buf); if (n < 0) { free(buf); - dprintf("res_nquery failed (%d)\n", n, statp); + dbg_printf("res_nquery failed (%d)\n", n, statp); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } if (n > sizeof buf->buf) { free(buf); - dprintf("static buffer is too small (%d)\n", n, statp); + dbg_printf("static buffer is too small (%d)\n", n, statp); *h_errnop = statp->res_h_errno; return (NS_UNAVAIL); } @@ -771,7 +767,7 @@ _sethostdnsent(int stayopen) } void -_endhostdnsent() +_endhostdnsent(void) { res_state statp; diff --git a/freebsd/lib/libc/net/gethostbyht.c b/freebsd/lib/libc/net/gethostbyht.c index f373fcbd..80a66922 100644 --- a/freebsd/lib/libc/net/gethostbyht.c +++ b/freebsd/lib/libc/net/gethostbyht.c @@ -74,7 +74,7 @@ void _sethosthtent(int f, struct hostent_data *hed) { if (!hed->hostf) - hed->hostf = fopen(_PATH_HOSTS, "r"); + hed->hostf = fopen(_PATH_HOSTS, "re"); else rewind(hed->hostf); hed->stayopen = f; @@ -98,7 +98,7 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped, int af, len; char hostbuf[BUFSIZ + 1]; - if (!hed->hostf && !(hed->hostf = fopen(_PATH_HOSTS, "r"))) { + if (!hed->hostf && !(hed->hostf = fopen(_PATH_HOSTS, "re"))) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } diff --git a/freebsd/lib/libc/net/gethostbynis.c b/freebsd/lib/libc/net/gethostbynis.c index 959caae4..19d3f92a 100644 --- a/freebsd/lib/libc/net/gethostbynis.c +++ b/freebsd/lib/libc/net/gethostbynis.c @@ -93,7 +93,7 @@ _gethostbynis(const char *name, char *map, int af, struct hostent *he, free(result); result = (char *)&ypbuf; - if ((cp = index(result, '\n'))) + if ((cp = strchr(result, '\n'))) *cp = '\0'; cp = strpbrk(result, " \t"); @@ -200,61 +200,6 @@ _gethostbynisaddr_r(const void *addr, socklen_t len, int af, } #endif /* YP */ -/* XXX _gethostbynisname/_gethostbynisaddr only used by getipnodeby*() */ -struct hostent * -_gethostbynisname(const char *name, int af) -{ -#ifdef YP - struct hostent *he; - struct hostent_data *hed; - u_long oresopt; - int error; - res_state statp; - - statp = __res_state(); - if ((he = __hostent_init()) == NULL || - (hed = __hostent_data_init()) == NULL) { - RES_SET_H_ERRNO(statp, NETDB_INTERNAL); - return (NULL); - } - - oresopt = statp->options; - statp->options &= ~RES_USE_INET6; - error = _gethostbynisname_r(name, af, he, hed); - statp->options = oresopt; - return (error == 0) ? he : NULL; -#else - return (NULL); -#endif -} - -struct hostent * -_gethostbynisaddr(const void *addr, socklen_t len, int af) -{ -#ifdef YP - struct hostent *he; - struct hostent_data *hed; - u_long oresopt; - int error; - res_state statp; - - statp = __res_state(); - if ((he = __hostent_init()) == NULL || - (hed = __hostent_data_init()) == NULL) { - RES_SET_H_ERRNO(statp, NETDB_INTERNAL); - return (NULL); - } - - oresopt = statp->options; - statp->options &= ~RES_USE_INET6; - error = _gethostbynisaddr_r(addr, len, af, he, hed); - statp->options = oresopt; - return (error == 0) ? he : NULL; -#else - return (NULL); -#endif -} - int _nis_gethostbyname(void *rval, void *cb_data, va_list ap) { diff --git a/freebsd/lib/libc/net/gethostnamadr.c b/freebsd/lib/libc/net/gethostnamadr.c index 7960be7c..e5d41ac0 100644 --- a/freebsd/lib/libc/net/gethostnamadr.c +++ b/freebsd/lib/libc/net/gethostnamadr.c @@ -50,17 +50,10 @@ __FBSDID("$FreeBSD$"); #include "nscache.h" #endif -extern int _ht_gethostbyname(void *, void *, va_list); -extern int _dns_gethostbyname(void *, void *, va_list); -extern int _nis_gethostbyname(void *, void *, va_list); -extern int _ht_gethostbyaddr(void *, void *, va_list); -extern int _dns_gethostbyaddr(void *, void *, va_list); -extern int _nis_gethostbyaddr(void *, void *, va_list); - static int gethostbyname_internal(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *, res_state); -/* Host lookup order if nsswitch.conf is broken or nonexistant */ +/* Host lookup order if nsswitch.conf is broken or nonexistent */ static const ns_src default_src[] = { { NSSRC_FILES, NS_SUCCESS }, { NSSRC_DNS, NS_SUCCESS }, diff --git a/freebsd/lib/libc/net/getifaddrs.c b/freebsd/lib/libc/net/getifaddrs.c index 17ef0198..ee5ecd76 100644 --- a/freebsd/lib/libc/net/getifaddrs.c +++ b/freebsd/lib/libc/net/getifaddrs.c @@ -74,19 +74,6 @@ __FBSDID("$FreeBSD$"); #define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES) #endif -#if _BSDI_VERSION >= 199701 -#define HAVE_IFM_DATA -#endif - -#if _BSDI_VERSION >= 199802 -/* ifam_data is very specific to recent versions of bsdi */ -#define HAVE_IFAM_DATA -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) -#define HAVE_IFM_DATA -#endif - #define MAX_SYSCTL_TRY 5 int @@ -95,39 +82,31 @@ getifaddrs(struct ifaddrs **pif) int icnt = 1; int dcnt = 0; int ncnt = 0; -#ifdef NET_RT_IFLIST int ntry = 0; int mib[6]; size_t needed; char *buf; char *next; - struct ifaddrs *cif = 0; + struct ifaddrs *cif; char *p, *p0; struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; + struct if_msghdrl *ifm; + struct ifa_msghdrl *ifam; struct sockaddr_dl *dl; struct sockaddr *sa; struct ifaddrs *ifa, *ift; + struct if_data *if_data; u_short idx = 0; -#else /* NET_RT_IFLIST */ - char buf[1024]; - int m, sock; - struct ifconf ifc; - struct ifreq *ifr; - struct ifreq *lifr; -#endif /* NET_RT_IFLIST */ int i; size_t len, alen; char *data; char *names; -#ifdef NET_RT_IFLIST mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; /* protocol */ mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; + mib[4] = NET_RT_IFLISTL;/* extra fields for extensible msghdr structs */ mib[5] = 0; /* no flags */ do { /* @@ -161,34 +140,33 @@ getifaddrs(struct ifaddrs **pif) continue; switch (rtm->rtm_type) { case RTM_IFINFO: - ifm = (struct if_msghdr *)(void *)rtm; + ifm = (struct if_msghdrl *)(void *)rtm; if (ifm->ifm_addrs & RTA_IFP) { idx = ifm->ifm_index; ++icnt; - dl = (struct sockaddr_dl *)(void *)(ifm + 1); + if_data = IF_MSGHDRL_IFM_DATA(ifm); + dcnt += if_data->ifi_datalen; + dl = (struct sockaddr_dl *)IF_MSGHDRL_RTA(ifm); dcnt += SA_RLEN((struct sockaddr *)(void*)dl) + ALIGNBYTES; -#ifdef HAVE_IFM_DATA - dcnt += sizeof(ifm->ifm_data); -#endif /* HAVE_IFM_DATA */ ncnt += dl->sdl_nlen + 1; } else idx = 0; break; case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)(void *)rtm; + ifam = (struct ifa_msghdrl *)(void *)rtm; if (idx && ifam->ifam_index != idx) abort(); /* this cannot happen */ #define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) break; - p = (char *)(void *)(ifam + 1); + p = (char *)IFA_MSGHDRL_RTA(ifam); ++icnt; -#ifdef HAVE_IFAM_DATA - dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES; -#endif /* HAVE_IFAM_DATA */ + if_data = IFA_MSGHDRL_IFAM_DATA(ifam); + dcnt += if_data->ifi_datalen + ALIGNBYTES; + /* Scan to look for length of address */ alen = 0; for (p0 = p, i = 0; i < RTAX_MAX; i++) { @@ -218,34 +196,6 @@ getifaddrs(struct ifaddrs **pif) break; } } -#else /* NET_RT_IFLIST */ - ifc.ifc_buf = buf; - ifc.ifc_len = sizeof(buf); - - if ((sock = _socket(AF_INET, SOCK_STREAM, 0)) < 0) - return (-1); - i = _ioctl(sock, SIOCGIFCONF, (char *)&ifc); - _close(sock); - if (i < 0) - return (-1); - - ifr = ifc.ifc_req; - lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; - - while (ifr < lifr) { - struct sockaddr *sa; - - sa = &ifr->ifr_addr; - ++icnt; - dcnt += SA_RLEN(sa); - ncnt += sizeof(ifr->ifr_name) + 1; - - if (SA_LEN(sa) < sizeof(*sa)) - ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa)); - else - ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa)); - } -#endif /* NET_RT_IFLIST */ if (icnt + dcnt + ncnt == 1) { *pif = NULL; @@ -265,49 +215,46 @@ getifaddrs(struct ifaddrs **pif) memset(ifa, 0, sizeof(struct ifaddrs) * icnt); ift = ifa; -#ifdef NET_RT_IFLIST idx = 0; + cif = NULL; for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)(void *)next; if (rtm->rtm_version != RTM_VERSION) continue; switch (rtm->rtm_type) { case RTM_IFINFO: - ifm = (struct if_msghdr *)(void *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - idx = ifm->ifm_index; - dl = (struct sockaddr_dl *)(void *)(ifm + 1); - - cif = ift; - ift->ifa_name = names; - ift->ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, - (size_t)dl->sdl_nlen); - names[dl->sdl_nlen] = 0; - names += dl->sdl_nlen + 1; - - ift->ifa_addr = (struct sockaddr *)(void *)data; - memcpy(data, dl, - (size_t)SA_LEN((struct sockaddr *) - (void *)dl)); - data += SA_RLEN((struct sockaddr *)(void *)dl); - -#ifdef HAVE_IFM_DATA - /* ifm_data needs to be aligned */ - ift->ifa_data = data = (void *)ALIGN(data); - memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data)); - data += sizeof(ifm->ifm_data); -#else /* HAVE_IFM_DATA */ - ift->ifa_data = NULL; -#endif /* HAVE_IFM_DATA */ - - ift = (ift->ifa_next = ift + 1); - } else + ifm = (struct if_msghdrl *)(void *)rtm; + if ((ifm->ifm_addrs & RTA_IFP) == 0) { idx = 0; + break; + } + + idx = ifm->ifm_index; + dl = (struct sockaddr_dl *)IF_MSGHDRL_RTA(ifm); + + cif = ift; + ift->ifa_name = names; + ift->ifa_flags = (int)ifm->ifm_flags; + memcpy(names, dl->sdl_data, (size_t)dl->sdl_nlen); + names[dl->sdl_nlen] = 0; + names += dl->sdl_nlen + 1; + + ift->ifa_addr = (struct sockaddr *)(void *)data; + memcpy(data, dl, (size_t)SA_LEN((struct sockaddr *) + (void *)dl)); + data += SA_RLEN((struct sockaddr *)(void *)dl); + + if_data = IF_MSGHDRL_IFM_DATA(ifm); + /* ifm_data needs to be aligned */ + ift->ifa_data = data = (void *)ALIGN(data); + memcpy(data, if_data, if_data->ifi_datalen); + data += if_data->ifi_datalen; + + ift = (ift->ifa_next = ift + 1); break; case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)(void *)rtm; + ifam = (struct ifa_msghdrl *)(void *)rtm; if (idx && ifam->ifam_index != idx) abort(); /* this cannot happen */ @@ -316,7 +263,8 @@ getifaddrs(struct ifaddrs **pif) ift->ifa_name = cif->ifa_name; ift->ifa_flags = cif->ifa_flags; ift->ifa_data = NULL; - p = (char *)(void *)(ifam + 1); + + p = (char *)IFA_MSGHDRL_RTA(ifam); /* Scan to look for length of address */ alen = 0; for (p0 = p, i = 0; i < RTAX_MAX; i++) { @@ -367,12 +315,11 @@ getifaddrs(struct ifaddrs **pif) p += len; } -#ifdef HAVE_IFAM_DATA + if_data = IFA_MSGHDRL_IFAM_DATA(ifam); /* ifam_data needs to be aligned */ ift->ifa_data = data = (void *)ALIGN(data); - memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data)); - data += sizeof(ifam->ifam_data); -#endif /* HAVE_IFAM_DATA */ + memcpy(data, if_data, if_data->ifi_datalen); + data += if_data->ifi_datalen; ift = (ift->ifa_next = ift + 1); break; @@ -380,28 +327,7 @@ getifaddrs(struct ifaddrs **pif) } free(buf); -#else /* NET_RT_IFLIST */ - ifr = ifc.ifc_req; - lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; - - while (ifr < lifr) { - struct sockaddr *sa; - - ift->ifa_name = names; - names[sizeof(ifr->ifr_name)] = 0; - strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name)); - while (*names++) - ; - - ift->ifa_addr = (struct sockaddr *)data; - sa = &ifr->ifr_addr; - memcpy(data, sa, SA_LEN(sa)); - data += SA_RLEN(sa); - - ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa)); - ift = (ift->ifa_next = ift + 1); - } -#endif /* NET_RT_IFLIST */ + if (--ift >= ifa) { ift->ifa_next = NULL; *pif = ifa; diff --git a/freebsd/lib/libc/net/getifmaddrs.c b/freebsd/lib/libc/net/getifmaddrs.c index 6d2bf84a..72d07733 100644 --- a/freebsd/lib/libc/net/getifmaddrs.c +++ b/freebsd/lib/libc/net/getifmaddrs.c @@ -12,24 +12,18 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Bruce M. Simpson. - * 4. Neither the name of Bruce M. Simpson nor the names of other - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY BRUCE M. SIMPSON AND AFFILIATES - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRUCE M. SIMPSON OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #include <sys/cdefs.h> diff --git a/freebsd/lib/libc/net/getnameinfo.c b/freebsd/lib/libc/net/getnameinfo.c index 3a489c48..e042c549 100644 --- a/freebsd/lib/libc/net/getnameinfo.c +++ b/freebsd/lib/libc/net/getnameinfo.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/socket.h> +#include <sys/un.h> #include <net/if.h> #include <net/if_dl.h> #include <net/if_types.h> @@ -64,92 +65,123 @@ __FBSDID("$FreeBSD$"); #include <stddef.h> #include <errno.h> -static int getnameinfo_inet(const struct sockaddr *, socklen_t, char *, +static const struct afd *find_afd(int); +static int getnameinfo_inet(const struct afd *, + const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int); #ifdef INET6 static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, size_t, int); static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); #endif -static int getnameinfo_link(const struct sockaddr *, socklen_t, char *, +static int getnameinfo_link(const struct afd *, + const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int); +static int hexname(const u_int8_t *, size_t, char *, size_t); +static int getnameinfo_un(const struct afd *, + const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int); -static int hexname(const u_int8_t *, size_t, char *, size_t); - -int -getnameinfo(const struct sockaddr *sa, socklen_t salen, - char *host, size_t hostlen, char *serv, size_t servlen, - int flags) -{ - - switch (sa->sa_family) { - case AF_INET: -#ifdef INET6 - case AF_INET6: -#endif - return getnameinfo_inet(sa, salen, host, hostlen, serv, - servlen, flags); - case AF_LINK: - return getnameinfo_link(sa, salen, host, hostlen, serv, - servlen, flags); - default: - return EAI_FAMILY; - } -} static const struct afd { int a_af; size_t a_addrlen; socklen_t a_socklen; int a_off; + int (*a_func)(const struct afd *, + const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int); } afdl [] = { #ifdef INET6 {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6), - offsetof(struct sockaddr_in6, sin6_addr)}, + offsetof(struct sockaddr_in6, sin6_addr), + getnameinfo_inet}, #endif {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), - offsetof(struct sockaddr_in, sin_addr)}, + offsetof(struct sockaddr_in, sin_addr), + getnameinfo_inet}, +#define sizeofmember(type, member) (sizeof(((type *)0)->member)) + {PF_LOCAL, sizeofmember(struct sockaddr_un, sun_path), + sizeof(struct sockaddr_un), + offsetof(struct sockaddr_un, sun_path), + getnameinfo_un}, + {PF_LINK, sizeofmember(struct sockaddr_dl, sdl_data), + sizeof(struct sockaddr_dl), + offsetof(struct sockaddr_dl, sdl_data), + getnameinfo_link}, {0, 0, 0}, }; -struct sockinet { - u_char si_len; - u_char si_family; - u_short si_port; -}; +int +getnameinfo(const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, + int flags) +{ + const struct afd *afd; + + if (sa == NULL) + return (EAI_FAIL); + + afd = find_afd(sa->sa_family); + if (afd == NULL) + return (EAI_FAMILY); + switch (sa->sa_family) { + case PF_LOCAL: + /* + * PF_LOCAL uses variable sa->sa_len depending on the + * content length of sun_path. Require 1 byte in + * sun_path at least. + */ + if (salen > afd->a_socklen || + salen <= afd->a_socklen - + sizeofmember(struct sockaddr_un, sun_path)) + return (EAI_FAIL); + break; + case PF_LINK: + if (salen <= afd->a_socklen - + sizeofmember(struct sockaddr_dl, sdl_data)) + return (EAI_FAIL); + break; + default: + if (salen != afd->a_socklen) + return (EAI_FAIL); + break; + } + + return ((*afd->a_func)(afd, sa, salen, host, hostlen, + serv, servlen, flags)); +} + +static const struct afd * +find_afd(int af) +{ + const struct afd *afd; + + if (af == PF_UNSPEC) + return (NULL); + for (afd = &afdl[0]; afd->a_af > 0; afd++) { + if (afd->a_af == af) + return (afd); + } + return (NULL); +} static int -getnameinfo_inet(const struct sockaddr *sa, socklen_t salen, +getnameinfo_inet(const struct afd *afd, + const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { - const struct afd *afd; struct servent *sp; struct hostent *hp; u_short port; - int family, i; const char *addr; u_int32_t v4a; int h_error; char numserv[512]; char numaddr[512]; - if (sa == NULL) - return EAI_FAIL; - - family = sa->sa_family; - for (i = 0; afdl[i].a_af; i++) - if (afdl[i].a_af == family) { - afd = &afdl[i]; - goto found; - } - return EAI_FAMILY; - - found: - if (salen != afd->a_socklen) - return EAI_FAIL; - /* network byte order */ - port = ((const struct sockinet *)sa)->si_port; + port = ((const struct sockaddr_in *)sa)->sin_port; addr = (const char *)sa + afd->a_off; if (serv == NULL || servlen == 0) { @@ -348,7 +380,6 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) ifindex = (unsigned int)sa6->sin6_scope_id; a6 = &sa6->sin6_addr; -#ifdef NI_NUMERICSCOPE if ((flags & NI_NUMERICSCOPE) != 0) { n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id); if (n < 0 || n >= bufsiz) @@ -356,7 +387,6 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) else return n; } -#endif /* if_indextoname() does not take buffer size. not a good api... */ if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || @@ -383,7 +413,8 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) */ /* ARGSUSED */ static int -getnameinfo_link(const struct sockaddr *sa, socklen_t salen, +getnameinfo_link(const struct afd *afd, + const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { const struct sockaddr_dl *sdl = @@ -396,11 +427,22 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { n = snprintf(host, hostlen, "link#%d", sdl->sdl_index); - if (n > hostlen) { + if (n >= hostlen) { *host = '\0'; - return EAI_MEMORY; + return (EAI_MEMORY); } - return 0; + return (0); + } + + if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) { + n = sdl->sdl_nlen; + if (n >= hostlen) { + *host = '\0'; + return (EAI_MEMORY); + } + memcpy(host, sdl->sdl_data, sdl->sdl_nlen); + host[n] = '\0'; + return (0); } switch (sdl->sdl_type) { @@ -416,7 +458,6 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, /* * The following have zero-length addresses. * IFT_ATM (net/if_atmsubr.c) - * IFT_FAITH (net/if_faith.c) * IFT_GIF (net/if_gif.c) * IFT_LOOP (net/if_loop.c) * IFT_PPP (net/if_ppp.c, net/if_spppsubr.c) @@ -443,10 +484,7 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, } static int -hexname(cp, len, host, hostlen) - const u_int8_t *cp; - char *host; - size_t len, hostlen; +hexname(const u_int8_t *cp, size_t len, char *host, size_t hostlen) { int i, n; char *outp = host; @@ -464,3 +502,30 @@ hexname(cp, len, host, hostlen) } return 0; } + +/* + * getnameinfo_un(): + * Format a UNIX IPC domain address (pathname). + */ +/* ARGSUSED */ +static int +getnameinfo_un(const struct afd *afd, + const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, int flags) +{ + size_t pathlen; + + if (serv != NULL && servlen > 0) + *serv = '\0'; + if (host != NULL && hostlen > 0) { + pathlen = sa->sa_len - afd->a_off; + + if (pathlen + 1 > hostlen) { + *host = '\0'; + return (EAI_MEMORY); + } + strlcpy(host, (const char *)sa + afd->a_off, pathlen + 1); + } + + return (0); +} diff --git a/freebsd/lib/libc/net/getnetbydns.c b/freebsd/lib/libc/net/getnetbydns.c index 7f2b08fb..1e0cc3d1 100644 --- a/freebsd/lib/libc/net/getnetbydns.c +++ b/freebsd/lib/libc/net/getnetbydns.c @@ -457,7 +457,7 @@ _setnetdnsent(int stayopen) } void -_endnetdnsent() +_endnetdnsent(void) { res_state statp; diff --git a/freebsd/lib/libc/net/getnetbyht.c b/freebsd/lib/libc/net/getnetbyht.c index caf9c3a6..ee80bab0 100644 --- a/freebsd/lib/libc/net/getnetbyht.c +++ b/freebsd/lib/libc/net/getnetbyht.c @@ -65,7 +65,7 @@ _setnethtent(int f, struct netent_data *ned) { if (ned->netf == NULL) - ned->netf = fopen(_PATH_NETWORKS, "r"); + ned->netf = fopen(_PATH_NETWORKS, "re"); else rewind(ned->netf); ned->stayopen |= f; @@ -91,7 +91,7 @@ getnetent_p(struct netent *ne, struct netent_data *ned) char line[BUFSIZ + 1]; if (ned->netf == NULL && - (ned->netf = fopen(_PATH_NETWORKS, "r")) == NULL) + (ned->netf = fopen(_PATH_NETWORKS, "re")) == NULL) return (-1); again: p = fgets(line, sizeof line, ned->netf); diff --git a/freebsd/lib/libc/net/getnetbynis.c b/freebsd/lib/libc/net/getnetbynis.c index dd9f506a..7b561abc 100644 --- a/freebsd/lib/libc/net/getnetbynis.c +++ b/freebsd/lib/libc/net/getnetbynis.c @@ -82,7 +82,7 @@ _getnetbynis(const char *name, char *map, int af, struct netent *ne, free(result); result = (char *)&ypbuf; - if ((cp = index(result, '\n'))) + if ((cp = strchr(result, '\n'))) *cp = '\0'; cp = strpbrk(result, " \t"); diff --git a/freebsd/lib/libc/net/getnetnamadr.c b/freebsd/lib/libc/net/getnetnamadr.c index 2974d152..79cd5f62 100644 --- a/freebsd/lib/libc/net/getnetnamadr.c +++ b/freebsd/lib/libc/net/getnetnamadr.c @@ -48,14 +48,7 @@ __FBSDID("$FreeBSD$"); #include "nscache.h" #endif -extern int _ht_getnetbyname(void *, void *, va_list); -extern int _dns_getnetbyname(void *, void *, va_list); -extern int _nis_getnetbyname(void *, void *, va_list); -extern int _ht_getnetbyaddr(void *, void *, va_list); -extern int _dns_getnetbyaddr(void *, void *, va_list); -extern int _nis_getnetbyaddr(void *, void *, va_list); - -/* Network lookup order if nsswitch.conf is broken or nonexistant */ +/* Network lookup order if nsswitch.conf is broken or nonexistent */ static const ns_src default_src[] = { { NSSRC_FILES, NS_SUCCESS }, { NSSRC_DNS, NS_SUCCESS }, diff --git a/freebsd/lib/libc/net/getproto.c b/freebsd/lib/libc/net/getproto.c index e0c30df0..5f9950ae 100644 --- a/freebsd/lib/libc/net/getproto.c +++ b/freebsd/lib/libc/net/getproto.c @@ -49,12 +49,6 @@ static const ns_src defaultsrc[] = { { NULL, 0 } }; -#ifdef NS_CACHING -extern int __proto_id_func(char *, size_t *, va_list, void *); -extern int __proto_marshal_func(char *, size_t *, void *, va_list, void *); -extern int __proto_unmarshal_func(char *, size_t, void *, va_list, void *); -#endif - static int files_getprotobynumber(void *retval, void *mdata, va_list ap) { diff --git a/freebsd/lib/libc/net/getprotoent.c b/freebsd/lib/libc/net/getprotoent.c index d0a7a97e..774ae95a 100644 --- a/freebsd/lib/libc/net/getprotoent.c +++ b/freebsd/lib/libc/net/getprotoent.c @@ -36,7 +36,6 @@ static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <errno.h> #include <limits.h> @@ -344,7 +343,7 @@ void __setprotoent_p(int f, struct protoent_data *ped) { if (ped->fp == NULL) - ped->fp = fopen(_PATH_PROTOCOLS, "r"); + ped->fp = fopen(_PATH_PROTOCOLS, "re"); else rewind(ped->fp); ped->stayopen |= f; @@ -367,7 +366,7 @@ __getprotoent_p(struct protoent *pe, struct protoent_data *ped) char *cp, **q, *endp; long l; - if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL) + if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "re")) == NULL) return (-1); again: if ((p = fgets(ped->line, sizeof ped->line, ped->fp)) == NULL) diff --git a/freebsd/lib/libc/net/getservent.c b/freebsd/lib/libc/net/getservent.c index aff91ed2..63aba518 100644 --- a/freebsd/lib/libc/net/getservent.c +++ b/freebsd/lib/libc/net/getservent.c @@ -36,7 +36,6 @@ static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <db.h> @@ -323,7 +322,7 @@ files_servent(void *retval, void *mdata, va_list ap) break; default: return NS_NOTFOUND; - }; + } serv = va_arg(ap, struct servent *); buffer = va_arg(ap, char *); @@ -337,7 +336,7 @@ files_servent(void *retval, void *mdata, va_list ap) if (st->fp == NULL) st->compat_mode_active = 0; - if (st->fp == NULL && (st->fp = fopen(_PATH_SERVICES, "r")) == NULL) { + if (st->fp == NULL && (st->fp = fopen(_PATH_SERVICES, "re")) == NULL) { *errnop = errno; return (NS_UNAVAIL); } @@ -408,14 +407,14 @@ files_servent(void *retval, void *mdata, va_list ap) continue; gotname: - if (proto == 0 || strcmp(serv->s_proto, proto) == 0) + if (proto == NULL || strcmp(serv->s_proto, proto) == 0) rv = NS_SUCCESS; break; case nss_lt_id: if (port != serv->s_port) continue; - if (proto == 0 || strcmp(serv->s_proto, proto) == 0) + if (proto == NULL || strcmp(serv->s_proto, proto) == 0) rv = NS_SUCCESS; break; case nss_lt_all: @@ -451,7 +450,7 @@ files_setservent(void *retval, void *mdata, va_list ap) case SETSERVENT: f = va_arg(ap,int); if (st->fp == NULL) - st->fp = fopen(_PATH_SERVICES, "r"); + st->fp = fopen(_PATH_SERVICES, "re"); else rewind(st->fp); st->stayopen |= f; @@ -465,7 +464,7 @@ files_setservent(void *retval, void *mdata, va_list ap) break; default: break; - }; + } st->compat_mode_active = 0; return (NS_UNAVAIL); @@ -524,7 +523,7 @@ db_servent(void *retval, void *mdata, va_list ap) break; default: return NS_NOTFOUND; - }; + } serv = va_arg(ap, struct servent *); buffer = va_arg(ap, char *); @@ -643,7 +642,7 @@ db_setservent(void *retval, void *mdata, va_list ap) break; default: break; - }; + } return (NS_UNAVAIL); } @@ -696,7 +695,7 @@ nis_servent(void *retval, void *mdata, va_list ap) break; default: return NS_NOTFOUND; - }; + } serv = va_arg(ap, struct servent *); buffer = va_arg(ap, char *); @@ -783,7 +782,7 @@ nis_servent(void *retval, void *mdata, va_list ap) } } break; - }; + } rv = parse_result(serv, buffer, bufsize, resultbuf, resultbuflen, errnop); @@ -817,7 +816,7 @@ nis_setservent(void *result, void *mdata, va_list ap) break; default: break; - }; + } return (NS_UNAVAIL); } @@ -1243,7 +1242,7 @@ setservent(int stayopen) } void -endservent() +endservent(void) { #ifdef NS_CACHING static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( @@ -1364,7 +1363,7 @@ getservbyport(int port, const char *proto) } struct servent * -getservent() +getservent(void) { struct key key; diff --git a/freebsd/lib/libc/net/if_indextoname.c b/freebsd/lib/libc/net/if_indextoname.c index b0f10f72..236ccbda 100644 --- a/freebsd/lib/libc/net/if_indextoname.c +++ b/freebsd/lib/libc/net/if_indextoname.c @@ -72,7 +72,7 @@ if_indextoname(unsigned int ifindex, char *ifname) for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_LINK && - ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index) + ifindex == LLINDEX((struct sockaddr_dl*)ifa->ifa_addr)) break; } diff --git a/freebsd/lib/libc/net/if_nameindex.c b/freebsd/lib/libc/net/if_nameindex.c index 7cb14a80..6d2573e8 100644 --- a/freebsd/lib/libc/net/if_nameindex.c +++ b/freebsd/lib/libc/net/if_nameindex.c @@ -125,7 +125,7 @@ if_nameindex(void) if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_LINK) { ifni2->if_index = - ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; + LLINDEX((struct sockaddr_dl*)ifa->ifa_addr); ifni2->if_name = cp; strcpy(cp, ifa->ifa_name); ifni2++; diff --git a/freebsd/lib/libc/net/if_nametoindex.c b/freebsd/lib/libc/net/if_nametoindex.c index eff590e7..92a2abed 100644 --- a/freebsd/lib/libc/net/if_nametoindex.c +++ b/freebsd/lib/libc/net/if_nametoindex.c @@ -70,8 +70,9 @@ if_nametoindex(const char *ifname) struct ifaddrs *ifaddrs, *ifa; unsigned int ni; - s = _socket(AF_INET, SOCK_DGRAM, 0); + s = _socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (s != -1) { + memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (_ioctl(s, SIOCGIFINDEX, &ifr) != -1) { _close(s); @@ -89,7 +90,7 @@ if_nametoindex(const char *ifname) if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_LINK && strcmp(ifa->ifa_name, ifname) == 0) { - ni = ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; + ni = LLINDEX((struct sockaddr_dl*)ifa->ifa_addr); break; } } diff --git a/freebsd/lib/libc/net/ip6opt.c b/freebsd/lib/libc/net/ip6opt.c index a09f05d8..2fbd6cc6 100644 --- a/freebsd/lib/libc/net/ip6opt.c +++ b/freebsd/lib/libc/net/ip6opt.c @@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -47,6 +46,18 @@ __FBSDID("$FreeBSD$"); static int ip6optlen(u_int8_t *opt, u_int8_t *lim); static void inet6_insert_padopt(u_char *p, int len); +#ifndef IPV6_2292HOPOPTS +#define IPV6_2292HOPOPTS 22 +#endif +#ifndef IPV6_2292DSTOPTS +#define IPV6_2292DSTOPTS 23 +#endif + +#define is_ipv6_hopopts(x) \ + ((x) == IPV6_HOPOPTS || (x) == IPV6_2292HOPOPTS) +#define is_ipv6_dstopts(x) \ + ((x) == IPV6_DSTOPTS || (x) == IPV6_2292DSTOPTS) + /* * This function returns the number of bytes required to hold an option * when it is stored as ancillary data, including the cmsghdr structure @@ -74,9 +85,9 @@ inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) struct cmsghdr *ch = (struct cmsghdr *)bp; /* argument validation */ - if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) + if (!is_ipv6_hopopts(type) && !is_ipv6_dstopts(type)) return(-1); - + ch->cmsg_level = IPPROTO_IPV6; ch->cmsg_type = type; ch->cmsg_len = CMSG_LEN(0); @@ -121,8 +132,7 @@ inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ @@ -191,8 +201,7 @@ inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ @@ -236,8 +245,8 @@ inet6_option_next(const struct cmsghdr *cmsg, u_int8_t **tptrp) u_int8_t *lim; if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) + (!is_ipv6_hopopts(cmsg->cmsg_type) && + !is_ipv6_dstopts(cmsg->cmsg_type))) return(-1); /* message length validation */ @@ -292,8 +301,8 @@ inet6_option_find(const struct cmsghdr *cmsg, u_int8_t **tptrp, int type) u_int8_t *optp, *lim; if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) + (!is_ipv6_hopopts(cmsg->cmsg_type) && + !is_ipv6_dstopts(cmsg->cmsg_type))) return(-1); /* message length validation */ @@ -383,11 +392,8 @@ inet6_opt_init(void *extbuf, socklen_t extlen) { struct ip6_ext *ext = (struct ip6_ext *)extbuf; - if (extlen < 0 || (extlen % 8)) - return(-1); - if (ext) { - if (extlen == 0) + if (extlen <= 0 || (extlen % 8)) return(-1); ext->ip6e_len = (extlen >> 3) - 1; } @@ -412,7 +418,7 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, * The option data length must have a value between 0 and 255, * inclusive, and is the length of the option data that follows. */ - if (len < 0 || len > 255) + if (len > 255 || len < 0 ) return(-1); /* diff --git a/freebsd/lib/libc/net/linkaddr.c b/freebsd/lib/libc/net/linkaddr.c index 10aff86c..1a2c3fd3 100644 --- a/freebsd/lib/libc/net/linkaddr.c +++ b/freebsd/lib/libc/net/linkaddr.c @@ -52,9 +52,7 @@ __FBSDID("$FreeBSD$"); #define LETTER (4*3) void -link_addr(addr, sdl) - const char *addr; - struct sockaddr_dl *sdl; +link_addr(const char *addr, struct sockaddr_dl *sdl) { char *cp = sdl->sdl_data; char *cplim = sdl->sdl_len + (char *)sdl; @@ -120,11 +118,10 @@ link_addr(addr, sdl) return; } -static char hexlist[] = "0123456789abcdef"; +static const char hexlist[] = "0123456789abcdef"; char * -link_ntoa(sdl) - const struct sockaddr_dl *sdl; +link_ntoa(const struct sockaddr_dl *sdl) { static char obuf[64]; char *out = obuf; diff --git a/freebsd/lib/libc/net/map_v4v6.c b/freebsd/lib/libc/net/map_v4v6.c index e2fc9747..2923fb48 100644 --- a/freebsd/lib/libc/net/map_v4v6.c +++ b/freebsd/lib/libc/net/map_v4v6.c @@ -57,7 +57,6 @@ static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> #include <netinet/in.h> @@ -70,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include <resolv.h> #include <ctype.h> #include <syslog.h> +#include "netdb_private.h" typedef union { int32_t al; @@ -79,19 +79,11 @@ typedef union { void _map_v4v6_address(const char *src, char *dst) { - u_char *p = (u_char *)dst; - char tmp[NS_INADDRSZ]; - int i; - - /* Stash a temporary copy so our caller can update in place. */ - memcpy(tmp, src, NS_INADDRSZ); + /* Our caller may update in place. */ + memmove(&dst[12], src, NS_INADDRSZ); /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Retrieve the saved copy and we're done. */ - memcpy((void*)p, tmp, NS_INADDRSZ); + memset(&dst[10], 0xff, 2); + memset(&dst[0], 0, 10); } void diff --git a/freebsd/lib/libc/net/name6.c b/freebsd/lib/libc/net/name6.c index 2a93efce..a106ad98 100644 --- a/freebsd/lib/libc/net/name6.c +++ b/freebsd/lib/libc/net/name6.c @@ -44,11 +44,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -100,7 +96,6 @@ __FBSDID("$FreeBSD$"); #include <netinet/in.h> #ifdef INET6 #include <net/if.h> -#include <net/if_var.h> #include <sys/sysctl.h> #include <sys/ioctl.h> #include <netinet6/in6_var.h> /* XXX */ @@ -241,13 +236,13 @@ getipnodebyname(const char *name, int af, int flags, int *errp) if (flags & AI_ADDRCONFIG) { int s; - if ((s = _socket(af, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(af, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) return NULL; /* * TODO: * Note that implementation dependent test for address - * configuration should be done everytime called - * (or apropriate interval), + * configuration should be done every time called + * (or appropriate interval), * because addresses will be dynamically assigned or deleted. */ _close(s); @@ -337,7 +332,7 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp) *errp = NO_RECOVERY; return NULL; } - if ((long)src & ~(sizeof(struct in_addr) - 1)) { + if (rounddown2((long)src, sizeof(struct in_addr))) { memcpy(&addrbuf, src, len); src = &addrbuf; } @@ -350,7 +345,8 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp) *errp = NO_RECOVERY; return NULL; } - if ((long)src & ~(sizeof(struct in6_addr) / 2 - 1)) { /*XXX*/ + if (rounddown2((long)src, sizeof(struct in6_addr) / 2)) { + /* XXX */ memcpy(&addrbuf, src, len); src = &addrbuf; } @@ -661,7 +657,6 @@ _hpreorder(struct hostent *hp) #endif break; default: - free_addrselectpolicy(&policyhead); return hp; } @@ -742,11 +737,11 @@ get_addrselectpolicy(struct policyhead *head) char *buf; struct in6_addrpolicy *pol, *ep; - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) + if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) return (0); if ((buf = malloc(l)) == NULL) return (0); - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) { free(buf); return (0); } @@ -801,10 +796,9 @@ match_addrselectpolicy(struct sockaddr *addr, struct policyhead *head) memset(&key, 0, sizeof(key)); key.sin6_family = AF_INET6; key.sin6_len = sizeof(key); - key.sin6_addr.s6_addr[10] = 0xff; - key.sin6_addr.s6_addr[11] = 0xff; - memcpy(&key.sin6_addr.s6_addr[12], - &((struct sockaddr_in *)addr)->sin_addr, 4); + _map_v4v6_address( + (char *)&((struct sockaddr_in *)addr)->sin_addr, + (char *)&key.sin6_addr); break; default: return(NULL); @@ -874,7 +868,8 @@ set_source(struct hp_order *aio, struct policyhead *ph) } /* open a socket to get the source address for the given dst */ - if ((s = _socket(ss.ss_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) + if ((s = _socket(ss.ss_family, SOCK_DGRAM | SOCK_CLOEXEC, + IPPROTO_UDP)) < 0) return; /* give up */ if (_connect(s, (struct sockaddr *)&ss, ss.ss_len) < 0) goto cleanup; diff --git a/freebsd/lib/libc/net/netdb_private.h b/freebsd/lib/libc/net/netdb_private.h index ed3465e9..51f28f07 100644 --- a/freebsd/lib/libc/net/netdb_private.h +++ b/freebsd/lib/libc/net/netdb_private.h @@ -130,8 +130,6 @@ void _endhostdnsent(void); void _endhosthtent(struct hostent_data *); void _endnetdnsent(void); void _endnethtent(struct netent_data *); -struct hostent *_gethostbynisaddr(const void *, socklen_t, int); -struct hostent *_gethostbynisname(const char *, int); void _map_v4v6_address(const char *, char *); void _map_v4v6_hostent(struct hostent *, char **, char *); void _sethostdnsent(int); @@ -139,7 +137,23 @@ void _sethosthtent(int, struct hostent_data *); void _setnetdnsent(int); void _setnethtent(int, struct netent_data *); -int _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, - const char *method_name, const ns_src defaults[], ...); +struct hostent *__dns_getanswer(const char *, int, const char *, int); +int _dns_gethostbyaddr(void *, void *, va_list); +int _dns_gethostbyname(void *, void *, va_list); +int _dns_getnetbyaddr(void *, void *, va_list); +int _dns_getnetbyname(void *, void *, va_list); +int _ht_gethostbyaddr(void *, void *, va_list); +int _ht_gethostbyname(void *, void *, va_list); +int _ht_getnetbyaddr(void *, void *, va_list); +int _ht_getnetbyname(void *, void *, va_list); +int _nis_gethostbyaddr(void *, void *, va_list); +int _nis_gethostbyname(void *, void *, va_list); +int _nis_getnetbyaddr(void *, void *, va_list); +int _nis_getnetbyname(void *, void *, va_list); +#ifdef NS_CACHING +int __proto_id_func(char *, size_t *, va_list, void *); +int __proto_marshal_func(char *, size_t *, void *, va_list, void *); +int __proto_unmarshal_func(char *, size_t, void *, va_list, void *); +#endif #endif /* _NETDB_PRIVATE_H_ */ diff --git a/freebsd/lib/libc/net/nsdispatch.c b/freebsd/lib/libc/net/nsdispatch.c index f1a88d8d..8d0e1493 100644 --- a/freebsd/lib/libc/net/nsdispatch.c +++ b/freebsd/lib/libc/net/nsdispatch.c @@ -17,13 +17,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -147,14 +140,17 @@ static void *nss_cache_cycle_prevention_func = NULL; #endif /* - * When this is set to 1, nsdispatch won't use nsswitch.conf - * but will consult the 'defaults' source list only. - * NOTE: nested fallbacks (when nsdispatch calls fallback functions, - * which in turn calls nsdispatch, which should call fallback - * function) are not supported + * We keep track of nsdispatch() nesting depth in dispatch_depth. When a + * fallback method is invoked from nsdispatch(), we temporarily set + * fallback_depth to the current dispatch depth plus one. Subsequent + * calls at that exact depth will run in fallback mode (restricted to the + * same source as the call that was handled by the fallback method), while + * calls below that depth will be handled normally, allowing fallback + * methods to perform arbitrary lookups. */ struct fb_state { - int fb_dispatch; + int dispatch_depth; + int fallback_depth; }; static void fb_endstate(void *); NSS_TLS_HANDLING(fb); @@ -352,7 +348,6 @@ _nsdbtdump(const ns_dbt *dbt) static int nss_configure(void) { - static pthread_mutex_t conf_lock = PTHREAD_MUTEX_INITIALIZER; static time_t confmod; struct stat statbuf; int result, isthreaded; @@ -376,15 +371,16 @@ nss_configure(void) if (statbuf.st_mtime <= confmod) return (0); if (isthreaded) { - result = _pthread_mutex_trylock(&conf_lock); - if (result != 0) - return (0); (void)_pthread_rwlock_unlock(&nss_lock); result = _pthread_rwlock_wrlock(&nss_lock); if (result != 0) - goto fin2; + return (result); + if (stat(path, &statbuf) != 0) + goto fin; + if (statbuf.st_mtime <= confmod) + goto fin; } - _nsyyin = fopen(path, "r"); + _nsyyin = fopen(path, "re"); if (_nsyyin == NULL) goto fin; VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap), @@ -417,9 +413,6 @@ fin: if (result == 0) result = _pthread_rwlock_rdlock(&nss_lock); } -fin2: - if (isthreaded) - (void)_pthread_mutex_unlock(&conf_lock); return (result); } @@ -681,6 +674,7 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, void *mdata; int isthreaded, serrno, i, result, srclistsize; struct fb_state *st; + int saved_depth; #ifdef NS_CACHING nss_cache_data cache_data; @@ -712,7 +706,8 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, result = NS_UNAVAIL; goto fin; } - if (st->fb_dispatch == 0) { + ++st->dispatch_depth; + if (st->dispatch_depth > st->fallback_depth) { dbt = vector_search(&database, _nsmap, _nsmapsize, sizeof(*_nsmap), string_compare); fb_method = nss_method_lookup(NSSRC_FALLBACK, database, @@ -781,12 +776,13 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, break; } else { if (fb_method != NULL) { - st->fb_dispatch = 1; + saved_depth = st->fallback_depth; + st->fallback_depth = st->dispatch_depth + 1; va_start(ap, defaults); result = fb_method(retval, (void *)srclist[i].name, ap); va_end(ap); - st->fb_dispatch = 0; + st->fallback_depth = saved_depth; } else nss_log(LOG_DEBUG, "%s, %s, %s, not found, " "and no fallback provided", @@ -818,6 +814,7 @@ _nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, if (isthreaded) (void)_pthread_rwlock_unlock(&nss_lock); + --st->dispatch_depth; fin: errno = serrno; return (result); diff --git a/freebsd/lib/libc/net/nslexer.l b/freebsd/lib/libc/net/nslexer.l index bc36ea2b..c7a95f61 100644 --- a/freebsd/lib/libc/net/nslexer.l +++ b/freebsd/lib/libc/net/nslexer.l @@ -16,13 +16,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -104,14 +97,13 @@ STRING [a-zA-Z][a-zA-Z0-9_]* #undef _nsyywrap int -_nsyywrap() +_nsyywrap(void) { return 1; } /* _nsyywrap */ void -_nsyyerror(msg) - const char *msg; +_nsyyerror(const char *msg) { syslog(LOG_ERR, "NSSWITCH(nslexer): %s line %d: %s at '%s'", diff --git a/freebsd/lib/libc/net/nsparser.y b/freebsd/lib/libc/net/nsparser.y index 8f1d162d..773e23fc 100644 --- a/freebsd/lib/libc/net/nsparser.y +++ b/freebsd/lib/libc/net/nsparser.y @@ -16,13 +16,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -152,8 +145,7 @@ Action %% static void -_nsaddsrctomap(elem) - const char *elem; +_nsaddsrctomap(const char *elem) { int i, lineno; extern int _nsyylineno; diff --git a/freebsd/lib/libc/net/rcmd.c b/freebsd/lib/libc/net/rcmd.c index 2f5e593f..8458a34c 100644 --- a/freebsd/lib/libc/net/rcmd.c +++ b/freebsd/lib/libc/net/rcmd.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #endif #include <arpa/nameser.h> #include "un-namespace.h" +#include "libc_private.h" extern int innetgr( const char *, const char *, const char *, const char * ); @@ -74,22 +75,15 @@ static int __icheckhost(const struct sockaddr *, socklen_t, const char *); char paddr[NI_MAXHOST]; int -rcmd(ahost, rport, locuser, remuser, cmd, fd2p) - char **ahost; - u_short rport; - const char *locuser, *remuser, *cmd; - int *fd2p; +rcmd(char **ahost, int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p) { return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); } int -rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) - char **ahost; - u_short rport; - const char *locuser, *remuser, *cmd; - int *fd2p; - int af; +rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p, int af) { struct addrinfo hints, *res, *ai; struct sockaddr_storage from; @@ -150,7 +144,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) refused = 0; sigemptyset(&newmask); sigaddset(&newmask, SIGURG); - _sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); + __libc_sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); for (timo = 1, lport = IPPORT_RESERVED - 1;;) { s = rresvport_af(&lport, ai->ai_family); if (s < 0) { @@ -165,7 +159,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "rcmd: socket: %s\n", strerror(errno)); freeaddrinfo(res); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); return (-1); } @@ -183,7 +177,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno)); freeaddrinfo(res); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); return (-1); } @@ -215,7 +209,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) } } lport--; - if (fd2p == 0) { + if (fd2p == NULL) { _write(s, "", 1); lport = 0; } else { @@ -308,7 +302,7 @@ again: } goto bad2; } - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (s); bad2: @@ -316,21 +310,19 @@ bad2: (void)_close(*fd2p); bad: (void)_close(s); - _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); + __libc_sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (-1); } int -rresvport(port) - int *port; +rresvport(int *port) { return rresvport_af(port, AF_INET); } int -rresvport_af(alport, family) - int *alport, family; +rresvport_af(int *alport, int family) { int s; struct sockaddr_storage ss; @@ -381,9 +373,7 @@ int __check_rhosts_file = 1; char *__rcmd_errstr; int -ruserok(rhost, superuser, ruser, luser) - const char *rhost, *ruser, *luser; - int superuser; +ruserok(const char *rhost, int superuser, const char *ruser, const char *luser) { struct addrinfo hints, *res, *r; int error; @@ -416,10 +406,7 @@ ruserok(rhost, superuser, ruser, luser) * Returns 0 if ok, -1 if not ok. */ int -iruserok(raddr, superuser, ruser, luser) - unsigned long raddr; - int superuser; - const char *ruser, *luser; +iruserok(unsigned long raddr, int superuser, const char *ruser, const char *luser) { struct sockaddr_in sin; @@ -437,11 +424,8 @@ iruserok(raddr, superuser, ruser, luser) * Returns 0 if ok, -1 if not ok. */ int -iruserok_sa(ra, rlen, superuser, ruser, luser) - const void *ra; - int rlen; - int superuser; - const char *ruser, *luser; +iruserok_sa(const void *ra, int rlen, int superuser, const char *ruser, + const char *luser) { char *cp; struct stat sbuf; @@ -460,7 +444,7 @@ iruserok_sa(ra, rlen, superuser, ruser, luser) raddr = (struct sockaddr *)&ss; first = 1; - hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); + hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "re"); again: if (hostf) { if (__ivaliduser_sa(hostf, raddr, rlen, luser, ruser) == 0) { @@ -483,7 +467,7 @@ again: */ uid = geteuid(); (void)seteuid(pwd->pw_uid); - hostf = fopen(pbuf, "r"); + hostf = fopen(pbuf, "re"); (void)seteuid(uid); if (hostf == NULL) @@ -521,10 +505,7 @@ again: * Returns 0 if ok, -1 if not ok. */ int -__ivaliduser(hostf, raddr, luser, ruser) - FILE *hostf; - u_int32_t raddr; - const char *luser, *ruser; +__ivaliduser(FILE *hostf, u_int32_t raddr, const char *luser, const char *ruser) { struct sockaddr_in sin; @@ -542,11 +523,8 @@ __ivaliduser(hostf, raddr, luser, ruser) * XXX obsolete API. */ int -__ivaliduser_af(hostf, raddr, luser, ruser, af, len) - FILE *hostf; - const void *raddr; - const char *luser, *ruser; - int af, len; +__ivaliduser_af(FILE *hostf, const void *raddr, const char *luser, + const char *ruser, int af, int len) { struct sockaddr *sa = NULL; struct sockaddr_in *sin = NULL; @@ -585,11 +563,8 @@ __ivaliduser_af(hostf, raddr, luser, ruser, af, len) } int -__ivaliduser_sa(hostf, raddr, salen, luser, ruser) - FILE *hostf; - const struct sockaddr *raddr; - socklen_t salen; - const char *luser, *ruser; +__ivaliduser_sa(FILE *hostf, const struct sockaddr *raddr, socklen_t salen, + const char *luser, const char *ruser) { char *user, *p; int ch; @@ -708,10 +683,7 @@ __ivaliduser_sa(hostf, raddr, salen, luser, ruser) * Returns "true" if match, 0 if no match. */ static int -__icheckhost(raddr, salen, lhost) - const struct sockaddr *raddr; - socklen_t salen; - const char *lhost; +__icheckhost(const struct sockaddr *raddr, socklen_t salen, const char *lhost) { struct sockaddr_in sin; struct sockaddr_in6 *sin6; diff --git a/freebsd/lib/libc/net/recv.c b/freebsd/lib/libc/net/recv.c index 168cb85e..71c531c8 100644 --- a/freebsd/lib/libc/net/recv.c +++ b/freebsd/lib/libc/net/recv.c @@ -35,18 +35,25 @@ static char sccsid[] = "@(#)recv.c 8.2 (Berkeley) 2/21/94"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include "namespace.h" #include <sys/types.h> #include <sys/socket.h> +#include "libc_private.h" #include <stddef.h> -#include "un-namespace.h" ssize_t -recv(s, buf, len, flags) - int s, flags; - size_t len; - void *buf; +recv(int s, void *buf, size_t len, int flags) { - return (_recvfrom(s, buf, len, flags, NULL, 0)); + /* + * POSIX says recv() shall be a cancellation point, so call the + * cancellation-enabled recvfrom() and not _recvfrom(). + */ +#ifndef __rtems__ + return (((ssize_t (*)(int, void *, size_t, int, + struct sockaddr *, socklen_t *)) + __libc_interposing[INTERPOS_recvfrom])(s, buf, len, flags, + NULL, NULL)); +#else /* __rtems__ */ + return (recvfrom(s, buf, len, flags, NULL, 0)); +#endif /* __rtems__ */ } diff --git a/freebsd/lib/libc/net/res_config.h b/freebsd/lib/libc/net/res_config.h index 411542d1..c730aad3 100644 --- a/freebsd/lib/libc/net/res_config.h +++ b/freebsd/lib/libc/net/res_config.h @@ -2,7 +2,7 @@ #define DEBUG 1 /* enable debugging code (needed for dig) */ #define RESOLVSORT /* allow sorting of addresses in gethostbyname */ -#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */ +#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DON'T NEED IT */ #define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */ #ifdef __rtems__ #define dprintf gethostbydns_dprintf diff --git a/freebsd/lib/libc/net/rthdr.c b/freebsd/lib/libc/net/rthdr.c index f2a1d3d0..dd7c9a9a 100644 --- a/freebsd/lib/libc/net/rthdr.c +++ b/freebsd/lib/libc/net/rthdr.c @@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -49,8 +48,7 @@ __FBSDID("$FreeBSD$"); */ size_t -inet6_rthdr_space(type, seg) - int type, seg; +inet6_rthdr_space(int type, int seg) { switch (type) { case IPV6_RTHDR_TYPE_0: @@ -69,9 +67,7 @@ inet6_rthdr_space(type, seg) } struct cmsghdr * -inet6_rthdr_init(bp, type) - void *bp; - int type; +inet6_rthdr_init(void *bp, int type) { struct cmsghdr *ch = (struct cmsghdr *)bp; struct ip6_rthdr *rthdr; @@ -100,10 +96,7 @@ inet6_rthdr_init(bp, type) /* ARGSUSED */ int -inet6_rthdr_add(cmsg, addr, flags) - struct cmsghdr *cmsg; - const struct in6_addr *addr; - u_int flags; +inet6_rthdr_add(struct cmsghdr *cmsg, const struct in6_addr *addr, u_int flags) { struct ip6_rthdr *rthdr; @@ -145,9 +138,7 @@ inet6_rthdr_add(cmsg, addr, flags) /* ARGSUSED */ int -inet6_rthdr_lasthop(cmsg, flags) - struct cmsghdr *cmsg; - unsigned int flags; +inet6_rthdr_lasthop(struct cmsghdr *cmsg, unsigned int flags) { struct ip6_rthdr *rthdr; @@ -185,9 +176,7 @@ inet6_rthdr_lasthop(cmsg, flags) #if 0 int -inet6_rthdr_reverse(in, out) - const struct cmsghdr *in; - struct cmsghdr *out; +inet6_rthdr_reverse(const struct cmsghdr *in, struct cmsghdr *out) { return (-1); @@ -195,8 +184,7 @@ inet6_rthdr_reverse(in, out) #endif int -inet6_rthdr_segments(cmsg) - const struct cmsghdr *cmsg; +inet6_rthdr_segments(const struct cmsghdr *cmsg) { struct ip6_rthdr *rthdr; @@ -219,9 +207,7 @@ inet6_rthdr_segments(cmsg) } struct in6_addr * -inet6_rthdr_getaddr(cmsg, idx) - struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getaddr(struct cmsghdr *cmsg, int idx) { struct ip6_rthdr *rthdr; @@ -251,9 +237,7 @@ inet6_rthdr_getaddr(cmsg, idx) } int -inet6_rthdr_getflags(cmsg, idx) - const struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getflags(const struct cmsghdr *cmsg, int idx) { struct ip6_rthdr *rthdr; diff --git a/freebsd/lib/libc/net/send.c b/freebsd/lib/libc/net/send.c index aac2e1f8..332f850d 100644 --- a/freebsd/lib/libc/net/send.c +++ b/freebsd/lib/libc/net/send.c @@ -35,18 +35,25 @@ static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include "namespace.h" #include <sys/types.h> #include <sys/socket.h> +#include "libc_private.h" #include <stddef.h> -#include "un-namespace.h" ssize_t -send(s, msg, len, flags) - int s, flags; - size_t len; - const void *msg; +send(int s, const void *msg, size_t len, int flags) { - return (_sendto(s, msg, len, flags, NULL, 0)); + /* + * POSIX says send() shall be a cancellation point, so call the + * cancellation-enabled sendto() and not _sendto(). + */ +#ifndef __rtems__ + return (((ssize_t (*)(int, const void *, size_t, int, + const struct sockaddr *, socklen_t)) + __libc_interposing[INTERPOS_sendto])(s, msg, len, flags, + NULL, 0)); +#else /* __rtems__ */ + return (sendto(s, msg, len, flags, NULL, 0)); +#endif /* __rtems__ */ } diff --git a/freebsd/lib/libc/posix1e/mac.c b/freebsd/lib/libc/posix1e/mac.c index 3806130a..16e45199 100644 --- a/freebsd/lib/libc/posix1e/mac.c +++ b/freebsd/lib/libc/posix1e/mac.c @@ -181,7 +181,7 @@ mac_init_internal(int ignore_errors) filename = getenv("MAC_CONFFILE"); else filename = MAC_CONFFILE; - file = fopen(filename, "r"); + file = fopen(filename, "re"); if (file == NULL) return (0); diff --git a/freebsd/lib/libc/resolv/h_errno.c b/freebsd/lib/libc/resolv/h_errno.c index 4902e22c..aed29e84 100644 --- a/freebsd/lib/libc/resolv/h_errno.c +++ b/freebsd/lib/libc/resolv/h_errno.c @@ -35,6 +35,9 @@ #undef h_errno extern int h_errno; +int *__h_errno(void); +void __h_errno_set(res_state res, int err); + int * __h_errno(void) { diff --git a/freebsd/lib/libc/resolv/herror.c b/freebsd/lib/libc/resolv/herror.c index aea3a745..1c6900b0 100644 --- a/freebsd/lib/libc/resolv/herror.c +++ b/freebsd/lib/libc/resolv/herror.c @@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" #include "namespace.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/uio.h> @@ -78,7 +77,7 @@ const char *h_errlist[] = { "Unknown server error", /*%< 3 NO_RECOVERY */ "No address associated with name", /*%< 4 NO_ADDRESS */ }; -const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; +const int h_nerr = { nitems(h_errlist) }; #undef h_errno int h_errno; diff --git a/freebsd/lib/libc/resolv/mtctxres.c b/freebsd/lib/libc/resolv/mtctxres.c index 6ba2bc97..f4fd36a5 100644 --- a/freebsd/lib/libc/resolv/mtctxres.c +++ b/freebsd/lib/libc/resolv/mtctxres.c @@ -77,7 +77,7 @@ __res_init_ctx(void) { return (0); } - if ((mt = malloc(sizeof (mtctxres_t))) == 0) { + if ((mt = malloc(sizeof(mtctxres_t))) == NULL) { errno = ENOMEM; return (-1); } @@ -96,10 +96,7 @@ __res_init_ctx(void) { static void __res_destroy_ctx(void *value) { - mtctxres_t *mt = (mtctxres_t *)value; - - if (mt != 0) - free(mt); + free(value); } #endif @@ -134,9 +131,9 @@ ___mtctxres(void) { * that fails return a global context. */ if (mt_key_initialized) { - if (((mt = pthread_getspecific(key)) != 0) || + if (((mt = pthread_getspecific(key)) != NULL) || (__res_init_ctx() == 0 && - (mt = pthread_getspecific(key)) != 0)) { + (mt = pthread_getspecific(key)) != NULL)) { return (mt); } } diff --git a/freebsd/lib/libc/resolv/res_comp.c b/freebsd/lib/libc/resolv/res_comp.c index 9b6ee369..9908da3c 100644 --- a/freebsd/lib/libc/resolv/res_comp.c +++ b/freebsd/lib/libc/resolv/res_comp.c @@ -74,7 +74,6 @@ static const char rcsid[] = "$Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <netinet/in.h> #include <arpa/nameser.h> @@ -88,7 +87,7 @@ __FBSDID("$FreeBSD$"); /*% * Expand compressed domain name 'src' to full domain name. * - * \li 'msg' is a pointer to the begining of the message, + * \li 'msg' is a pointer to the beginning of the message, * \li 'eom' points to the first location after the message, * \li 'dst' is a pointer to a buffer of size 'dstsiz' for the result. * \li Return size of compressed name or -1 if there was an error. @@ -149,12 +148,12 @@ dn_skipname(const u_char *ptr, const u_char *eom) { || ((c) >= 0x61 && (c) <= 0x7a)) #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) -#define borderchar(c) (alphachar(c) || digitchar(c)) #ifdef RES_ENFORCE_RFC1034 -#define middlechar(c) (borderchar(c) || hyphenchar(c)) +#define borderchar(c) (alphachar(c) || digitchar(c)) #else -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) +#define borderchar(c) (alphachar(c) || digitchar(c) || underscorechar(c)) #endif +#define middlechar(c) (borderchar(c) || hyphenchar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int diff --git a/freebsd/lib/libc/resolv/res_data.c b/freebsd/lib/libc/resolv/res_data.c index 0ab7ed20..e89390f8 100644 --- a/freebsd/lib/libc/resolv/res_data.c +++ b/freebsd/lib/libc/resolv/res_data.c @@ -25,7 +25,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> #include <sys/time.h> @@ -79,9 +78,10 @@ const char *_res_sectioncodes[] = { int res_ourserver_p(const res_state, const struct sockaddr_in *); -int +__noinline int res_init(void) { extern int __res_vinit(res_state, int); + res_state statp = &_res; /* * These three fields used to be statically initialized. This made @@ -102,14 +102,14 @@ res_init(void) { * set in RES_DEFAULT). Our solution is to declare such applications * "broken". They could fool us by setting RES_INIT but none do (yet). */ - if (!_res.retrans) - _res.retrans = RES_TIMEOUT; - if (!_res.retry) - _res.retry = RES_DFLRETRY; - if (!(_res.options & RES_INIT)) - _res.options = RES_DEFAULT; - - return (__res_vinit(&_res, 1)); + if (!statp->retrans) + statp->retrans = RES_TIMEOUT; + if (!statp->retry) + statp->retry = RES_DFLRETRY; + if (!(statp->options & RES_INIT)) + statp->options = RES_DEFAULT; + + return (__res_vinit(statp, 1)); } void @@ -124,10 +124,11 @@ fp_query(const u_char *msg, FILE *file) { void fp_nquery(const u_char *msg, int len, FILE *file) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) return; - res_pquery(&_res, msg, len, file); + res_pquery(statp, msg, len, file); } int @@ -140,23 +141,25 @@ res_mkquery(int op, /*!< opcode of query */ u_char *buf, /*!< buffer to put query */ int buflen) /*!< size of buffer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nmkquery(&_res, op, dname, class, type, + return (res_nmkquery(statp, op, dname, class, type, data, datalen, newrr_in, buf, buflen)); } int res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nmkupdate(&_res, rrecp_in, buf, buflen)); + return (res_nmkupdate(statp, rrecp_in, buf, buflen)); } int @@ -165,11 +168,12 @@ res_query(const char *name, /*!< domain name */ u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer buffer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nquery(&_res, name, class, type, answer, anslen)); + return (res_nquery(statp, name, class, type, answer, anslen)); } #ifndef _LIBC @@ -191,12 +195,13 @@ res_isourserver(const struct sockaddr_in *inp) { int res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } - return (res_nsend(&_res, buf, buflen, ans, anssiz)); + return (res_nsend(statp, buf, buflen, ans, anssiz)); } #ifndef _LIBC @@ -204,12 +209,13 @@ int res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } - return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz)); + return (res_nsendsigned(statp, buf, buflen, key, ans, anssiz)); } #endif @@ -220,12 +226,13 @@ res_close(void) { int res_update(ns_updrec *rrecp_in) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nupdate(&_res, rrecp_in, NULL)); + return (res_nupdate(statp, rrecp_in, NULL)); } int @@ -234,12 +241,13 @@ res_search(const char *name, /*!< domain name */ u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nsearch(&_res, name, class, type, answer, anslen)); + return (res_nsearch(statp, name, class, type, answer, anslen)); } int @@ -249,24 +257,26 @@ res_querydomain(const char *name, u_char *answer, /*!< buffer to put answer */ int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nquerydomain(&_res, name, domain, + return (res_nquerydomain(statp, name, domain, class, type, answer, anslen)); } u_int res_randomid(void) { - if ((_res.options & RES_INIT) == 0U && res_init() == -1) { - RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + res_state statp = &_res; + if ((statp->options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (-1); } - return (res_nrandomid(&_res)); + return (res_nrandomid(statp)); } int @@ -286,13 +296,15 @@ hostalias(const char *name) { int local_hostname_length(const char *hostname) { int len_host, len_domain; + res_state statp; - if (!*_res.defdname) + statp = &_res; + if (!*statp->defdname) res_init(); len_host = strlen(hostname); - len_domain = strlen(_res.defdname); + len_domain = strlen(statp->defdname); if (len_host > len_domain && - !strcasecmp(hostname + len_host - len_domain, _res.defdname) && + !strcasecmp(hostname + len_host - len_domain, statp->defdname) && hostname[len_host - len_domain - 1] == '.') return (len_host - len_domain - 1); return (0); diff --git a/freebsd/lib/libc/resolv/res_debug.c b/freebsd/lib/libc/resolv/res_debug.c index 632aa666..d2551e57 100644 --- a/freebsd/lib/libc/resolv/res_debug.c +++ b/freebsd/lib/libc/resolv/res_debug.c @@ -100,7 +100,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> @@ -369,11 +368,8 @@ p_cdname(const u_char *cp, const u_char *msg, FILE *file) { length supplied). */ const u_char * -p_fqnname(cp, msg, msglen, name, namelen) - const u_char *cp, *msg; - int msglen; - char *name; - int namelen; +p_fqnname(const u_char *cp, const u_char *msg, int msglen, char *name, + int namelen) { int n, newlen; @@ -760,8 +756,7 @@ static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, /*% takes an XeY precision/size value, returns a string representation. */ static const char * -precsize_ntoa(prec) - u_int8_t prec; +precsize_ntoa(u_int8_t prec) { char *retbuf = precsize_ntoa_retbuf; unsigned long val; @@ -914,9 +909,7 @@ latlon2ul(const char **latlonstrptr, int *which) { * converts a zone file representation in a string to an RDATA on-the-wire * representation. */ int -loc_aton(ascii, binary) - const char *ascii; - u_char *binary; +loc_aton(const char *ascii, u_char *binary) { const char *cp, *maxcp; u_char *bcp; @@ -1025,9 +1018,7 @@ loc_aton(ascii, binary) /*% takes an on-the-wire LOC RR and formats it in a human readable format. */ const char * -loc_ntoa(binary, ascii) - const u_char *binary; - char *ascii; +loc_ntoa(const u_char *binary, char *ascii) { static const char *error = "?"; static char tmpbuf[sizeof diff --git a/freebsd/lib/libc/resolv/res_findzonecut.c b/freebsd/lib/libc/resolv/res_findzonecut.c index e776a1eb..360bd498 100644 --- a/freebsd/lib/libc/resolv/res_findzonecut.c +++ b/freebsd/lib/libc/resolv/res_findzonecut.c @@ -121,7 +121,7 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2); * notes: *\li this function calls res_nsend() which means it depends on correctly * functioning recursive nameservers (usually defined in /etc/resolv.conf - * or its local equivilent). + * or its local equivalent). * *\li we start by asking for an SOA<dname,class>. if we get one as an * answer, that just means <dname,class> is a zone top, which is fine. diff --git a/freebsd/lib/libc/resolv/res_init.c b/freebsd/lib/libc/resolv/res_init.c index 75a8dff3..1c7b8c25 100644 --- a/freebsd/lib/libc/resolv/res_init.c +++ b/freebsd/lib/libc/resolv/res_init.c @@ -77,9 +77,9 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> +#include <sys/stat.h> #include <sys/time.h> #include <netinet/in.h> @@ -117,7 +117,9 @@ __FBSDID("$FreeBSD$"); /*% Options. Should all be left alone. */ #define RESOLVSORT -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #ifdef SOLARIS2 #include <sys/systeminfo.h> @@ -144,7 +146,7 @@ static u_int32_t net_mask(struct in_addr); * there will have precedence. Otherwise, the server address is set to * INADDR_ANY and the default domain name comes from the gethostname(). * - * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 + * An interim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 * rather than INADDR_ANY ("0.0.0.0") as the default name server address * since it was noted that INADDR_ANY actually meant ``the first interface * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, @@ -167,7 +169,7 @@ res_ninit(res_state statp) { return (__res_vinit(statp, 0)); } -/*% This function has to be reachable by res_data.c but not publically. */ +/*% This function has to be reachable by res_data.c but not publicly. */ int __res_vinit(res_state statp, int preinit) { FILE *fp; @@ -238,6 +240,7 @@ __res_vinit(res_state statp, int preinit) { statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); + statp->_u._ext.ext->reload_period = 2; } else { /* * Historically res_init() rarely, if at all, failed. @@ -313,7 +316,7 @@ __res_vinit(res_state statp, int preinit) { while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n') cp++; *cp = '\0'; - *pp++ = 0; + *pp++ = NULL; } #define MATCH(line, name) \ @@ -322,7 +325,19 @@ __res_vinit(res_state statp, int preinit) { line[sizeof(name) - 1] == '\t')) nserv = 0; - if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { + if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) { + struct stat sb; + struct timespec now; + + if (statp->_u._ext.ext != NULL) { + if (_fstat(fileno(fp), &sb) == 0) { + statp->_u._ext.ext->conf_mtim = sb.st_mtim; + if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) == 0) { + statp->_u._ext.ext->conf_stat = now.tv_sec; + } + } + } + /* read the config file */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ @@ -377,7 +392,7 @@ __res_vinit(res_state statp, int preinit) { while (*cp != '\0' && *cp != ' ' && *cp != '\t') cp++; *cp = '\0'; - *pp++ = 0; + *pp++ = NULL; havesearch = 1; continue; } @@ -398,20 +413,21 @@ __res_vinit(res_state statp, int preinit) { hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; sprintf(sbuf, "%u", NAMESERVER_PORT); - if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 && - ai->ai_addrlen <= minsiz) { - if (statp->_u._ext.ext != NULL) { - memcpy(&statp->_u._ext.ext->nsaddrs[nserv], - ai->ai_addr, ai->ai_addrlen); + if (getaddrinfo(cp, sbuf, &hints, &ai) == 0) { + if (ai->ai_addrlen <= minsiz) { + if (statp->_u._ext.ext != NULL) { + memcpy(&statp->_u._ext.ext->nsaddrs[nserv], + ai->ai_addr, ai->ai_addrlen); + } + if (ai->ai_addrlen <= + sizeof(statp->nsaddr_list[nserv])) { + memcpy(&statp->nsaddr_list[nserv], + ai->ai_addr, ai->ai_addrlen); + } else + statp->nsaddr_list[nserv].sin_family = 0; + nserv++; } - if (ai->ai_addrlen <= - sizeof(statp->nsaddr_list[nserv])) { - memcpy(&statp->nsaddr_list[nserv], - ai->ai_addr, ai->ai_addrlen); - } else - statp->nsaddr_list[nserv].sin_family = 0; freeaddrinfo(ai); - nserv++; } } continue; @@ -583,9 +599,7 @@ res_setoptions(res_state statp, const char *options, const char *source) { const char *cp = options; int i; -#ifndef _LIBC struct __res_state_ext *ext = statp->_u._ext.ext; -#endif #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -668,6 +682,12 @@ res_setoptions(res_state statp, const char *options, const char *source) } else if (!strncmp(cp, "no-check-names", sizeof("no-check-names") - 1)) { statp->options |= RES_NOCHECKNAME; + } else if (!strncmp(cp, "reload-period:", + sizeof("reload-period:") - 1)) { + if (ext != NULL) { + ext->reload_period = (u_short) + atoi(cp + sizeof("reload-period:") - 1); + } } #ifdef RES_USE_EDNS0 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { @@ -720,8 +740,7 @@ res_setoptions(res_state statp, const char *options, const char *source) #ifdef RESOLVSORT /* XXX - should really support CIDR which means explicit masks always. */ static u_int32_t -net_mask(in) /*!< XXX - should really use system's version of this */ - struct in_addr in; +net_mask(struct in_addr in) /*!< XXX - should really use system's version of this */ { u_int32_t i = ntohl(in.s_addr); diff --git a/freebsd/lib/libc/resolv/res_mkquery.c b/freebsd/lib/libc/resolv/res_mkquery.c index 84800095..866dbaf6 100644 --- a/freebsd/lib/libc/resolv/res_mkquery.c +++ b/freebsd/lib/libc/resolv/res_mkquery.c @@ -74,7 +74,6 @@ static const char rcsid[] = "$Id: res_mkquery.c,v 1.10 2008/12/11 09:59:00 marka __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <netinet/in.h> #include <arpa/nameser.h> @@ -85,7 +84,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif extern const char *_res_opcodes[]; @@ -133,7 +134,7 @@ res_nmkquery(res_state statp, dpp = dnptrs; *dpp++ = buf; *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + lastdnptr = dnptrs + nitems(dnptrs); /* * perform opcode specific processing */ diff --git a/freebsd/lib/libc/resolv/res_mkupdate.c b/freebsd/lib/libc/resolv/res_mkupdate.c index fade9356..6b0c484f 100644 --- a/freebsd/lib/libc/resolv/res_mkupdate.c +++ b/freebsd/lib/libc/resolv/res_mkupdate.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <netinet/in.h> @@ -56,7 +55,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #define MAXPORT 1024 static int getnum_str(u_char **, u_char *); @@ -127,7 +128,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { dpp = dnptrs; *dpp++ = buf; *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; + lastdnptr = dnptrs + nitems(dnptrs); if (rrecp_start == NULL) return (-5); @@ -975,7 +976,7 @@ struct valuelist { static struct valuelist *servicelist, *protolist; static void -res_buildservicelist() { +res_buildservicelist(void) { struct servent *sp; struct valuelist *slp; @@ -1175,7 +1176,7 @@ res_protocolname(int num) { if (protolist == (struct valuelist *)0) res_buildprotolist(); pp = cgetprotobynumber(num); - if (pp == 0) { + if (pp == NULL) { (void) sprintf(number, "%d", num); return (number); } @@ -1190,7 +1191,7 @@ res_servicename(u_int16_t port, const char *proto) { /*%< Host byte order. */ if (servicelist == (struct valuelist *)0) res_buildservicelist(); ss = cgetservbyport(htons(port), proto); - if (ss == 0) { + if (ss == NULL) { (void) sprintf(number, "%d", port); return (number); } diff --git a/freebsd/lib/libc/resolv/res_private.h b/freebsd/lib/libc/resolv/res_private.h index 4e98157c..a986e95c 100644 --- a/freebsd/lib/libc/resolv/res_private.h +++ b/freebsd/lib/libc/resolv/res_private.h @@ -1,3 +1,5 @@ +/* $FreeBSD$ */ + #ifndef res_private_h #define res_private_h @@ -12,6 +14,9 @@ struct __res_state_ext { } sort_list[MAXRESOLVSORT]; char nsuffix[64]; char nsuffix2[64]; + struct timespec conf_mtim; /* mod time of loaded resolv.conf */ + time_t conf_stat; /* time of last stat(resolv.conf) */ + u_short reload_period; /* seconds between stat(resolv.conf) */ }; extern int diff --git a/freebsd/lib/libc/resolv/res_query.c b/freebsd/lib/libc/resolv/res_query.c index 9dd8f186..7189e6e2 100644 --- a/freebsd/lib/libc/resolv/res_query.c +++ b/freebsd/lib/libc/resolv/res_query.c @@ -74,7 +74,6 @@ static const char rcsid[] = "$Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka E __FBSDID("$FreeBSD$"); #include "port_before.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -90,7 +89,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #if PACKETSZ > 1024 #define MAXPACKET PACKETSZ @@ -136,8 +137,8 @@ again: if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 && (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID))) { n = res_nopt(statp, n, buf, sizeof(buf), anslen); - rdata = &buf[n]; if (n > 0 && (statp->options & RES_NSID) != 0U) { + rdata = &buf[n]; n = res_nopt_rdata(statp, n, buf, sizeof(buf), rdata, NS_OPT_NSID, 0, NULL); } @@ -459,7 +460,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { if (issetugid()) return (NULL); file = getenv("HOSTALIASES"); - if (file == NULL || (fp = fopen(file, "r")) == NULL) + if (file == NULL || (fp = fopen(file, "re")) == NULL) return (NULL); setbuf(fp, NULL); buf[sizeof(buf) - 1] = '\0'; diff --git a/freebsd/lib/libc/resolv/res_send.c b/freebsd/lib/libc/resolv/res_send.c index c39d8df9..73817ad5 100644 --- a/freebsd/lib/libc/resolv/res_send.c +++ b/freebsd/lib/libc/resolv/res_send.c @@ -79,12 +79,11 @@ __FBSDID("$FreeBSD$"); */ #include "port_before.h" -#ifndef USE_KQUEUE +#if !defined(USE_KQUEUE) && !defined(USE_POLL) #include "fd_setsize.h" #endif #include "namespace.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/time.h> #include <sys/socket.h> @@ -121,7 +120,9 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #include "res_debug.h" #include "res_private.h" @@ -576,8 +577,7 @@ res_nsend(res_state statp, /* Private */ static int -get_salen(sa) - const struct sockaddr *sa; +get_salen(const struct sockaddr *sa) { #ifdef HAVE_SA_LEN @@ -598,9 +598,7 @@ get_salen(sa) * pick appropriate nsaddr_list for use. see res_init() for initialization. */ static struct sockaddr * -get_nsaddr(statp, n) - res_state statp; - size_t n; +get_nsaddr(res_state statp, size_t n) { if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) { @@ -662,7 +660,8 @@ send_vc(res_state statp, if (statp->_vcsock >= 0) res_nclose(statp); - statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM, 0); + statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM | + SOCK_CLOEXEC, 0); #if !defined(USE_POLL) && !defined(USE_KQUEUE) if (statp->_vcsock > highestFD) { res_nclose(statp); @@ -853,7 +852,7 @@ send_dg(res_state statp, nsaplen = get_salen(nsap); if (EXT(statp).nssocks[ns] == -1) { EXT(statp).nssocks[ns] = _socket(nsap->sa_family, - SOCK_DGRAM, 0); + SOCK_DGRAM | SOCK_CLOEXEC, 0); #if !defined(USE_POLL) && !defined(USE_KQUEUE) if (EXT(statp).nssocks[ns] > highestFD) { res_nclose(statp); @@ -964,7 +963,7 @@ send_dg(res_state statp, timeout.tv_nsec/1000000; pollfd.fd = s; pollfd.events = POLLRDNORM; - n = poll(&pollfd, 1, polltimeout); + n = _poll(&pollfd, 1, polltimeout); #endif /* USE_POLL */ if (n == 0) { diff --git a/freebsd/lib/libc/resolv/res_state.c b/freebsd/lib/libc/resolv/res_state.c index a89b9b5e..1cfe1700 100644 --- a/freebsd/lib/libc/resolv/res_state.c +++ b/freebsd/lib/libc/resolv/res_state.c @@ -28,6 +28,8 @@ */ #include <sys/types.h> +#include <sys/stat.h> +#include <sys/time.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> @@ -37,6 +39,8 @@ #include "reentrant.h" #include "un-namespace.h" +#include "res_private.h" + #undef _res struct __res_state _res; @@ -61,6 +65,37 @@ res_keycreate(void) res_thr_keycreated = thr_keycreate(&res_key, free_res) == 0; } +static res_state +res_check_reload(res_state statp) +{ + struct timespec now; + struct stat sb; + struct __res_state_ext *ext; + + if ((statp->options & RES_INIT) == 0) { + return (statp); + } + + ext = statp->_u._ext.ext; + if (ext == NULL || ext->reload_period == 0) { + return (statp); + } + + if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) != 0 || + (now.tv_sec - ext->conf_stat) < ext->reload_period) { + return (statp); + } + + ext->conf_stat = now.tv_sec; + if (stat(_PATH_RESCONF, &sb) == 0 && + (sb.st_mtim.tv_sec != ext->conf_mtim.tv_sec || + sb.st_mtim.tv_nsec != ext->conf_mtim.tv_nsec)) { + statp->options &= ~RES_INIT; + } + + return (statp); +} + res_state __res_state(void) { @@ -68,7 +103,7 @@ __res_state(void) #ifndef __rtems__ if (thr_main() != 0) - return (&_res); + return res_check_reload(&_res); #endif /* __rtems__ */ if (thr_once(&res_init_once, res_keycreate) != 0 || @@ -77,7 +112,7 @@ __res_state(void) statp = thr_getspecific(res_key); if (statp != NULL) - return (statp); + return res_check_reload(statp); statp = calloc(1, sizeof(*statp)); if (statp == NULL) return (&_res); diff --git a/freebsd/lib/libc/rpc/auth_des.c b/freebsd/lib/libc/rpc/auth_des.c index b3002301..02943484 100644 --- a/freebsd/lib/libc/rpc/auth_des.c +++ b/freebsd/lib/libc/rpc/auth_des.c @@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$"); extern bool_t xdr_authdes_cred( XDR *, struct authdes_cred *); extern bool_t xdr_authdes_verf( XDR *, struct authdes_verf *); -extern int key_encryptsession_pk(); +extern int key_encryptsession_pk(char *, netobj *, des_block *); extern bool_t __rpc_get_time_offset(struct timeval *, nis_server *, char *, char **, char **); @@ -261,7 +261,7 @@ failed: */ /*ARGSUSED*/ static void -authdes_nextverf(AUTH *auth) +authdes_nextverf(AUTH *auth __unused) { /* what the heck am I supposed to do??? */ } @@ -287,7 +287,7 @@ authdes_marshal(AUTH *auth, XDR *xdrs) * Figure out the "time", accounting for any time difference * with the server if necessary. */ - (void) gettimeofday(&ad->ad_timestamp, (struct timezone *)NULL); + (void)gettimeofday(&ad->ad_timestamp, NULL); ad->ad_timestamp.tv_sec += ad->ad_timediff.tv_sec; ad->ad_timestamp.tv_usec += ad->ad_timediff.tv_usec; while (ad->ad_timestamp.tv_usec >= USEC_PER_SEC) { @@ -422,7 +422,7 @@ authdes_validate(AUTH *auth, struct opaque_auth *rverf) */ /*ARGSUSED*/ static bool_t -authdes_refresh(AUTH *auth, void *dummy) +authdes_refresh(AUTH *auth, void *dummy __unused) { /* LINTED pointer alignment */ struct ad_private *ad = AUTH_PRIVATE(auth); diff --git a/freebsd/lib/libc/rpc/auth_none.c b/freebsd/lib/libc/rpc/auth_none.c index 821771de..9f91292a 100644 --- a/freebsd/lib/libc/rpc/auth_none.c +++ b/freebsd/lib/libc/rpc/auth_none.c @@ -67,9 +67,9 @@ static bool_t authnone_validate (AUTH *, struct opaque_auth *); static bool_t authnone_refresh (AUTH *, void *); static void authnone_destroy (AUTH *); -extern bool_t xdr_opaque_auth(); +extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); -static struct auth_ops *authnone_ops(); +static struct auth_ops *authnone_ops(void); static struct authnone_private { AUTH no_client; @@ -78,16 +78,16 @@ static struct authnone_private { } *authnone_private; AUTH * -authnone_create() +authnone_create(void) { struct authnone_private *ap = authnone_private; XDR xdr_stream; XDR *xdrs; mutex_lock(&authnone_lock); - if (ap == 0) { - ap = (struct authnone_private *)calloc(1, sizeof (*ap)); - if (ap == 0) { + if (ap == NULL) { + ap = calloc(1, sizeof (*ap)); + if (ap == NULL) { mutex_unlock(&authnone_lock); return (0); } @@ -158,7 +158,7 @@ authnone_destroy(AUTH *client) } static struct auth_ops * -authnone_ops() +authnone_ops(void) { static struct auth_ops ops; diff --git a/freebsd/lib/libc/rpc/auth_time.c b/freebsd/lib/libc/rpc/auth_time.c index 09e197a7..a685ebb5 100644 --- a/freebsd/lib/libc/rpc/auth_time.c +++ b/freebsd/lib/libc/rpc/auth_time.c @@ -63,8 +63,7 @@ extern int _rpc_dtablesize( void ); static int saw_alarm = 0; static void -alarm_hndler(s) - int s; +alarm_hndler(int s) { saw_alarm = 1; return; @@ -85,12 +84,7 @@ alarm_hndler(s) * Turn a 'universal address' into a struct sockaddr_in. * Bletch. */ -static int uaddr_to_sockaddr(uaddr, sin) -#ifdef foo - endpoint *endpt; -#endif - char *uaddr; - struct sockaddr_in *sin; +static int uaddr_to_sockaddr(char *uaddr, struct sockaddr_in *sin) { unsigned char p_bytes[2]; int i; @@ -120,9 +114,7 @@ static int uaddr_to_sockaddr(uaddr, sin) * Free the strings that were strduped into the eps structure. */ static void -free_eps(eps, num) - endpoint eps[]; - int num; +free_eps(endpoint eps[], int num) { int i; @@ -144,14 +136,15 @@ free_eps(eps, num) * fact that gethostbyname() could do an NIS search. Ideally, the * NIS+ server will call __rpc_get_time_offset() with the nis_server * structure already populated. + * + * host - name of the time host + * srv - nis_server struct to use. + * eps[] - array of endpoints + * maxep - max array size */ static nis_server * -get_server(sin, host, srv, eps, maxep) - struct sockaddr_in *sin; - char *host; /* name of the time host */ - nis_server *srv; /* nis_server struct to use. */ - endpoint eps[]; /* array of endpoints */ - int maxep; /* max array size */ +get_server(struct sockaddr_in *sin, char *host, nis_server *srv, + endpoint eps[], int maxep) { char hname[256]; int num_ep = 0, i; @@ -238,14 +231,16 @@ get_server(sin, host, srv, eps, maxep) * structure and to then contact the machine for the time. * * td = "server" - "client" + * + * td - Time difference + * srv - NIS Server description + * thost - if no server, this is the timehost + * uaddr - known universal address + * netid - known network identifier */ int -__rpc_get_time_offset(td, srv, thost, uaddr, netid) - struct timeval *td; /* Time difference */ - nis_server *srv; /* NIS Server description */ - char *thost; /* if no server, this is the timehost */ - char **uaddr; /* known universal address */ - struct sockaddr_in *netid; /* known network identifier */ +__rpc_get_time_offset(struct timeval *td, nis_server *srv, char *thost, + char **uaddr, struct sockaddr_in *netid) { CLIENT *clnt; /* Client handle */ endpoint *ep, /* useful endpoints */ @@ -262,7 +257,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) char ut[64], ipuaddr[64]; endpoint teps[32]; nis_server tsrv; - void (*oldsig)() = NULL; /* old alarm handler */ + void (*oldsig)(int) = NULL; /* old alarm handler */ struct sockaddr_in sin; socklen_t len; int s = RPC_ANYSOCK; @@ -431,7 +426,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) } else { int res; - oldsig = (void (*)())signal(SIGALRM, alarm_hndler); + oldsig = (void (*)(int))signal(SIGALRM, alarm_hndler); saw_alarm = 0; /* global tracking the alarm */ alarm(20); /* only wait 20 seconds */ res = _connect(s, (struct sockaddr *)&sin, sizeof(sin)); diff --git a/freebsd/lib/libc/rpc/auth_unix.c b/freebsd/lib/libc/rpc/auth_unix.c index 1d9130df..b27236ad 100644 --- a/freebsd/lib/libc/rpc/auth_unix.c +++ b/freebsd/lib/libc/rpc/auth_unix.c @@ -93,12 +93,7 @@ struct audata { * Returns an auth handle with the given stuff in it. */ AUTH * -authunix_create(machname, uid, gid, len, aup_gids) - char *machname; - u_int uid; - u_int gid; - int len; - u_int *aup_gids; +authunix_create(char *machname, u_int uid, u_int gid, int len, u_int *aup_gids) { struct authunix_parms aup; char mymem[MAX_AUTH_BYTES]; @@ -184,15 +179,15 @@ authunix_create(machname, uid, gid, len, aup_gids) * syscalls. */ AUTH * -authunix_create_default() +authunix_create_default(void) { AUTH *auth; int ngids; long ngids_max; char machname[MAXHOSTNAMELEN + 1]; - u_int uid; - u_int gid; - u_int *gids; + uid_t uid; + gid_t gid; + gid_t *gids; ngids_max = sysconf(_SC_NGROUPS_MAX) + 1; gids = malloc(sizeof(gid_t) * ngids_max); @@ -220,16 +215,13 @@ authunix_create_default() /* ARGSUSED */ static void -authunix_nextverf(auth) - AUTH *auth; +authunix_nextverf(AUTH *auth) { /* no action necessary */ } static bool_t -authunix_marshal(auth, xdrs) - AUTH *auth; - XDR *xdrs; +authunix_marshal(AUTH *auth, XDR *xdrs) { struct audata *au; @@ -241,9 +233,7 @@ authunix_marshal(auth, xdrs) } static bool_t -authunix_validate(auth, verf) - AUTH *auth; - struct opaque_auth *verf; +authunix_validate(AUTH *auth, struct opaque_auth *verf) { struct audata *au; XDR xdrs; @@ -319,8 +309,7 @@ done: } static void -authunix_destroy(auth) - AUTH *auth; +authunix_destroy(AUTH *auth) { struct audata *au; @@ -345,8 +334,7 @@ authunix_destroy(auth) * sets private data, au_marshed and au_mpos */ static void -marshal_new_auth(auth) - AUTH *auth; +marshal_new_auth(AUTH *auth) { XDR xdr_stream; XDR *xdrs = &xdr_stream; @@ -365,7 +353,7 @@ marshal_new_auth(auth) } static struct auth_ops * -authunix_ops() +authunix_ops(void) { static struct auth_ops ops; diff --git a/freebsd/lib/libc/rpc/authdes_prot.c b/freebsd/lib/libc/rpc/authdes_prot.c index af77afdd..dd28c049 100644 --- a/freebsd/lib/libc/rpc/authdes_prot.c +++ b/freebsd/lib/libc/rpc/authdes_prot.c @@ -51,9 +51,7 @@ __FBSDID("$FreeBSD$"); #define ATTEMPT(xdr_op) if (!(xdr_op)) return (FALSE) bool_t -xdr_authdes_cred(xdrs, cred) - XDR *xdrs; - struct authdes_cred *cred; +xdr_authdes_cred(XDR *xdrs, struct authdes_cred *cred) { enum authdes_namekind *padc_namekind = &cred->adc_namekind; /* @@ -80,9 +78,7 @@ xdr_authdes_cred(xdrs, cred) bool_t -xdr_authdes_verf(xdrs, verf) - XDR *xdrs; - struct authdes_verf *verf; +xdr_authdes_verf(XDR *xdrs, struct authdes_verf *verf) { /* * Unrolled xdr diff --git a/freebsd/lib/libc/rpc/authunix_prot.c b/freebsd/lib/libc/rpc/authunix_prot.c index e5413b2d..9eb5e8d3 100644 --- a/freebsd/lib/libc/rpc/authunix_prot.c +++ b/freebsd/lib/libc/rpc/authunix_prot.c @@ -57,9 +57,7 @@ __FBSDID("$FreeBSD$"); * XDR for unix authentication parameters. */ bool_t -xdr_authunix_parms(xdrs, p) - XDR *xdrs; - struct authunix_parms *p; +xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p) { u_int **paup_gids; diff --git a/freebsd/lib/libc/rpc/bindresvport.c b/freebsd/lib/libc/rpc/bindresvport.c index baf5cbd4..77e03568 100644 --- a/freebsd/lib/libc/rpc/bindresvport.c +++ b/freebsd/lib/libc/rpc/bindresvport.c @@ -63,9 +63,7 @@ __FBSDID("$FreeBSD$"); * Bind a socket to a privileged IP port */ int -bindresvport(sd, sin) - int sd; - struct sockaddr_in *sin; +bindresvport(int sd, struct sockaddr_in *sin) { return bindresvport_sa(sd, (struct sockaddr *)sin); } @@ -74,9 +72,7 @@ bindresvport(sd, sin) * Bind a socket to a privileged IP port */ int -bindresvport_sa(sd, sa) - int sd; - struct sockaddr *sa; +bindresvport_sa(int sd, struct sockaddr *sa) { int old, error, af; struct sockaddr_storage myaddr; diff --git a/freebsd/lib/libc/rpc/clnt_bcast.c b/freebsd/lib/libc/rpc/clnt_bcast.c index 3a12c1e9..d17e9166 100644 --- a/freebsd/lib/libc/rpc/clnt_bcast.c +++ b/freebsd/lib/libc/rpc/clnt_bcast.c @@ -227,21 +227,26 @@ __rpc_broadenable(int af, int s, struct broadif *bip) return 0; } - +/* + * rpc_broadcast_exp() + * + * prog - program number + * vers - version number + * proc - procedure number + * xargs - xdr routine for args + * argsp - pointer to args + * xresults - xdr routine for results + * resultsp - pointer to results + * eachresult - call with each result obtained + * inittime - how long to wait initially + * waittime - maximum time to wait + * nettype - transport type + */ enum clnt_stat -rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, - eachresult, inittime, waittime, nettype) - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - caddr_t argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ - int inittime; /* how long to wait initially */ - int waittime; /* maximum time to wait */ - const char *nettype; /* transport type */ +rpc_broadcast_exp(rpcprog_t prog, rpcvers_t vers, rpcproc_t proc, + xdrproc_t xargs, caddr_t argsp, xdrproc_t xresults, caddr_t resultsp, + resultproc_t eachresult, int inittime, int waittime, + const char *nettype) { enum clnt_stat stat = RPC_SUCCESS; /* Return status */ XDR xdr_stream; /* XDR stream */ @@ -253,7 +258,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, int inlen; u_int maxbufsize = 0; AUTH *sys_auth = authunix_create_default(); - int i; + u_int i; void *handle; char uaddress[1024]; /* A self imposed limit */ char *uaddrp = uaddress; @@ -343,7 +348,8 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, #ifdef PORTMAP if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) { udpbufsz = fdlist[fdlistno].dsize; - if ((outbuf_pmap = malloc(udpbufsz)) == NULL) { + outbuf_pmap = reallocf(outbuf_pmap, udpbufsz); + if (outbuf_pmap == NULL) { _close(fd); stat = RPC_SYSTEMERROR; goto done_broad; @@ -466,7 +472,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, "broadcast packet"); stat = RPC_CANTSEND; continue; - }; + } #ifdef RPC_DEBUG if (!__rpc_lowvers) fprintf(stderr, "Broadcast packet sent " @@ -633,13 +639,10 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, } /* The giant for loop */ done_broad: - if (inbuf) - (void) free(inbuf); - if (outbuf) - (void) free(outbuf); + free(inbuf); + free(outbuf); #ifdef PORTMAP - if (outbuf_pmap) - (void) free(outbuf_pmap); + free(outbuf_pmap); #endif /* PORTMAP */ for (i = 0; i < fdlistno; i++) { (void)_close(fdlist[i].fd); @@ -651,19 +654,23 @@ done_broad: return (stat); } - +/* + * rpc_broadcast() + * + * prog - program number + * vers - version number + * proc - procedure number + * xargs - xdr routine for args + * argsp - pointer to args + * xresults - xdr routine for results + * resultsp - pointer to results + * eachresult - call with each result obtained + * nettype - transport type + */ enum clnt_stat -rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, - eachresult, nettype) - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - caddr_t argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ - const char *nettype; /* transport type */ +rpc_broadcast(rpcprog_t prog, rpcvers_t vers, rpcproc_t proc, xdrproc_t xargs, + caddr_t argsp, xdrproc_t xresults, caddr_t resultsp, + resultproc_t eachresult, const char *nettype) { enum clnt_stat dummy; diff --git a/freebsd/lib/libc/rpc/clnt_dg.c b/freebsd/lib/libc/rpc/clnt_dg.c index c3694337..0c6db42d 100644 --- a/freebsd/lib/libc/rpc/clnt_dg.c +++ b/freebsd/lib/libc/rpc/clnt_dg.c @@ -155,15 +155,17 @@ struct cu_data { * If they are 0, use the transport default. * * If svcaddr is NULL, returns NULL. + * + * fd - open file descriptor + * svcaddr - servers address + * program - program number + * version - version number + * sendsz - buffer recv size + * recvsz - buffer send size */ CLIENT * -clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz) - int fd; /* open file descriptor */ - const struct netbuf *svcaddr; /* servers address */ - rpcprog_t program; /* program number */ - rpcvers_t version; /* version number */ - u_int sendsz; /* buffer recv size */ - u_int recvsz; /* buffer send size */ +clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program, + rpcvers_t version, u_int sendsz, u_int recvsz) { CLIENT *cl = NULL; /* client handle */ struct cu_data *cu = NULL; /* private data */ @@ -303,15 +305,18 @@ err2: return (NULL); } +/* + * cl - client handle + * proc - procedure number + * xargs - xdr routine for args + * argsp - pointer to args + * xresults - xdr routine for results + * resultsp - pointer to results + * utimeout - seconds to wait before giving up + */ static enum clnt_stat -clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout) - CLIENT *cl; /* client handle */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - void *argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - void *resultsp; /* pointer to results */ - struct timeval utimeout; /* seconds to wait before giving up */ +clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp, + xdrproc_t xresults, void *resultsp, struct timeval utimeout) { struct cu_data *cu = (struct cu_data *)cl->cl_private; XDR *xdrs; @@ -329,7 +334,7 @@ clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout) struct sockaddr *sa; sigset_t mask; sigset_t newmask; - socklen_t inlen, salen; + socklen_t salen; ssize_t recvlen = 0; int kin_len, n, rpc_lock_value; u_int32_t xid; @@ -522,7 +527,6 @@ get_reply: goto call_again_same_xid; } } - inlen = (socklen_t)recvlen; /* * now decode and validate the response @@ -580,7 +584,7 @@ get_reply: } } /* end successful completion */ /* - * If unsuccesful AND error is an authentication error + * If unsuccessful AND error is an authentication error * then refresh credentials and try again, else break */ else if (cu->cu_error.re_status == RPC_AUTHERROR) @@ -605,9 +609,7 @@ out: } static void -clnt_dg_geterr(cl, errp) - CLIENT *cl; - struct rpc_err *errp; +clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp) { struct cu_data *cu = (struct cu_data *)cl->cl_private; @@ -615,10 +617,7 @@ clnt_dg_geterr(cl, errp) } static bool_t -clnt_dg_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - void *res_ptr; +clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr) { struct cu_data *cu = (struct cu_data *)cl->cl_private; XDR *xdrs = &(cu->cu_outxdrs); @@ -641,16 +640,12 @@ clnt_dg_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_dg_abort(h) - CLIENT *h; +clnt_dg_abort(CLIENT *h) { } static bool_t -clnt_dg_control(cl, request, info) - CLIENT *cl; - u_int request; - void *info; +clnt_dg_control(CLIENT *cl, u_int request, void *info) { struct cu_data *cu = (struct cu_data *)cl->cl_private; struct netbuf *addr; @@ -749,7 +744,7 @@ clnt_dg_control(cl, request, info) /* * This RELIES on the information that, in the call body, * the version number field is the fifth field from the - * begining of the RPC header. MUST be changed if the + * beginning of the RPC header. MUST be changed if the * call_struct is changed */ *(u_int32_t *)info = @@ -766,7 +761,7 @@ clnt_dg_control(cl, request, info) /* * This RELIES on the information that, in the call body, * the program number field is the fourth field from the - * begining of the RPC header. MUST be changed if the + * beginning of the RPC header. MUST be changed if the * call_struct is changed */ *(u_int32_t *)info = @@ -793,8 +788,7 @@ clnt_dg_control(cl, request, info) } static void -clnt_dg_destroy(cl) - CLIENT *cl; +clnt_dg_destroy(CLIENT *cl) { struct cu_data *cu = (struct cu_data *)cl->cl_private; int cu_fd = cu->cu_fd; @@ -823,7 +817,7 @@ clnt_dg_destroy(cl) } static struct clnt_ops * -clnt_dg_ops() +clnt_dg_ops(void) { static struct clnt_ops ops; sigset_t mask; @@ -851,8 +845,7 @@ clnt_dg_ops() * Make sure that the time is not garbage. -1 value is allowed. */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { return (t->tv_sec < -1 || t->tv_sec > 100000000 || t->tv_usec < -1 || t->tv_usec > 1000000); diff --git a/freebsd/lib/libc/rpc/clnt_generic.c b/freebsd/lib/libc/rpc/clnt_generic.c index cca7f3e3..1f9960d2 100644 --- a/freebsd/lib/libc/rpc/clnt_generic.c +++ b/freebsd/lib/libc/rpc/clnt_generic.c @@ -404,7 +404,7 @@ clnt_tli_create(int fd, const struct netconfig *nconf, if (madefd) { (void) CLNT_CONTROL(cl, CLSET_FD_CLOSE, NULL); /* (void) CLNT_CONTROL(cl, CLSET_POP_TIMOD, NULL); */ - }; + } return (cl); diff --git a/freebsd/lib/libc/rpc/clnt_perror.c b/freebsd/lib/libc/rpc/clnt_perror.c index 56155728..1dda69bc 100644 --- a/freebsd/lib/libc/rpc/clnt_perror.c +++ b/freebsd/lib/libc/rpc/clnt_perror.c @@ -63,11 +63,11 @@ static char *auth_errmsg(enum auth_stat); #define CLNT_PERROR_BUFLEN 256 static char * -_buf() +_buf(void) { - if (buf == 0) - buf = (char *)malloc(CLNT_PERROR_BUFLEN); + if (buf == NULL) + buf = malloc(CLNT_PERROR_BUFLEN); return (buf); } @@ -75,9 +75,7 @@ _buf() * Print reply error info */ char * -clnt_sperror(rpch, s) - CLIENT *rpch; - const char *s; +clnt_sperror(CLIENT *rpch, const char *s) { struct rpc_err e; char *err; @@ -89,7 +87,7 @@ clnt_sperror(rpch, s) assert(s != NULL); str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */ - if (str == 0) + if (str == NULL) return (0); len = CLNT_PERROR_BUFLEN; strstart = str; @@ -182,9 +180,7 @@ clnt_sperror(rpch, s) } void -clnt_perror(rpch, s) - CLIENT *rpch; - const char *s; +clnt_perror(CLIENT *rpch, const char *s) { assert(rpch != NULL); @@ -219,8 +215,7 @@ static const char *const rpc_errlist[] = { * This interface for use by clntrpc */ char * -clnt_sperrno(stat) - enum clnt_stat stat; +clnt_sperrno(enum clnt_stat stat) { unsigned int errnum = stat; @@ -232,16 +227,14 @@ clnt_sperrno(stat) } void -clnt_perrno(num) - enum clnt_stat num; +clnt_perrno(enum clnt_stat num) { (void) fprintf(stderr, "%s\n", clnt_sperrno(num)); } char * -clnt_spcreateerror(s) - const char *s; +clnt_spcreateerror(const char *s) { char *str; size_t len, i; @@ -249,7 +242,7 @@ clnt_spcreateerror(s) assert(s != NULL); str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */ - if (str == 0) + if (str == NULL) return(0); len = CLNT_PERROR_BUFLEN; i = snprintf(str, len, "%s: ", s); @@ -293,8 +286,7 @@ clnt_spcreateerror(s) } void -clnt_pcreateerror(s) - const char *s; +clnt_pcreateerror(const char *s) { assert(s != NULL); @@ -321,8 +313,7 @@ static const char *const auth_errlist[] = { }; static char * -auth_errmsg(stat) - enum auth_stat stat; +auth_errmsg(enum auth_stat stat) { unsigned int errnum = stat; diff --git a/freebsd/lib/libc/rpc/clnt_raw.c b/freebsd/lib/libc/rpc/clnt_raw.c index ec130c14..f2f18b33 100644 --- a/freebsd/lib/libc/rpc/clnt_raw.c +++ b/freebsd/lib/libc/rpc/clnt_raw.c @@ -89,9 +89,7 @@ static struct clnt_ops *clnt_raw_ops(void); * Create a client handle for memory based rpc. */ CLIENT * -clnt_raw_create(prog, vers) - rpcprog_t prog; - rpcvers_t vers; +clnt_raw_create(rpcprog_t prog, rpcvers_t vers) { struct clntraw_private *clp; struct rpc_msg call_msg; @@ -144,14 +142,8 @@ clnt_raw_create(prog, vers) /* ARGSUSED */ static enum clnt_stat -clnt_raw_call(h, proc, xargs, argsp, xresults, resultsp, timeout) - CLIENT *h; - rpcproc_t proc; - xdrproc_t xargs; - void *argsp; - xdrproc_t xresults; - void *resultsp; - struct timeval timeout; +clnt_raw_call(CLIENT *h, rpcproc_t proc, xdrproc_t xargs, void *argsp, + xdrproc_t xresults, void *resultsp, struct timeval timeout) { struct clntraw_private *clp = clntraw_private; XDR *xdrs = &clp->xdr_stream; @@ -242,19 +234,14 @@ call_again: /*ARGSUSED*/ static void -clnt_raw_geterr(cl, err) - CLIENT *cl; - struct rpc_err *err; +clnt_raw_geterr(CLIENT *cl, struct rpc_err *err) { } /* ARGSUSED */ static bool_t -clnt_raw_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - void *res_ptr; +clnt_raw_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr) { struct clntraw_private *clp = clntraw_private; XDR *xdrs = &clp->xdr_stream; @@ -273,30 +260,25 @@ clnt_raw_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_raw_abort(cl) - CLIENT *cl; +clnt_raw_abort(CLIENT *cl) { } /*ARGSUSED*/ static bool_t -clnt_raw_control(cl, ui, str) - CLIENT *cl; - u_int ui; - void *str; +clnt_raw_control(CLIENT *cl, u_int ui, void *str) { return (FALSE); } /*ARGSUSED*/ static void -clnt_raw_destroy(cl) - CLIENT *cl; +clnt_raw_destroy(CLIENT *cl) { } static struct clnt_ops * -clnt_raw_ops() +clnt_raw_ops(void) { static struct clnt_ops ops; diff --git a/freebsd/lib/libc/rpc/clnt_simple.c b/freebsd/lib/libc/rpc/clnt_simple.c index 56d76b8a..491172cf 100644 --- a/freebsd/lib/libc/rpc/clnt_simple.c +++ b/freebsd/lib/libc/rpc/clnt_simple.c @@ -109,17 +109,19 @@ rpc_call_key_init(void) * the future calls to same prog, vers, host and nettype combination. * * The total time available is 25 seconds. + * + * host - host name + * prognum - program number + * versnum - version number + * procnum - procedure number + * inproc, outproc - in/out XDR procedures + * in, out - recv/send data + * nettype - nettype */ enum clnt_stat -rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype) - const char *host; /* host name */ - rpcprog_t prognum; /* program number */ - rpcvers_t versnum; /* version number */ - rpcproc_t procnum; /* procedure number */ - xdrproc_t inproc, outproc; /* in/out XDR procedures */ - const char *in; - char *out; /* recv/send data */ - const char *nettype; /* nettype */ +rpc_call(const char *host, const rpcprog_t prognum, const rpcvers_t versnum, + const rpcproc_t procnum, const xdrproc_t inproc, const char *in, + const xdrproc_t outproc, char *out, const char *nettype) { struct rpc_call_private *rcp = (struct rpc_call_private *) 0; enum clnt_stat clnt_stat; diff --git a/freebsd/lib/libc/rpc/clnt_vc.c b/freebsd/lib/libc/rpc/clnt_vc.c index 6c34cccc..8dc3de48 100644 --- a/freebsd/lib/libc/rpc/clnt_vc.c +++ b/freebsd/lib/libc/rpc/clnt_vc.c @@ -143,7 +143,6 @@ static cond_t *vc_cv; static const char clnt_vc_errstr[] = "%s : %s"; static const char clnt_vc_str[] = "clnt_vc_create"; -static const char clnt_read_vc_str[] = "read_vc"; static const char __no_mem_str[] = "out of memory"; /* @@ -156,15 +155,17 @@ static const char __no_mem_str[] = "out of memory"; * set this something more useful. * * fd should be an open socket + * + * fd - open file descriptor + * raddr - servers address + * prog - program number + * vers - version number + * sendsz - buffer send size + * recvsz - buffer recv size */ CLIENT * -clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz) - int fd; /* open file descriptor */ - const struct netbuf *raddr; /* servers address */ - const rpcprog_t prog; /* program number */ - const rpcvers_t vers; /* version number */ - u_int sendsz; /* buffer recv size */ - u_int recvsz; /* buffer send size */ +clnt_vc_create(int fd, const struct netbuf *raddr, const rpcprog_t prog, + const rpcvers_t vers, u_int sendsz, u_int recvsz) { CLIENT *cl; /* client handle */ struct ct_data *ct = NULL; /* client handle */ @@ -261,7 +262,7 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz) if (ct->ct_addr.buf == NULL) goto err; memcpy(ct->ct_addr.buf, raddr->buf, raddr->len); - ct->ct_addr.len = raddr->maxlen; + ct->ct_addr.len = raddr->len; ct->ct_addr.maxlen = raddr->maxlen; /* @@ -314,14 +315,8 @@ err: } static enum clnt_stat -clnt_vc_call(cl, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout) - CLIENT *cl; - rpcproc_t proc; - xdrproc_t xdr_args; - void *args_ptr; - xdrproc_t xdr_results; - void *results_ptr; - struct timeval timeout; +clnt_vc_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xdr_args, void *args_ptr, + xdrproc_t xdr_results, void *results_ptr, struct timeval timeout) { struct ct_data *ct = (struct ct_data *) cl->cl_private; XDR *xdrs = &(ct->ct_xdrs); @@ -464,9 +459,7 @@ call_again: } static void -clnt_vc_geterr(cl, errp) - CLIENT *cl; - struct rpc_err *errp; +clnt_vc_geterr(CLIENT *cl, struct rpc_err *errp) { struct ct_data *ct; @@ -478,10 +471,7 @@ clnt_vc_geterr(cl, errp) } static bool_t -clnt_vc_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - void *res_ptr; +clnt_vc_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr) { struct ct_data *ct; XDR *xdrs; @@ -510,16 +500,26 @@ clnt_vc_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_vc_abort(cl) - CLIENT *cl; +clnt_vc_abort(CLIENT *cl) +{ +} + +static __inline void +htonlp(void *dst, const void *src, uint32_t incr) +{ + /* We are aligned, so we think */ + *(uint32_t *)dst = htonl(*(const uint32_t *)src + incr); +} + +static __inline void +ntohlp(void *dst, const void *src) { + /* We are aligned, so we think */ + *(uint32_t *)dst = htonl(*(const uint32_t *)src); } static bool_t -clnt_vc_control(cl, request, info) - CLIENT *cl; - u_int request; - void *info; +clnt_vc_control(CLIENT *cl, u_int request, void *info) { struct ct_data *ct; void *infop = info; @@ -592,49 +592,39 @@ clnt_vc_control(cl, request, info) * first element in the call structure * This will get the xid of the PREVIOUS call */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)&ct->ct_u.ct_mcalli); + ntohlp(info, &ct->ct_u.ct_mcalli); break; case CLSET_XID: /* This will set the xid of the NEXT call */ - *(u_int32_t *)(void *)&ct->ct_u.ct_mcalli = - htonl(*((u_int32_t *)info) + 1); /* increment by 1 as clnt_vc_call() decrements once */ + htonlp(&ct->ct_u.ct_mcalli, info, 1); break; case CLGET_VERS: /* * This RELIES on the information that, in the call body, * the version number field is the fifth field from the - * begining of the RPC header. MUST be changed if the + * beginning of the RPC header. MUST be changed if the * call_struct is changed */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 4 * BYTES_PER_XDR_UNIT)); + ntohlp(info, ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT); break; case CLSET_VERS: - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 4 * BYTES_PER_XDR_UNIT) = - htonl(*(u_int32_t *)info); + htonlp(ct->ct_u.ct_mcallc + 4 * BYTES_PER_XDR_UNIT, info, 0); break; case CLGET_PROG: /* * This RELIES on the information that, in the call body, * the program number field is the fourth field from the - * begining of the RPC header. MUST be changed if the + * beginning of the RPC header. MUST be changed if the * call_struct is changed */ - *(u_int32_t *)info = - ntohl(*(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 3 * BYTES_PER_XDR_UNIT)); + ntohlp(info, ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT); break; case CLSET_PROG: - *(u_int32_t *)(void *)(ct->ct_u.ct_mcallc + - 3 * BYTES_PER_XDR_UNIT) = - htonl(*(u_int32_t *)info); + htonlp(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT, info, 0); break; default: @@ -647,8 +637,7 @@ clnt_vc_control(cl, request, info) static void -clnt_vc_destroy(cl) - CLIENT *cl; +clnt_vc_destroy(CLIENT *cl) { struct ct_data *ct = (struct ct_data *) cl->cl_private; int ct_fd = ct->ct_fd; @@ -668,8 +657,7 @@ clnt_vc_destroy(cl) (void)_close(ct->ct_fd); } XDR_DESTROY(&(ct->ct_xdrs)); - if (ct->ct_addr.buf) - free(ct->ct_addr.buf); + free(ct->ct_addr.buf); mem_free(ct, sizeof(struct ct_data)); if (cl->cl_netid && cl->cl_netid[0]) mem_free(cl->cl_netid, strlen(cl->cl_netid) +1); @@ -687,10 +675,7 @@ clnt_vc_destroy(cl) * around for the rpc level. */ static int -read_vc(ctp, buf, len) - void *ctp; - void *buf; - int len; +read_vc(void *ctp, void *buf, int len) { struct sockaddr sa; socklen_t sal; @@ -744,10 +729,7 @@ read_vc(ctp, buf, len) } static int -write_vc(ctp, buf, len) - void *ctp; - void *buf; - int len; +write_vc(void *ctp, void *buf, int len) { struct sockaddr sa; socklen_t sal; @@ -778,7 +760,7 @@ write_vc(ctp, buf, len) } static struct clnt_ops * -clnt_vc_ops() +clnt_vc_ops(void) { static struct clnt_ops ops; sigset_t mask, newmask; @@ -806,18 +788,14 @@ clnt_vc_ops() * Note this is different from time_not_ok in clnt_dg.c */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { return (t->tv_sec <= -1 || t->tv_sec > 100000000 || t->tv_usec <= -1 || t->tv_usec > 1000000); } static int -__msgread(sock, buf, cnt) - int sock; - void *buf; - size_t cnt; +__msgread(int sock, void *buf, size_t cnt) { struct iovec iov[1]; struct msghdr msg; @@ -842,10 +820,7 @@ __msgread(sock, buf, cnt) } static int -__msgwrite(sock, buf, cnt) - int sock; - void *buf; - size_t cnt; +__msgwrite(int sock, void *buf, size_t cnt) { struct iovec iov[1]; struct msghdr msg; diff --git a/freebsd/lib/libc/rpc/crypt_client.c b/freebsd/lib/libc/rpc/crypt_client.c index 9ce94157..15e915ad 100644 --- a/freebsd/lib/libc/rpc/crypt_client.c +++ b/freebsd/lib/libc/rpc/crypt_client.c @@ -45,10 +45,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" int -_des_crypt_call(buf, len, dparms) - char *buf; - int len; - struct desparams *dparms; +_des_crypt_call(char *buf, int len, struct desparams *dparms) { CLIENT *clnt; desresp *result_1; @@ -66,6 +63,7 @@ _des_crypt_call(buf, len, dparms) } if (nconf == NULL) { warnx("getnetconfig: %s", nc_sperror()); + endnetconfig(localhandle); return(DESERR_HWERROR); } clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf); diff --git a/freebsd/lib/libc/rpc/des_crypt.c b/freebsd/lib/libc/rpc/des_crypt.c index b5f14f82..31763422 100644 --- a/freebsd/lib/libc/rpc/des_crypt.c +++ b/freebsd/lib/libc/rpc/des_crypt.c @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)des_crypt.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02 __FBSDID("$FreeBSD$"); static int common_crypt( char *, char *, unsigned, unsigned, struct desparams * ); -int (*__des_crypt_LOCAL)() = 0; +int (*__des_crypt_LOCAL)(char *, unsigned, struct desparams *) = 0; extern int _des_crypt_call(char *, int, struct desparams *); /* * Copy 8 bytes @@ -72,12 +72,7 @@ extern int _des_crypt_call(char *, int, struct desparams *); * CBC mode encryption */ int -cbc_crypt(key, buf, len, mode, ivec) - char *key; - char *buf; - unsigned len; - unsigned mode; - char *ivec; +cbc_crypt(char *key, char *buf, unsigned len, unsigned mode, char *ivec) { int err; struct desparams dp; @@ -99,11 +94,7 @@ cbc_crypt(key, buf, len, mode, ivec) * ECB mode encryption */ int -ecb_crypt(key, buf, len, mode) - char *key; - char *buf; - unsigned len; - unsigned mode; +ecb_crypt(char *key, char *buf, unsigned len, unsigned mode) { struct desparams dp; @@ -122,12 +113,8 @@ ecb_crypt(key, buf, len, mode) * Common code to cbc_crypt() & ecb_crypt() */ static int -common_crypt(key, buf, len, mode, desp) - char *key; - char *buf; - unsigned len; - unsigned mode; - struct desparams *desp; +common_crypt(char *key, char *buf, unsigned len, unsigned mode, + struct desparams *desp) { int desdev; diff --git a/freebsd/lib/libc/rpc/des_soft.c b/freebsd/lib/libc/rpc/des_soft.c index e67f90d8..2b6b8606 100644 --- a/freebsd/lib/libc/rpc/des_soft.c +++ b/freebsd/lib/libc/rpc/des_soft.c @@ -60,8 +60,7 @@ static char partab[128] = { * Add odd parity to low bit of 8 byte key */ void -des_setparity(p) - char *p; +des_setparity(char *p) { int i; diff --git a/freebsd/lib/libc/rpc/getnetconfig.c b/freebsd/lib/libc/rpc/getnetconfig.c index f6279e04..bc3bc7ef 100644 --- a/freebsd/lib/libc/rpc/getnetconfig.c +++ b/freebsd/lib/libc/rpc/getnetconfig.c @@ -149,7 +149,7 @@ nc_key_init(void) #define MAXNETCONFIGLINE 1000 static int * -__nc_error() +__nc_error(void) { static int nc_error = 0; int *nc_addr; @@ -166,8 +166,7 @@ __nc_error() if ((nc_addr = (int *)thr_getspecific(nc_key)) == NULL) { nc_addr = (int *)malloc(sizeof (int)); if (thr_setspecific(nc_key, (void *) nc_addr) != 0) { - if (nc_addr) - free(nc_addr); + free(nc_addr); return (&nc_error); } *nc_addr = 0; @@ -196,7 +195,7 @@ __nc_error() * the netconfig database is not present). */ void * -setnetconfig() +setnetconfig(void) { struct netconfig_vars *nc_vars; @@ -242,8 +241,7 @@ setnetconfig() */ struct netconfig * -getnetconfig(handlep) -void *handlep; +getnetconfig(void *handlep) { struct netconfig_vars *ncp = (struct netconfig_vars *)handlep; char *stringp; /* tmp string pointer */ @@ -380,8 +378,7 @@ void *handlep; * previously). */ int -endnetconfig(handlep) -void *handlep; +endnetconfig(void *handlep) { struct netconfig_vars *nc_handlep = (struct netconfig_vars *)handlep; @@ -410,7 +407,7 @@ void *handlep; } /* - * Noone needs these entries anymore, then frees them. + * No one needs these entries anymore, then frees them. * Make sure all info in netconfig_info structure has been reinitialized. */ q = ni.head; @@ -421,7 +418,7 @@ void *handlep; while (q != NULL) { p = q->next; - if (q->ncp->nc_lookups != NULL) free(q->ncp->nc_lookups); + free(q->ncp->nc_lookups); free(q->ncp); free(q->linep); free(q); @@ -446,8 +443,7 @@ void *handlep; */ struct netconfig * -getnetconfigent(netid) - const char *netid; +getnetconfigent(const char *netid) { FILE *file; /* NETCONFIG db's file pointer */ char *linep; /* holds current netconfig line */ @@ -538,13 +534,11 @@ getnetconfigent(netid) */ void -freenetconfigent(netconfigp) - struct netconfig *netconfigp; +freenetconfigent(struct netconfig *netconfigp) { if (netconfigp != NULL) { free(netconfigp->nc_netid); /* holds all netconfigp's strings */ - if (netconfigp->nc_lookups != NULL) - free(netconfigp->nc_lookups); + free(netconfigp->nc_lookups); free(netconfigp); } return; @@ -560,12 +554,13 @@ freenetconfigent(netconfigp) * Note that we modify stringp (putting NULLs after tokens) and * we set the ncp's string field pointers to point to these tokens within * stringp. + * + * stringp - string to parse + * ncp - where to put results */ static int -parse_ncp(stringp, ncp) -char *stringp; /* string to parse */ -struct netconfig *ncp; /* where to put results */ +parse_ncp(char *stringp, struct netconfig *ncp) { char *tokenp; /* for processing tokens */ char *lasts; @@ -633,8 +628,7 @@ struct netconfig *ncp; /* where to put results */ } else { char *cp; /* tmp string */ - if (ncp->nc_lookups != NULL) /* from last visit */ - free(ncp->nc_lookups); + free(ncp->nc_lookups); /* from last visit */ ncp->nc_lookups = NULL; ncp->nc_nlookups = 0; while ((cp = tokenp) != NULL) { @@ -657,7 +651,7 @@ struct netconfig *ncp; /* where to put results */ * Returns a string describing the reason for failure. */ char * -nc_sperror() +nc_sperror(void) { const char *message; @@ -688,8 +682,7 @@ nc_sperror() * Prints a message onto standard error describing the reason for failure. */ void -nc_perror(s) - const char *s; +nc_perror(const char *s) { fprintf(stderr, "%s: %s\n", s, nc_sperror()); } @@ -698,11 +691,10 @@ nc_perror(s) * Duplicates the matched netconfig buffer. */ static struct netconfig * -dup_ncp(ncp) -struct netconfig *ncp; +dup_ncp(struct netconfig *ncp) { struct netconfig *p; - char *tmp; + char *tmp, *tmp2; u_int i; if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL) @@ -711,6 +703,7 @@ struct netconfig *ncp; free(tmp); return(NULL); } + tmp2 = tmp; /* * First we dup all the data from matched netconfig buffer. Then we * adjust some of the member pointer to a pre-allocated buffer where @@ -732,6 +725,7 @@ struct netconfig *ncp; if (p->nc_lookups == NULL) { free(p->nc_netid); free(p); + free(tmp2); return(NULL); } for (i=0; i < p->nc_nlookups; i++) { diff --git a/freebsd/lib/libc/rpc/getnetpath.c b/freebsd/lib/libc/rpc/getnetpath.c index 56493557..12def71b 100644 --- a/freebsd/lib/libc/rpc/getnetpath.c +++ b/freebsd/lib/libc/rpc/getnetpath.c @@ -84,7 +84,7 @@ char *_get_next_token(char *, int); */ void * -setnetpath() +setnetpath(void) { struct netpath_vars *np_sessionp; /* this session's variables */ @@ -99,9 +99,8 @@ setnetpath() return (NULL); } if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) { - free(np_sessionp); syslog (LOG_ERR, "rpc: failed to open " NETCONFIG); - return (NULL); + goto failed; } np_sessionp->valid = NP_VALID; np_sessionp->ncp_list = NULL; @@ -144,8 +143,7 @@ failed: */ struct netconfig * -getnetpath(handlep) - void *handlep; +getnetpath(void *handlep) { struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep; struct netconfig *ncp = NULL; /* temp. holds a netconfig session */ @@ -200,8 +198,7 @@ getnetpath(handlep) * (e.g. if setnetpath() was not called previously. */ int -endnetpath(handlep) - void *handlep; +endnetpath(void *handlep) { struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep; struct netpath_chain *chainp, *lastp; @@ -234,12 +231,12 @@ endnetpath(handlep) * Returns pointer to the rest-of-the-string after the current token. * The token itself starts at arg, and we null terminate it. We return NULL * if either the arg is empty, or if this is the last token. + * + * npp - string + * token - char to parse string for */ - char * -_get_next_token(npp, token) -char *npp; /* string */ -int token; /* char to parse string for */ +_get_next_token(char *npp, int token) { char *cp; /* char pointer */ char *np; /* netpath pointer */ @@ -267,7 +264,7 @@ int token; /* char to parse string for */ *cp++ = '\0'; /* null-terminate token */ /* get rid of any backslash escapes */ ep = npp; - while ((np = strchr(ep, '\\')) != 0) { + while ((np = strchr(ep, '\\')) != NULL) { if (np[1] == '\\') np++; strcpy(np, (ep = &np[1])); /* XXX: overlapping string copy */ diff --git a/freebsd/lib/libc/rpc/getpublickey.c b/freebsd/lib/libc/rpc/getpublickey.c index d7bac7c2..0fef3d38 100644 --- a/freebsd/lib/libc/rpc/getpublickey.c +++ b/freebsd/lib/libc/rpc/getpublickey.c @@ -58,15 +58,13 @@ __FBSDID("$FreeBSD$"); /* * Hack to let ypserv/rpc.nisd use AUTH_DES. */ -int (*__getpublickey_LOCAL)() = 0; +int (*__getpublickey_LOCAL)(const char *, char *) = 0; /* * Get somebody's public key */ static int -__getpublickey_real(netname, publickey) - const char *netname; - char *publickey; +__getpublickey_real(const char *netname, char *publickey) { char lookup[3 * HEXKEYBYTES]; char *p; @@ -91,9 +89,7 @@ __getpublickey_real(netname, publickey) */ int -getpublicandprivatekey(key, ret) - const char *key; - char *ret; +getpublicandprivatekey(const char *key, char *ret) { char buf[1024]; /* big enough */ char *res; @@ -168,9 +164,7 @@ getpublicandprivatekey(key, ret) } } -int getpublickey(netname, publickey) - const char *netname; - char *publickey; +int getpublickey(const char *netname, char *publickey) { if (__getpublickey_LOCAL != NULL) return(__getpublickey_LOCAL(netname, publickey)); diff --git a/freebsd/lib/libc/rpc/getrpcent.c b/freebsd/lib/libc/rpc/getrpcent.c index b4d51e0d..bed8074c 100644 --- a/freebsd/lib/libc/rpc/getrpcent.c +++ b/freebsd/lib/libc/rpc/getrpcent.c @@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$"); */ #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <assert.h> @@ -514,6 +513,7 @@ nis_rpcent(void *retval, void *mdata, va_list ap) sizeof(char *)) { *errnop = ERANGE; rv = NS_RETURN; + free(resultbuf); break; } @@ -523,6 +523,7 @@ nis_rpcent(void *retval, void *mdata, va_list ap) if (aliases_size < 1) { *errnop = ERANGE; rv = NS_RETURN; + free(resultbuf); break; } @@ -971,7 +972,7 @@ getrpc(int (*fn)(union key, struct rpcent *, char *, size_t, struct rpcent **), } struct rpcent * -getrpcbyname(char *name) +getrpcbyname(const char *name) { union key key; @@ -991,7 +992,7 @@ getrpcbynumber(int number) } struct rpcent * -getrpcent() +getrpcent(void) { union key key; @@ -1025,7 +1026,7 @@ setrpcent(int stayopen) } void -endrpcent() +endrpcent(void) { #ifdef NS_CACHING static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( diff --git a/freebsd/lib/libc/rpc/getrpcport.c b/freebsd/lib/libc/rpc/getrpcport.c index 161486dc..26e08b93 100644 --- a/freebsd/lib/libc/rpc/getrpcport.c +++ b/freebsd/lib/libc/rpc/getrpcport.c @@ -55,9 +55,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" int -getrpcport(host, prognum, versnum, proto) - char *host; - int prognum, versnum, proto; +getrpcport(char *host, int prognum, int versnum, int proto) { struct sockaddr_in addr; struct hostent *hp; diff --git a/freebsd/lib/libc/rpc/key_call.c b/freebsd/lib/libc/rpc/key_call.c index ba2a3835..c28aa507 100644 --- a/freebsd/lib/libc/rpc/key_call.c +++ b/freebsd/lib/libc/rpc/key_call.c @@ -83,15 +83,14 @@ __FBSDID("$FreeBSD$"); * implementations of these functions, and to call those in key_call(). */ -cryptkeyres *(*__key_encryptsession_pk_LOCAL)() = 0; -cryptkeyres *(*__key_decryptsession_pk_LOCAL)() = 0; -des_block *(*__key_gendes_LOCAL)() = 0; +cryptkeyres *(*__key_encryptsession_pk_LOCAL)(uid_t, void *arg) = 0; +cryptkeyres *(*__key_decryptsession_pk_LOCAL)(uid_t, void *arg) = 0; +des_block *(*__key_gendes_LOCAL)(uid_t, void *) = 0; static int key_call( u_long, xdrproc_t, void *, xdrproc_t, void *); int -key_setsecret(secretkey) - const char *secretkey; +key_setsecret(const char *secretkey) { keystatus status; @@ -133,10 +132,7 @@ key_secretkey_is_set(void) } int -key_encryptsession_pk(remotename, remotekey, deskey) - char *remotename; - netobj *remotekey; - des_block *deskey; +key_encryptsession_pk(char *remotename, netobj *remotekey, des_block *deskey) { cryptkeyarg2 arg; cryptkeyres res; @@ -157,10 +153,7 @@ key_encryptsession_pk(remotename, remotekey, deskey) } int -key_decryptsession_pk(remotename, remotekey, deskey) - char *remotename; - netobj *remotekey; - des_block *deskey; +key_decryptsession_pk(char *remotename, netobj *remotekey, des_block *deskey) { cryptkeyarg2 arg; cryptkeyres res; @@ -181,9 +174,7 @@ key_decryptsession_pk(remotename, remotekey, deskey) } int -key_encryptsession(remotename, deskey) - const char *remotename; - des_block *deskey; +key_encryptsession(const char *remotename, des_block *deskey) { cryptkeyarg arg; cryptkeyres res; @@ -203,9 +194,7 @@ key_encryptsession(remotename, deskey) } int -key_decryptsession(remotename, deskey) - const char *remotename; - des_block *deskey; +key_decryptsession(const char *remotename, des_block *deskey) { cryptkeyarg arg; cryptkeyres res; @@ -225,8 +214,7 @@ key_decryptsession(remotename, deskey) } int -key_gendes(key) - des_block *key; +key_gendes(des_block *key) { if (!key_call((u_long)KEY_GEN, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_des_block, key)) { @@ -236,8 +224,7 @@ key_gendes(key) } int -key_setnet(arg) -struct key_netstarg *arg; +key_setnet(struct key_netstarg *arg) { keystatus status; @@ -256,9 +243,7 @@ struct key_netstarg *arg; int -key_get_conv(pkey, deskey) - char *pkey; - des_block *deskey; +key_get_conv(char *pkey, des_block *deskey) { cryptkeyres res; @@ -307,8 +292,7 @@ key_call_init(void) * Keep the handle cached. This call may be made quite often. */ static CLIENT * -getkeyserv_handle(vers) -int vers; +getkeyserv_handle(int vers) { void *localhandle; struct netconfig *nconf; @@ -431,12 +415,8 @@ int vers; /* returns 0 on failure, 1 on success */ static int -key_call(proc, xdr_arg, arg, xdr_rslt, rslt) - u_long proc; - xdrproc_t xdr_arg; - void *arg; - xdrproc_t xdr_rslt; - void *rslt; +key_call(u_long proc, xdrproc_t xdr_arg, void *arg, xdrproc_t xdr_rslt, + void *rslt) { CLIENT *clnt; struct timeval wait_time; diff --git a/freebsd/lib/libc/rpc/mt_misc.c b/freebsd/lib/libc/rpc/mt_misc.c index b494bef7..75649fd2 100644 --- a/freebsd/lib/libc/rpc/mt_misc.c +++ b/freebsd/lib/libc/rpc/mt_misc.c @@ -95,9 +95,9 @@ rce_key_init(void) } struct rpc_createerr * -__rpc_createerr() +__rpc_createerr(void) { - struct rpc_createerr *rce_addr = 0; + struct rpc_createerr *rce_addr = NULL; if (thr_main()) return (&rpc_createerr); @@ -108,8 +108,7 @@ __rpc_createerr() rce_addr = (struct rpc_createerr *) malloc(sizeof (struct rpc_createerr)); if (thr_setspecific(rce_key, (void *) rce_addr) != 0) { - if (rce_addr) - free(rce_addr); + free(rce_addr); return (&rpc_createerr); } memset(rce_addr, 0, sizeof (struct rpc_createerr)); diff --git a/freebsd/lib/libc/rpc/netname.c b/freebsd/lib/libc/rpc/netname.c index d992c05d..25439fda 100644 --- a/freebsd/lib/libc/rpc/netname.c +++ b/freebsd/lib/libc/rpc/netname.c @@ -81,8 +81,7 @@ static char *OPSYS = "unix"; * Figure out my fully qualified network name */ int -getnetname(name) - char name[MAXNETNAMELEN+1]; +getnetname(char name[MAXNETNAMELEN+1]) { uid_t uid; @@ -99,10 +98,7 @@ getnetname(name) * Convert unix cred to network-name */ int -user2netname(netname, uid, domain) - char netname[MAXNETNAMELEN + 1]; - const uid_t uid; - const char *domain; +user2netname(char netname[MAXNETNAMELEN + 1], const uid_t uid, const char *domain) { char *dfltdom; @@ -124,10 +120,7 @@ user2netname(netname, uid, domain) * Convert host to network-name */ int -host2netname(netname, host, domain) - char netname[MAXNETNAMELEN + 1]; - const char *host; - const char *domain; +host2netname(char netname[MAXNETNAMELEN + 1], const char *host, const char *domain) { char *dfltdom; char hostname[MAXHOSTNAMELEN+1]; diff --git a/freebsd/lib/libc/rpc/netnamer.c b/freebsd/lib/libc/rpc/netnamer.c index dd09c257..be154eb0 100644 --- a/freebsd/lib/libc/rpc/netnamer.c +++ b/freebsd/lib/libc/rpc/netnamer.c @@ -70,12 +70,8 @@ static int _getgroups( char *, gid_t * ); * Convert network-name into unix credential */ int -netname2user(netname, uidp, gidp, gidlenp, gidlist) - char netname[MAXNETNAMELEN + 1]; - uid_t *uidp; - gid_t *gidp; - int *gidlenp; - gid_t *gidlist; +netname2user(char netname[MAXNETNAMELEN + 1], uid_t *uidp, gid_t *gidp, + int *gidlenp, gid_t *gidlist) { char *p; int gidlen; @@ -151,9 +147,7 @@ netname2user(netname, uidp, gidp, gidlenp, gidlist) */ static int -_getgroups(uname, groups) - char *uname; - gid_t groups[NGRPS]; +_getgroups(char *uname, gid_t groups[NGRPS]) { gid_t ngroups = 0; struct group *grp; @@ -192,10 +186,7 @@ toomany: * Convert network-name to hostname */ int -netname2host(netname, hostname, hostlen) - char netname[MAXNETNAMELEN + 1]; - char *hostname; - int hostlen; +netname2host(char netname[MAXNETNAMELEN + 1], char *hostname, int hostlen) { int err; char valbuf[1024]; @@ -241,8 +232,7 @@ netname2host(netname, hostname, hostlen) * network information service. */ int -getnetid(key, ret) - char *key, *ret; +getnetid(char *key, char *ret) { char buf[1024]; /* big enough */ char *res; @@ -255,6 +245,9 @@ getnetid(key, ret) char *lookup; int len; #endif + int rv; + + rv = 0; fd = fopen(NETIDFILE, "r"); if (fd == NULL) { @@ -265,13 +258,11 @@ getnetid(key, ret) return (0); #endif } - for (;;) { - if (fd == NULL) - return (0); /* getnetidyp brings us here */ + while (fd != NULL) { res = fgets(buf, sizeof(buf), fd); if (res == NULL) { - fclose(fd); - return (0); + rv = 0; + goto done; } if (res[0] == '#') continue; @@ -294,9 +285,8 @@ getnetid(key, ret) lookup[len] = 0; strcpy(ret, lookup); free(lookup); - if (fd != NULL) - fclose(fd); - return (2); + rv = 2; + goto done; #else /* YP */ #ifdef DEBUG fprintf(stderr, @@ -322,10 +312,14 @@ getnetid(key, ret) } if (strcmp(mkey, key) == 0) { strcpy(ret, mval); - fclose(fd); - return (1); - + rv = 1; + goto done; } } } + +done: + if (fd != NULL) + fclose(fd); + return (rv); } diff --git a/freebsd/lib/libc/rpc/pmap_getmaps.c b/freebsd/lib/libc/rpc/pmap_getmaps.c index 7c35ff26..fd6c4a85 100644 --- a/freebsd/lib/libc/rpc/pmap_getmaps.c +++ b/freebsd/lib/libc/rpc/pmap_getmaps.c @@ -72,8 +72,7 @@ __FBSDID("$FreeBSD$"); * Calls the pmap service remotely to do get the maps. */ struct pmaplist * -pmap_getmaps(address) - struct sockaddr_in *address; +pmap_getmaps(struct sockaddr_in *address) { struct pmaplist *head = NULL; int sock = -1; diff --git a/freebsd/lib/libc/rpc/pmap_getport.c b/freebsd/lib/libc/rpc/pmap_getport.c index 7b6c4818..0ddfb68c 100644 --- a/freebsd/lib/libc/rpc/pmap_getport.c +++ b/freebsd/lib/libc/rpc/pmap_getport.c @@ -68,11 +68,8 @@ static const struct timeval tottimeout = { 60, 0 }; * Returns 0 if no map exists. */ u_short -pmap_getport(address, program, version, protocol) - struct sockaddr_in *address; - u_long program; - u_long version; - u_int protocol; +pmap_getport(struct sockaddr_in *address, u_long program, u_long version, + u_int protocol) { u_short port = 0; int sock = -1; diff --git a/freebsd/lib/libc/rpc/pmap_prot.c b/freebsd/lib/libc/rpc/pmap_prot.c index 121af17a..03c303eb 100644 --- a/freebsd/lib/libc/rpc/pmap_prot.c +++ b/freebsd/lib/libc/rpc/pmap_prot.c @@ -54,9 +54,7 @@ __FBSDID("$FreeBSD$"); bool_t -xdr_pmap(xdrs, regs) - XDR *xdrs; - struct pmap *regs; +xdr_pmap(XDR *xdrs, struct pmap *regs) { assert(xdrs != NULL); diff --git a/freebsd/lib/libc/rpc/pmap_prot2.c b/freebsd/lib/libc/rpc/pmap_prot2.c index 9a50dfa7..0b5134a3 100644 --- a/freebsd/lib/libc/rpc/pmap_prot2.c +++ b/freebsd/lib/libc/rpc/pmap_prot2.c @@ -92,9 +92,7 @@ __FBSDID("$FreeBSD$"); * this sounds like a job for xdr_reference! */ bool_t -xdr_pmaplist(xdrs, rp) - XDR *xdrs; - struct pmaplist **rp; +xdr_pmaplist(XDR *xdrs, struct pmaplist **rp) { /* * more_elements is pre-computed in case the direction is @@ -136,9 +134,7 @@ xdr_pmaplist(xdrs, rp) * functionality to xdr_pmaplist(). */ bool_t -xdr_pmaplist_ptr(xdrs, rp) - XDR *xdrs; - struct pmaplist *rp; +xdr_pmaplist_ptr(XDR *xdrs, struct pmaplist *rp) { return xdr_pmaplist(xdrs, (struct pmaplist **)(void *)rp); } diff --git a/freebsd/lib/libc/rpc/pmap_rmt.c b/freebsd/lib/libc/rpc/pmap_rmt.c index e2d45608..17f9d5b4 100644 --- a/freebsd/lib/libc/rpc/pmap_rmt.c +++ b/freebsd/lib/libc/rpc/pmap_rmt.c @@ -78,14 +78,9 @@ static const struct timeval timeout = { 3, 0 }; * programs to do a lookup and call in one step. */ enum clnt_stat -pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, - port_ptr) - struct sockaddr_in *addr; - u_long prog, vers, proc; - xdrproc_t xdrargs, xdrres; - caddr_t argsp, resp; - struct timeval tout; - u_long *port_ptr; +pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc, + xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp, + struct timeval tout, u_long *port_ptr) { int sock = -1; CLIENT *client; @@ -124,9 +119,7 @@ pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, * written for XDR_ENCODE direction only */ bool_t -xdr_rmtcall_args(xdrs, cap) - XDR *xdrs; - struct rmtcallargs *cap; +xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap) { u_int lenposition, argposition, position; @@ -158,9 +151,7 @@ xdr_rmtcall_args(xdrs, cap) * written for XDR_DECODE direction only */ bool_t -xdr_rmtcallres(xdrs, crp) - XDR *xdrs; - struct rmtcallres *crp; +xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp) { caddr_t port_ptr; diff --git a/freebsd/lib/libc/rpc/rpc_callmsg.c b/freebsd/lib/libc/rpc/rpc_callmsg.c index 7d236d5e..f635205c 100644 --- a/freebsd/lib/libc/rpc/rpc_callmsg.c +++ b/freebsd/lib/libc/rpc/rpc_callmsg.c @@ -56,9 +56,7 @@ __FBSDID("$FreeBSD$"); * XDR a call message */ bool_t -xdr_callmsg(xdrs, cmsg) - XDR *xdrs; - struct rpc_msg *cmsg; +xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg) { enum msg_type *prm_direction; int32_t *buf; @@ -197,11 +195,11 @@ xdr_callmsg(xdrs, cmsg) xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && xdr_enum(xdrs, (enum_t *) prm_direction) && (cmsg->rm_direction == CALL) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && + xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog)) && + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_vers)) && + xdr_rpcproc(xdrs, &(cmsg->rm_call.cb_proc)) && xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); return (FALSE); diff --git a/freebsd/lib/libc/rpc/rpc_com.h b/freebsd/lib/libc/rpc/rpc_com.h index 770faf91..bfa6a0bc 100644 --- a/freebsd/lib/libc/rpc/rpc_com.h +++ b/freebsd/lib/libc/rpc/rpc_com.h @@ -86,8 +86,8 @@ bool_t __xdrrec_setnonblock(XDR *, int); bool_t __xdrrec_getrec(XDR *, enum xprt_stat *, bool_t); void __xprt_unregister_unlocked(SVCXPRT *); -SVCXPRT **__svc_xports; -int __svc_maxrec; +extern SVCXPRT **__svc_xports; +extern int __svc_maxrec; __END_DECLS diff --git a/freebsd/lib/libc/rpc/rpc_generic.c b/freebsd/lib/libc/rpc/rpc_generic.c index d58bbfc0..8471fd7c 100644 --- a/freebsd/lib/libc/rpc/rpc_generic.c +++ b/freebsd/lib/libc/rpc/rpc_generic.c @@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include "reentrant.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/socket.h> #include <sys/time.h> @@ -113,7 +112,7 @@ static int getnettype(const char *); * expensive call every time. */ int -__rpc_dtbsize() +__rpc_dtbsize(void) { static int tbsize; struct rlimit rl; @@ -134,12 +133,12 @@ __rpc_dtbsize() /* * Find the appropriate buffer size + * + * size - Size requested */ u_int /*ARGSUSED*/ -__rpc_get_t_size(af, proto, size) - int af, proto; - int size; /* Size requested */ +__rpc_get_t_size(int af, int proto, int size) { int maxsize, defsize; @@ -166,8 +165,7 @@ __rpc_get_t_size(af, proto, size) * Find the appropriate address buffer size */ u_int -__rpc_get_a_size(af) - int af; +__rpc_get_a_size(int af) { switch (af) { case AF_INET: @@ -186,8 +184,7 @@ __rpc_get_a_size(af) #if 0 static char * -strlocase(p) - char *p; +strlocase(char *p) { char *t = p; @@ -203,8 +200,7 @@ strlocase(p) * If nettype is NULL, it defaults to NETPATH. */ static int -getnettype(nettype) - const char *nettype; +getnettype(const char *nettype) { int i; @@ -239,8 +235,7 @@ keys_init(void) * This should be freed by calling freenetconfigent() */ struct netconfig * -__rpc_getconfip(nettype) - const char *nettype; +__rpc_getconfip(const char *nettype) { char *netid; char *netid_tcp = (char *) NULL; @@ -311,8 +306,7 @@ __rpc_getconfip(nettype) * __rpc_getconf(). */ void * -__rpc_setconf(nettype) - const char *nettype; +__rpc_setconf(const char *nettype) { struct handle *handle; @@ -355,8 +349,7 @@ failed: * __rpc_setconf() should have been called previously. */ struct netconfig * -__rpc_getconf(vhandle) - void *vhandle; +__rpc_getconf(void *vhandle) { struct handle *handle; struct netconfig *nconf; @@ -432,8 +425,7 @@ __rpc_getconf(vhandle) } void -__rpc_endconf(vhandle) - void * vhandle; +__rpc_endconf(void *vhandle) { struct handle *handle; @@ -454,8 +446,7 @@ __rpc_endconf(vhandle) * Returns NULL if fails, else a non-NULL pointer. */ void * -rpc_nullproc(clnt) - CLIENT *clnt; +rpc_nullproc(CLIENT *clnt) { struct timeval TIMEOUT = {25, 0}; @@ -471,8 +462,7 @@ rpc_nullproc(clnt) * one succeeds in finding the netconf for the given fd. */ struct netconfig * -__rpcgettp(fd) - int fd; +__rpcgettp(int fd) { const char *netid; struct __rpc_sockinfo si; diff --git a/freebsd/lib/libc/rpc/rpc_prot.c b/freebsd/lib/libc/rpc/rpc_prot.c index 754f7cb9..d943ceaf 100644 --- a/freebsd/lib/libc/rpc/rpc_prot.c +++ b/freebsd/lib/libc/rpc/rpc_prot.c @@ -70,9 +70,7 @@ extern struct opaque_auth _null_auth; * (see auth.h) */ bool_t -xdr_opaque_auth(xdrs, ap) - XDR *xdrs; - struct opaque_auth *ap; +xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap) { assert(xdrs != NULL); @@ -88,9 +86,7 @@ xdr_opaque_auth(xdrs, ap) * XDR a DES block */ bool_t -xdr_des_block(xdrs, blkp) - XDR *xdrs; - des_block *blkp; +xdr_des_block(XDR *xdrs, des_block *blkp) { assert(xdrs != NULL); @@ -105,9 +101,7 @@ xdr_des_block(xdrs, blkp) * XDR the MSG_ACCEPTED part of a reply message union */ bool_t -xdr_accepted_reply(xdrs, ar) - XDR *xdrs; - struct accepted_reply *ar; +xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar) { enum accept_stat *par_stat; @@ -127,9 +121,9 @@ xdr_accepted_reply(xdrs, ar) return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where)); case PROG_MISMATCH: - if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low))) + if (!xdr_rpcvers(xdrs, &(ar->ar_vers.low))) return (FALSE); - return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high))); + return (xdr_rpcvers(xdrs, &(ar->ar_vers.high))); case GARBAGE_ARGS: case SYSTEM_ERR: @@ -144,9 +138,7 @@ xdr_accepted_reply(xdrs, ar) * XDR the MSG_DENIED part of a reply message union */ bool_t -xdr_rejected_reply(xdrs, rr) - XDR *xdrs; - struct rejected_reply *rr; +xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr) { enum reject_stat *prj_stat; enum auth_stat *prj_why; @@ -162,9 +154,9 @@ xdr_rejected_reply(xdrs, rr) switch (rr->rj_stat) { case RPC_MISMATCH: - if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low))) + if (! xdr_rpcvers(xdrs, &(rr->rj_vers.low))) return (FALSE); - return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high))); + return (xdr_rpcvers(xdrs, &(rr->rj_vers.high))); case AUTH_ERROR: prj_why = &rr->rj_why; @@ -184,9 +176,7 @@ static const struct xdr_discrim reply_dscrm[3] = { * XDR a reply message */ bool_t -xdr_replymsg(xdrs, rmsg) - XDR *xdrs; - struct rpc_msg *rmsg; +xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg) { enum msg_type *prm_direction; enum reply_stat *prp_stat; @@ -214,9 +204,7 @@ xdr_replymsg(xdrs, rmsg) * The rm_xid is not really static, but the user can easily munge on the fly. */ bool_t -xdr_callhdr(xdrs, cmsg) - XDR *xdrs; - struct rpc_msg *cmsg; +xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg) { enum msg_type *prm_direction; @@ -231,8 +219,8 @@ xdr_callhdr(xdrs, cmsg) (xdrs->x_op == XDR_ENCODE) && xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && xdr_enum(xdrs, (enum_t *) prm_direction) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && - xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) ) + xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && + xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog)) ) return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers))); return (FALSE); } @@ -240,9 +228,7 @@ xdr_callhdr(xdrs, cmsg) /* ************************** Client utility routine ************* */ static void -accepted(acpt_stat, error) - enum accept_stat acpt_stat; - struct rpc_err *error; +accepted(enum accept_stat acpt_stat, struct rpc_err *error) { assert(error != NULL); @@ -281,9 +267,7 @@ accepted(acpt_stat, error) } static void -rejected(rjct_stat, error) - enum reject_stat rjct_stat; - struct rpc_err *error; +rejected(enum reject_stat rjct_stat, struct rpc_err *error) { assert(error != NULL); @@ -308,9 +292,7 @@ rejected(rjct_stat, error) * given a reply message, fills in the error */ void -_seterr_reply(msg, error) - struct rpc_msg *msg; - struct rpc_err *error; +_seterr_reply(struct rpc_msg *msg, struct rpc_err *error) { assert(msg != NULL); diff --git a/freebsd/lib/libc/rpc/rpc_soc.c b/freebsd/lib/libc/rpc/rpc_soc.c index 6b4260c4..d5b5be3a 100644 --- a/freebsd/lib/libc/rpc/rpc_soc.c +++ b/freebsd/lib/libc/rpc/rpc_soc.c @@ -90,14 +90,8 @@ static bool_t rpc_wrap_bcast(char *, struct netbuf *, struct netconfig *); * A common clnt create routine */ static CLIENT * -clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp) - struct sockaddr_in *raddr; - rpcprog_t prog; - rpcvers_t vers; - int *sockp; - u_int sendsz; - u_int recvsz; - char *tp; +clnt_com_create(struct sockaddr_in *raddr, rpcprog_t prog, rpcvers_t vers, int *sockp, + u_int sendsz, u_int recvsz, char *tp) { CLIENT *cl; int madefd = FALSE; @@ -166,14 +160,8 @@ err: if (madefd == TRUE) } CLIENT * -clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - struct timeval wait; - int *sockp; - u_int sendsz; - u_int recvsz; +clntudp_bufcreate(struct sockaddr_in *raddr, u_long prog, u_long vers, + struct timeval wait, int *sockp, u_int sendsz, u_int recvsz) { CLIENT *cl; @@ -187,12 +175,8 @@ clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) } CLIENT * -clntudp_create(raddr, program, version, wait, sockp) - struct sockaddr_in *raddr; - u_long program; - u_long version; - struct timeval wait; - int *sockp; +clntudp_create(struct sockaddr_in *raddr, u_long program, u_long version, + struct timeval wait, int *sockp) { return clntudp_bufcreate(raddr, program, version, wait, sockp, @@ -200,13 +184,8 @@ clntudp_create(raddr, program, version, wait, sockp) } CLIENT * -clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - int *sockp; - u_int sendsz; - u_int recvsz; +clnttcp_create(struct sockaddr_in *raddr, u_long prog, u_long vers, int *sockp, + u_int sendsz, u_int recvsz) { return clnt_com_create(raddr, (rpcprog_t)prog, (rpcvers_t)vers, sockp, @@ -214,9 +193,7 @@ clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) } CLIENT * -clntraw_create(prog, vers) - u_long prog; - u_long vers; +clntraw_create(u_long prog, u_long vers) { return clnt_raw_create((rpcprog_t)prog, (rpcvers_t)vers); @@ -226,11 +203,7 @@ clntraw_create(prog, vers) * A common server create routine */ static SVCXPRT * -svc_com_create(fd, sendsize, recvsize, netid) - int fd; - u_int sendsize; - u_int recvsize; - char *netid; +svc_com_create(int fd, u_int sendsize, u_int recvsize, char *netid) { struct netconfig *nconf; SVCXPRT *svc; @@ -270,29 +243,21 @@ svc_com_create(fd, sendsize, recvsize, netid) } SVCXPRT * -svctcp_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svctcp_create(int fd, u_int sendsize, u_int recvsize) { return svc_com_create(fd, sendsize, recvsize, "tcp"); } SVCXPRT * -svcudp_bufcreate(fd, sendsz, recvsz) - int fd; - u_int sendsz, recvsz; +svcudp_bufcreate(int fd, u_int sendsz, u_int recvsz) { return svc_com_create(fd, sendsz, recvsz, "udp"); } SVCXPRT * -svcfd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svcfd_create(int fd, u_int sendsize, u_int recvsize) { return svc_fd_create(fd, sendsize, recvsize); @@ -300,23 +265,21 @@ svcfd_create(fd, sendsize, recvsize) SVCXPRT * -svcudp_create(fd) - int fd; +svcudp_create(int fd) { return svc_com_create(fd, UDPMSGSIZE, UDPMSGSIZE, "udp"); } SVCXPRT * -svcraw_create() +svcraw_create(void) { return svc_raw_create(); } int -get_myaddress(addr) - struct sockaddr_in *addr; +get_myaddress(struct sockaddr_in *addr) { memset((void *) addr, 0, sizeof(*addr)); @@ -330,11 +293,8 @@ get_myaddress(addr) * For connectionless "udp" transport. Obsoleted by rpc_call(). */ int -callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) - const char *host; - int prognum, versnum, procnum; - xdrproc_t inproc, outproc; - void *in, *out; +callrpc(const char *host, int prognum, int versnum, int procnum, + xdrproc_t inproc, void *in, xdrproc_t outproc, void *out) { return (int)rpc_call(host, (rpcprog_t)prognum, (rpcvers_t)versnum, @@ -345,10 +305,9 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) * For connectionless kind of transport. Obsoleted by rpc_reg() */ int -registerrpc(prognum, versnum, procnum, progname, inproc, outproc) - int prognum, versnum, procnum; - char *(*progname)(char [UDPMSGSIZE]); - xdrproc_t inproc, outproc; +registerrpc(int prognum, int versnum, int procnum, + char *(*progname)(char [UDPMSGSIZE]), + xdrproc_t inproc, xdrproc_t outproc) { return rpc_reg((rpcprog_t)prognum, (rpcvers_t)versnum, @@ -376,10 +335,12 @@ clnt_broadcast_key_init(void) */ /* ARGSUSED */ static bool_t -rpc_wrap_bcast(resultp, addr, nconf) - char *resultp; /* results of the call */ - struct netbuf *addr; /* address of the guy who responded */ - struct netconfig *nconf; /* Netconf of the transport */ +rpc_wrap_bcast(char *resultp, struct netbuf *addr, struct netconfig *nconf) +/* + * char *resultp; // results of the call + * struct netbuf *addr; // address of the guy who responded + * struct netconfig *nconf; // Netconf of the transport + */ { resultproc_t clnt_broadcast_result; @@ -397,15 +358,18 @@ rpc_wrap_bcast(resultp, addr, nconf) * Broadcasts on UDP transport. Obsoleted by rpc_broadcast(). */ enum clnt_stat -clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) - u_long prog; /* program number */ - u_long vers; /* version number */ - u_long proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - void *argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - void *resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ +clnt_broadcast(u_long prog, u_long vers, u_long proc, xdrproc_t xargs, + void *argsp, xdrproc_t xresults, void *resultsp, resultproc_t eachresult) +/* + * u_long prog; // program number + * u_long vers; // version number + * u_long proc; // procedure number + * xdrproc_t xargs; // xdr routine for args + * void *argsp; // pointer to args + * xdrproc_t xresults; // xdr routine for results + * void *resultsp; // pointer to results + * resultproc_t eachresult; // call with each result obtained + */ { if (thr_main()) @@ -424,11 +388,14 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) * authdes_seccreate(). */ AUTH * -authdes_create(servername, window, syncaddr, ckey) - char *servername; /* network name of server */ - u_int window; /* time to live */ - struct sockaddr *syncaddr; /* optional hostaddr to sync with */ - des_block *ckey; /* optional conversation key to use */ +authdes_create(char *servername, u_int window, struct sockaddr *syncaddr, + des_block *ckey) +/* + * char *servername; // network name of server + * u_int window; // time to live + * struct sockaddr *syncaddr; // optional hostaddr to sync with + * des_block *ckey; // optional conversation key to use + */ { AUTH *dummy; AUTH *nauth; @@ -455,27 +422,19 @@ fallback: * Create a client handle for a unix connection. Obsoleted by clnt_vc_create() */ CLIENT * -clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz) - struct sockaddr_un *raddr; - u_long prog; - u_long vers; - int *sockp; - u_int sendsz; - u_int recvsz; +clntunix_create(struct sockaddr_un *raddr, u_long prog, u_long vers, int *sockp, + u_int sendsz, u_int recvsz) { struct netbuf *svcaddr; - struct netconfig *nconf; CLIENT *cl; int len; cl = NULL; - nconf = NULL; svcaddr = NULL; if ((raddr->sun_len == 0) || ((svcaddr = malloc(sizeof(struct netbuf))) == NULL ) || ((svcaddr->buf = malloc(sizeof(struct sockaddr_un))) == NULL)) { - if (svcaddr != NULL) - free(svcaddr); + free(svcaddr); rpc_createerr.cf_stat = RPC_SYSTEMERROR; rpc_createerr.cf_error.re_errno = errno; return(cl); @@ -508,11 +467,7 @@ done: * Obsoleted by svc_vc_create(). */ SVCXPRT * -svcunix_create(sock, sendsize, recvsize, path) - int sock; - u_int sendsize; - u_int recvsize; - char *path; +svcunix_create(int sock, u_int sendsize, u_int recvsize, char *path) { struct netconfig *nconf; void *localhandle; @@ -530,7 +485,7 @@ svcunix_create(sock, sendsize, recvsize, path) break; } if (nconf == NULL) - return(xprt); + goto done; if ((sock = __rpc_nconf2fd(nconf)) < 0) goto done; @@ -572,10 +527,7 @@ done: * descriptor as its first input. Obsoleted by svc_fd_create(); */ SVCXPRT * -svcunixfd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svcunixfd_create(int fd, u_int sendsize, u_int recvsize) { return (svc_fd_create(fd, sendsize, recvsize)); } diff --git a/freebsd/lib/libc/rpc/rpcb_clnt.c b/freebsd/lib/libc/rpc/rpcb_clnt.c index ffee9659..b8f1dd0c 100644 --- a/freebsd/lib/libc/rpc/rpcb_clnt.c +++ b/freebsd/lib/libc/rpc/rpcb_clnt.c @@ -111,9 +111,7 @@ static struct netbuf *got_entry(rpcb_entry_list_ptr, const struct netconfig *); * These are private routines that may not be provided in future releases. */ bool_t -__rpc_control(request, info) - int request; - void *info; +__rpc_control(int request, void *info) { switch (request) { case CLCR_GET_RPCB_TIMEOUT: @@ -152,8 +150,7 @@ __rpc_control(request, info) */ static struct address_cache * -check_cache(host, netid) - const char *host, *netid; +check_cache(const char *host, const char *netid) { struct address_cache *cptr; @@ -173,8 +170,7 @@ check_cache(host, netid) } static void -delete_cache(addr) - struct netbuf *addr; +delete_cache(struct netbuf *addr) { struct address_cache *cptr, *prevptr = NULL; @@ -185,8 +181,7 @@ delete_cache(addr) free(cptr->ac_netid); free(cptr->ac_taddr->buf); free(cptr->ac_taddr); - if (cptr->ac_uaddr) - free(cptr->ac_uaddr); + free(cptr->ac_uaddr); if (prevptr) prevptr->ac_next = cptr->ac_next; else @@ -200,10 +195,8 @@ delete_cache(addr) } static void -add_cache(host, netid, taddr, uaddr) - const char *host, *netid; - char *uaddr; - struct netbuf *taddr; +add_cache(const char *host, const char *netid, struct netbuf *taddr, + char *uaddr) { struct address_cache *ad_cache, *cptr, *prevptr; @@ -224,14 +217,10 @@ add_cache(host, netid, taddr, uaddr) ad_cache->ac_taddr->buf = (char *) malloc(taddr->len); if (ad_cache->ac_taddr->buf == NULL) { out: - if (ad_cache->ac_host) - free(ad_cache->ac_host); - if (ad_cache->ac_netid) - free(ad_cache->ac_netid); - if (ad_cache->ac_uaddr) - free(ad_cache->ac_uaddr); - if (ad_cache->ac_taddr) - free(ad_cache->ac_taddr); + free(ad_cache->ac_host); + free(ad_cache->ac_netid); + free(ad_cache->ac_uaddr); + free(ad_cache->ac_taddr); free(ad_cache); return; } @@ -264,8 +253,7 @@ out: free(cptr->ac_netid); free(cptr->ac_taddr->buf); free(cptr->ac_taddr); - if (cptr->ac_uaddr) - free(cptr->ac_uaddr); + free(cptr->ac_uaddr); if (prevptr) { prevptr->ac_next = NULL; @@ -288,10 +276,7 @@ out: * On error, returns NULL and free's everything. */ static CLIENT * -getclnthandle(host, nconf, targaddr) - const char *host; - const struct netconfig *nconf; - char **targaddr; +getclnthandle(const char *host, const struct netconfig *nconf, char **targaddr) { CLIENT *client; struct netbuf *addr, taddr; @@ -437,7 +422,7 @@ getclnthandle(host, nconf, targaddr) * rpcbind. Returns NULL on error and free's everything. */ static CLIENT * -local_rpcb() +local_rpcb(void) { CLIENT *client; static struct netconfig *loopnconf; @@ -516,6 +501,7 @@ try_nconf: hostname = IN6_LOCALHOST_STRING; } } + endnetconfig(nc_handle); if (tmpnconf == NULL) { rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; mutex_unlock(&loopnconf_lock); @@ -523,7 +509,6 @@ try_nconf: } loopnconf = getnetconfigent(tmpnconf->nc_netid); /* loopnconf is never freed */ - endnetconfig(nc_handle); } mutex_unlock(&loopnconf_lock); client = getclnthandle(hostname, loopnconf, NULL); @@ -533,13 +518,13 @@ try_nconf: /* * Set a mapping between program, version and address. * Calls the rpcbind service to do the mapping. + * + * nconf - Network structure of transport + * address - Services netconfig address */ bool_t -rpcb_set(program, version, nconf, address) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; /* Network structure of transport */ - const struct netbuf *address; /* Services netconfig address */ +rpcb_set(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, + const struct netbuf *address) { CLIENT *client; bool_t rslt = FALSE; @@ -596,10 +581,7 @@ rpcb_set(program, version, nconf, address) * only for the given transport. */ bool_t -rpcb_unset(program, version, nconf) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; +rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf) { CLIENT *client; bool_t rslt = FALSE; @@ -636,9 +618,7 @@ rpcb_unset(program, version, nconf) * From the merged list, find the appropriate entry */ static struct netbuf * -got_entry(relp, nconf) - rpcb_entry_list_ptr relp; - const struct netconfig *nconf; +got_entry(rpcb_entry_list_ptr relp, const struct netconfig *nconf) { struct netbuf *na = NULL; rpcb_entry_list_ptr sp; @@ -669,7 +649,7 @@ got_entry(relp, nconf) * local transport. */ static bool_t -__rpcbind_is_up() +__rpcbind_is_up(void) { struct netconfig *nconf; struct sockaddr_un sun; @@ -683,11 +663,11 @@ __rpcbind_is_up() strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) break; } + endnetconfig(localhandle); + if (nconf == NULL) return (FALSE); - endnetconfig(localhandle); - memset(&sun, 0, sizeof sun); sock = _socket(AF_LOCAL, SOCK_STREAM, 0); if (sock < 0) @@ -724,13 +704,9 @@ __rpcbind_is_up() * starts working properly. Also look under clnt_vc.c. */ struct netbuf * -__rpcb_findaddr_timed(program, version, nconf, host, clpp, tp) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - const char *host; - CLIENT **clpp; - struct timeval *tp; +__rpcb_findaddr_timed(rpcprog_t program, rpcvers_t version, + const struct netconfig *nconf, const char *host, + CLIENT **clpp, struct timeval *tp) { static bool_t check_rpcbind = TRUE; CLIENT *client = NULL; @@ -818,10 +794,8 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp) malloc(remote.len)) == NULL)) { rpc_createerr.cf_stat = RPC_SYSTEMERROR; clnt_geterr(client, &rpc_createerr.cf_error); - if (address) { - free(address); - address = NULL; - } + free(address); + address = NULL; goto error; } memcpy(address->buf, remote.buf, remote.len); @@ -1039,12 +1013,8 @@ done: * Assuming that the address is all properly allocated */ bool_t -rpcb_getaddr(program, version, nconf, address, host) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - struct netbuf *address; - const char *host; +rpcb_getaddr(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf, + struct netbuf *address, const char *host) { struct netbuf *na; @@ -1075,9 +1045,7 @@ rpcb_getaddr(program, version, nconf, address, host) * It returns NULL on failure. */ rpcblist * -rpcb_getmaps(nconf, host) - const struct netconfig *nconf; - const char *host; +rpcb_getmaps(const struct netconfig *nconf, const char *host) { rpcblist_ptr head = NULL; CLIENT *client; @@ -1125,19 +1093,20 @@ done: * which will look up a service program in the address maps, and then * remotely call that routine with the given parameters. This allows * programs to do a lookup and call in one step. -*/ + * + * nconf -Netconfig structure + * host - Remote host name + * proc - Remote proc identifiers + * xdrargs, xdrres; XDR routines + * argsp, resp - Argument and Result + * tout - Timeout value for this call + * addr_ptr - Preallocated netbuf address + */ enum clnt_stat -rpcb_rmtcall(nconf, host, prog, vers, proc, xdrargs, argsp, - xdrres, resp, tout, addr_ptr) - const struct netconfig *nconf; /* Netconfig structure */ - const char *host; /* Remote host name */ - rpcprog_t prog; - rpcvers_t vers; - rpcproc_t proc; /* Remote proc identifiers */ - xdrproc_t xdrargs, xdrres; /* XDR routines */ - caddr_t argsp, resp; /* Argument and Result */ - struct timeval tout; /* Timeout value for this call */ - const struct netbuf *addr_ptr; /* Preallocated netbuf address */ +rpcb_rmtcall(const struct netconfig *nconf, const char *host, rpcprog_t prog, + rpcvers_t vers, rpcproc_t proc, xdrproc_t xdrargs, caddr_t argsp, + xdrproc_t xdrres, caddr_t resp, struct timeval tout, + const struct netbuf *addr_ptr) { CLIENT *client; enum clnt_stat stat; @@ -1208,9 +1177,7 @@ error: * Returns 1 if succeeds else 0. */ bool_t -rpcb_gettime(host, timep) - const char *host; - time_t *timep; +rpcb_gettime(const char *host, time_t *timep) { CLIENT *client = NULL; void *handle; @@ -1269,9 +1236,7 @@ rpcb_gettime(host, timep) * really be called because local n2a libraries are always provided. */ char * -rpcb_taddr2uaddr(nconf, taddr) - struct netconfig *nconf; - struct netbuf *taddr; +rpcb_taddr2uaddr(struct netconfig *nconf, struct netbuf *taddr) { CLIENT *client; char *uaddr = NULL; @@ -1303,9 +1268,7 @@ rpcb_taddr2uaddr(nconf, taddr) * really be called because local n2a libraries are always provided. */ struct netbuf * -rpcb_uaddr2taddr(nconf, uaddr) - struct netconfig *nconf; - char *uaddr; +rpcb_uaddr2taddr(struct netconfig *nconf, char *uaddr) { CLIENT *client; struct netbuf *taddr; diff --git a/freebsd/lib/libc/rpc/rpcb_prot.c b/freebsd/lib/libc/rpc/rpcb_prot.c index c3a7ea8e..95072371 100644 --- a/freebsd/lib/libc/rpc/rpcb_prot.c +++ b/freebsd/lib/libc/rpc/rpcb_prot.c @@ -56,14 +56,12 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" bool_t -xdr_rpcb(xdrs, objp) - XDR *xdrs; - RPCB *objp; +xdr_rpcb(XDR *xdrs, RPCB *objp) { - if (!xdr_u_int32_t(xdrs, &objp->r_prog)) { + if (!xdr_rpcprog(xdrs, &objp->r_prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->r_vers)) { + if (!xdr_rpcvers(xdrs, &objp->r_vers)) { return (FALSE); } if (!xdr_string(xdrs, &objp->r_netid, (u_int)~0)) { @@ -102,9 +100,7 @@ xdr_rpcb(xdrs, objp) */ bool_t -xdr_rpcblist_ptr(xdrs, rp) - XDR *xdrs; - rpcblist_ptr *rp; +xdr_rpcblist_ptr(XDR *xdrs, rpcblist_ptr *rp) { /* * more_elements is pre-computed in case the direction is @@ -156,9 +152,7 @@ xdr_rpcblist_ptr(xdrs, rp) * functionality to xdr_rpcblist_ptr(). */ bool_t -xdr_rpcblist(xdrs, rp) - XDR *xdrs; - RPCBLIST **rp; +xdr_rpcblist(XDR *xdrs, RPCBLIST **rp) { bool_t dummy; @@ -168,9 +162,7 @@ xdr_rpcblist(xdrs, rp) bool_t -xdr_rpcb_entry(xdrs, objp) - XDR *xdrs; - rpcb_entry *objp; +xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp) { if (!xdr_string(xdrs, &objp->r_maddr, (u_int)~0)) { return (FALSE); @@ -191,9 +183,7 @@ xdr_rpcb_entry(xdrs, objp) } bool_t -xdr_rpcb_entry_list_ptr(xdrs, rp) - XDR *xdrs; - rpcb_entry_list_ptr *rp; +xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp) { /* * more_elements is pre-computed in case the direction is @@ -219,14 +209,14 @@ xdr_rpcb_entry_list_ptr(xdrs, rp) * the case of freeing we must remember the next object * before we free the current object ... */ - if (freeing) + if (freeing && *rp) next = (*rp)->rpcb_entry_next; if (! xdr_reference(xdrs, (caddr_t *)rp, (u_int)sizeof (rpcb_entry_list), (xdrproc_t)xdr_rpcb_entry)) { return (FALSE); } - if (freeing && *rp) { + if (freeing) { next_copy = next; rp = &next_copy; /* @@ -246,9 +236,7 @@ xdr_rpcb_entry_list_ptr(xdrs, rp) * written for XDR_ENCODE direction only */ bool_t -xdr_rpcb_rmtcallargs(xdrs, p) - XDR *xdrs; - struct rpcb_rmtcallargs *p; +xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *p) { struct r_rpcb_rmtcallargs *objp = (struct r_rpcb_rmtcallargs *)(void *)p; @@ -257,13 +245,13 @@ xdr_rpcb_rmtcallargs(xdrs, p) buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } } else { @@ -298,9 +286,7 @@ xdr_rpcb_rmtcallargs(xdrs, p) * written for XDR_DECODE direction only */ bool_t -xdr_rpcb_rmtcallres(xdrs, p) - XDR *xdrs; - struct rpcb_rmtcallres *p; +xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *p) { bool_t dummy; struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p; @@ -316,9 +302,7 @@ xdr_rpcb_rmtcallres(xdrs, p) } bool_t -xdr_netbuf(xdrs, objp) - XDR *xdrs; - struct netbuf *objp; +xdr_netbuf(XDR *xdrs, struct netbuf *objp) { bool_t dummy; void **pp; diff --git a/freebsd/lib/libc/rpc/rpcb_st_xdr.c b/freebsd/lib/libc/rpc/rpcb_st_xdr.c index 375f06cd..6b8711ea 100644 --- a/freebsd/lib/libc/rpc/rpcb_st_xdr.c +++ b/freebsd/lib/libc/rpc/rpcb_st_xdr.c @@ -49,16 +49,14 @@ __FBSDID("$FreeBSD$"); /* Link list of all the stats about getport and getaddr */ bool_t -xdr_rpcbs_addrlist(xdrs, objp) - XDR *xdrs; - rpcbs_addrlist *objp; +xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp) { struct rpcbs_addrlist **pnext; - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -85,9 +83,7 @@ xdr_rpcbs_addrlist(xdrs, objp) /* Link list of all the stats about rmtcall */ bool_t -xdr_rpcbs_rmtcalllist(xdrs, objp) - XDR *xdrs; - rpcbs_rmtcalllist *objp; +xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) { int32_t *buf; struct rpcbs_rmtcalllist **pnext; @@ -95,13 +91,13 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) if (xdrs->x_op == XDR_ENCODE) { buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -134,13 +130,13 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) } else if (xdrs->x_op == XDR_DECODE) { buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT); if (buf == NULL) { - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -170,13 +166,13 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) } return (TRUE); } - if (!xdr_u_int32_t(xdrs, &objp->prog)) { + if (!xdr_rpcprog(xdrs, &objp->prog)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->vers)) { + if (!xdr_rpcvers(xdrs, &objp->vers)) { return (FALSE); } - if (!xdr_u_int32_t(xdrs, &objp->proc)) { + if (!xdr_rpcproc(xdrs, &objp->proc)) { return (FALSE); } if (!xdr_int(xdrs, &objp->success)) { @@ -200,9 +196,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) } bool_t -xdr_rpcbs_proc(xdrs, objp) - XDR *xdrs; - rpcbs_proc objp; +xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp) { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC, sizeof (int), (xdrproc_t)xdr_int)) { @@ -212,9 +206,7 @@ xdr_rpcbs_proc(xdrs, objp) } bool_t -xdr_rpcbs_addrlist_ptr(xdrs, objp) - XDR *xdrs; - rpcbs_addrlist_ptr *objp; +xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp) { if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist), (xdrproc_t)xdr_rpcbs_addrlist)) { @@ -224,9 +216,7 @@ xdr_rpcbs_addrlist_ptr(xdrs, objp) } bool_t -xdr_rpcbs_rmtcalllist_ptr(xdrs, objp) - XDR *xdrs; - rpcbs_rmtcalllist_ptr *objp; +xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp) { if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { @@ -236,9 +226,7 @@ xdr_rpcbs_rmtcalllist_ptr(xdrs, objp) } bool_t -xdr_rpcb_stat(xdrs, objp) - XDR *xdrs; - rpcb_stat *objp; +xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp) { if (!xdr_rpcbs_proc(xdrs, objp->info)) { @@ -264,9 +252,7 @@ xdr_rpcb_stat(xdrs, objp) * being monitored. */ bool_t -xdr_rpcb_stat_byvers(xdrs, objp) - XDR *xdrs; - rpcb_stat_byvers objp; +xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp) { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT, sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) { diff --git a/freebsd/lib/libc/rpc/rpcdname.c b/freebsd/lib/libc/rpc/rpcdname.c index 1805da80..63ea11e1 100644 --- a/freebsd/lib/libc/rpc/rpcdname.c +++ b/freebsd/lib/libc/rpc/rpcdname.c @@ -45,20 +45,20 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include "un-namespace.h" -static char *default_domain = 0; +static char *default_domain; static char * -get_default_domain() +get_default_domain(void) { char temp[256]; - if (default_domain) + if (default_domain != NULL) return (default_domain); if (getdomainname(temp, sizeof(temp)) < 0) return (0); if ((int) strlen(temp) > 0) { - default_domain = (char *)malloc((strlen(temp)+(unsigned)1)); - if (default_domain == 0) + default_domain = malloc((strlen(temp) + (unsigned)1)); + if (default_domain == NULL) return (0); (void) strcpy(default_domain, temp); return (default_domain); @@ -73,10 +73,9 @@ get_default_domain() * get rejected elsewhere in the NIS client package. */ int -__rpc_get_default_domain(domain) - char **domain; +__rpc_get_default_domain(char **domain) { - if ((*domain = get_default_domain()) != 0) + if ((*domain = get_default_domain()) != NULL) return (0); return (-1); } diff --git a/freebsd/lib/libc/rpc/rtime.c b/freebsd/lib/libc/rpc/rtime.c index b8f783e9..a6223863 100644 --- a/freebsd/lib/libc/rpc/rtime.c +++ b/freebsd/lib/libc/rpc/rtime.c @@ -63,16 +63,14 @@ __FBSDID("$FreeBSD$"); extern int _rpc_dtablesize( void ); -#define NYEARS (unsigned long)(1970 - 1900) -#define TOFFSET (unsigned long)(60*60*24*(365*NYEARS + (NYEARS/4))) +#define NYEARS (unsigned long)(1970 - 1900) +#define TOFFSET (unsigned long)(60*60*24*(365*NYEARS + (NYEARS/4))) static void do_close( int ); int -rtime(addrp, timep, timeout) - struct sockaddr_in *addrp; - struct timeval *timep; - struct timeval *timeout; +rtime(struct sockaddr_in *addrp, struct timeval *timep, + struct timeval *timeout) { int s; fd_set readfds; @@ -102,11 +100,11 @@ rtime(addrp, timep, timeout) addrp->sin_port = serv->s_port; if (type == SOCK_DGRAM) { - res = _sendto(s, (char *)&thetime, sizeof(thetime), 0, + res = _sendto(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)addrp, sizeof(*addrp)); if (res < 0) { do_close(s); - return(-1); + return(-1); } do { FD_ZERO(&readfds); @@ -119,14 +117,14 @@ rtime(addrp, timep, timeout) errno = ETIMEDOUT; } do_close(s); - return(-1); + return(-1); } fromlen = sizeof(from); - res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0, + res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)&from, &fromlen); do_close(s); if (res < 0) { - return(-1); + return(-1); } } else { if (_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) { @@ -141,7 +139,7 @@ rtime(addrp, timep, timeout) } if (res != sizeof(thetime)) { errno = EIO; - return(-1); + return(-1); } thetime = ntohl(thetime); timep->tv_sec = thetime - TOFFSET; @@ -150,8 +148,7 @@ rtime(addrp, timep, timeout) } static void -do_close(s) - int s; +do_close(int s) { int save; diff --git a/freebsd/lib/libc/rpc/svc.c b/freebsd/lib/libc/rpc/svc.c index 709bfffa..64b79036 100644 --- a/freebsd/lib/libc/rpc/svc.c +++ b/freebsd/lib/libc/rpc/svc.c @@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$"); * The services list * Each entry represents a set of procedures (an rpc program). * The dispatch routine takes request structs and runs the - * apropriate procedure. + * appropriate procedure. */ static struct svc_callout { struct svc_callout *sc_next; @@ -86,6 +86,9 @@ static struct svc_callout { void (*sc_dispatch)(struct svc_req *, SVCXPRT *); } *svc_head; +SVCXPRT **__svc_xports; +int __svc_maxrec; + static struct svc_callout *svc_find(rpcprog_t, rpcvers_t, struct svc_callout **, char *); static void __xprt_do_unregister (SVCXPRT *xprt, bool_t dolock); @@ -96,8 +99,7 @@ static void __xprt_do_unregister (SVCXPRT *xprt, bool_t dolock); * Activate a transport handle. */ void -xprt_register(xprt) - SVCXPRT *xprt; +xprt_register(SVCXPRT *xprt) { int sock; @@ -139,9 +141,7 @@ __xprt_unregister_unlocked(SVCXPRT *xprt) * De-activate a transport handle. */ static void -__xprt_do_unregister(xprt, dolock) - SVCXPRT *xprt; - bool_t dolock; +__xprt_do_unregister(SVCXPRT *xprt, bool_t dolock) { int sock; @@ -170,12 +170,9 @@ __xprt_do_unregister(xprt, dolock) * program number comes in. */ bool_t -svc_reg(xprt, prog, vers, dispatch, nconf) - SVCXPRT *xprt; - const rpcprog_t prog; - const rpcvers_t vers; - void (*dispatch)(struct svc_req *, SVCXPRT *); - const struct netconfig *nconf; +svc_reg(SVCXPRT *xprt, const rpcprog_t prog, const rpcvers_t vers, + void (*dispatch)(struct svc_req *, SVCXPRT *), + const struct netconfig *nconf) { bool_t dummy; struct svc_callout *prev; @@ -203,8 +200,7 @@ svc_reg(xprt, prog, vers, dispatch, nconf) rwlock_wrlock(&svc_lock); if ((s = svc_find(prog, vers, &prev, netid)) != NULL) { - if (netid) - free(netid); + free(netid); if (s->sc_dispatch == dispatch) goto rpcb_it; /* he is registering another xptr */ rwlock_unlock(&svc_lock); @@ -212,8 +208,7 @@ svc_reg(xprt, prog, vers, dispatch, nconf) } s = mem_alloc(sizeof (struct svc_callout)); if (s == NULL) { - if (netid) - free(netid); + free(netid); rwlock_unlock(&svc_lock); return (FALSE); } @@ -244,9 +239,7 @@ rpcb_it: * Remove a service program from the callout list. */ void -svc_unreg(prog, vers) - const rpcprog_t prog; - const rpcvers_t vers; +svc_unreg(const rpcprog_t prog, const rpcvers_t vers) { struct svc_callout *prev; struct svc_callout *s; @@ -277,12 +270,9 @@ svc_unreg(prog, vers) * program number comes in. */ bool_t -svc_register(xprt, prog, vers, dispatch, protocol) - SVCXPRT *xprt; - u_long prog; - u_long vers; - void (*dispatch)(struct svc_req *, SVCXPRT *); - int protocol; +svc_register(SVCXPRT *xprt, u_long prog, u_long vers, + void (*dispatch)(struct svc_req *, SVCXPRT *), + int protocol) { struct svc_callout *prev; struct svc_callout *s; @@ -317,9 +307,7 @@ pmap_it: * Remove a service program from the callout list. */ void -svc_unregister(prog, vers) - u_long prog; - u_long vers; +svc_unregister(u_long prog, u_long vers) { struct svc_callout *prev; struct svc_callout *s; @@ -344,11 +332,8 @@ svc_unregister(prog, vers) * struct. */ static struct svc_callout * -svc_find(prog, vers, prev, netid) - rpcprog_t prog; - rpcvers_t vers; - struct svc_callout **prev; - char *netid; +svc_find(rpcprog_t prog, rpcvers_t vers, struct svc_callout **prev, + char *netid) { struct svc_callout *s, *p; @@ -372,10 +357,8 @@ svc_find(prog, vers, prev, netid) * Send a reply to an rpc request */ bool_t -svc_sendreply(xprt, xdr_results, xdr_location) - SVCXPRT *xprt; - xdrproc_t xdr_results; - void * xdr_location; +svc_sendreply(SVCXPRT *xprt, xdrproc_t xdr_results, + void * xdr_location) { struct rpc_msg rply; @@ -394,8 +377,7 @@ svc_sendreply(xprt, xdr_results, xdr_location) * No procedure error reply */ void -svcerr_noproc(xprt) - SVCXPRT *xprt; +svcerr_noproc(SVCXPRT *xprt) { struct rpc_msg rply; @@ -412,8 +394,7 @@ svcerr_noproc(xprt) * Can't decode args error reply */ void -svcerr_decode(xprt) - SVCXPRT *xprt; +svcerr_decode(SVCXPRT *xprt) { struct rpc_msg rply; @@ -430,8 +411,7 @@ svcerr_decode(xprt) * Some system error */ void -svcerr_systemerr(xprt) - SVCXPRT *xprt; +svcerr_systemerr(SVCXPRT *xprt) { struct rpc_msg rply; @@ -452,31 +432,27 @@ svcerr_systemerr(xprt) * protocol: the portmapper (or rpc binder). */ void -__svc_versquiet_on(xprt) - SVCXPRT *xprt; +__svc_versquiet_on(SVCXPRT *xprt) { SVC_EXT(xprt)->xp_flags |= SVC_VERSQUIET; } void -__svc_versquiet_off(xprt) - SVCXPRT *xprt; +__svc_versquiet_off(SVCXPRT *xprt) { SVC_EXT(xprt)->xp_flags &= ~SVC_VERSQUIET; } void -svc_versquiet(xprt) - SVCXPRT *xprt; +svc_versquiet(SVCXPRT *xprt) { __svc_versquiet_on(xprt); } int -__svc_versquiet_get(xprt) - SVCXPRT *xprt; +__svc_versquiet_get(SVCXPRT *xprt) { return (SVC_EXT(xprt)->xp_flags & SVC_VERSQUIET); @@ -487,9 +463,7 @@ __svc_versquiet_get(xprt) * Authentication error reply */ void -svcerr_auth(xprt, why) - SVCXPRT *xprt; - enum auth_stat why; +svcerr_auth(SVCXPRT *xprt, enum auth_stat why) { struct rpc_msg rply; @@ -506,8 +480,7 @@ svcerr_auth(xprt, why) * Auth too weak error reply */ void -svcerr_weakauth(xprt) - SVCXPRT *xprt; +svcerr_weakauth(SVCXPRT *xprt) { assert(xprt != NULL); @@ -519,8 +492,7 @@ svcerr_weakauth(xprt) * Program unavailable error reply */ void -svcerr_noprog(xprt) - SVCXPRT *xprt; +svcerr_noprog(SVCXPRT *xprt) { struct rpc_msg rply; @@ -537,10 +509,7 @@ svcerr_noprog(xprt) * Program version mismatch error reply */ void -svcerr_progvers(xprt, low_vers, high_vers) - SVCXPRT *xprt; - rpcvers_t low_vers; - rpcvers_t high_vers; +svcerr_progvers(SVCXPRT *xprt, rpcvers_t low_vers, rpcvers_t high_vers) { struct rpc_msg rply; @@ -562,7 +531,7 @@ svcerr_progvers(xprt, low_vers, high_vers) * parameters. */ SVCXPRT * -svc_xprt_alloc() +svc_xprt_alloc(void) { SVCXPRT *xprt; SVCXPRT_EXT *ext; @@ -587,8 +556,7 @@ svc_xprt_alloc() * Free a server transport structure. */ void -svc_xprt_free(xprt) - SVCXPRT *xprt; +svc_xprt_free(SVCXPRT *xprt) { mem_free(xprt->xp_p3, sizeof(SVCXPRT_EXT)); @@ -614,8 +582,7 @@ svc_xprt_free(xprt) */ void -svc_getreq(rdfds) - int rdfds; +svc_getreq(int rdfds) { fd_set readfds; @@ -625,8 +592,7 @@ svc_getreq(rdfds) } void -svc_getreqset(readfds) - fd_set *readfds; +svc_getreqset(fd_set *readfds) { int bit, fd; fd_mask mask, *maskp; @@ -646,8 +612,7 @@ svc_getreqset(readfds) } void -svc_getreq_common(fd) - int fd; +svc_getreq_common(int fd) { SVCXPRT *xprt; struct svc_req r; @@ -742,9 +707,7 @@ call_done: void -svc_getreq_poll(pfdp, pollretval) - struct pollfd *pfdp; - int pollretval; +svc_getreq_poll(struct pollfd *pfdp, int pollretval) { int i; int fds_found; diff --git a/freebsd/lib/libc/rpc/svc_auth.c b/freebsd/lib/libc/rpc/svc_auth.c index 917e5e81..ea56b340 100644 --- a/freebsd/lib/libc/rpc/svc_auth.c +++ b/freebsd/lib/libc/rpc/svc_auth.c @@ -97,9 +97,7 @@ struct svc_auth_ops svc_auth_null_ops; * invalid. */ enum auth_stat -_authenticate(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_authenticate(struct svc_req *rqst, struct rpc_msg *msg) { int cred_flavor; struct authsvc *asp; @@ -153,11 +151,7 @@ _authenticate(rqst, msg) * that don't need to inspect or modify the message body. */ static bool_t -svcauth_null_wrap(auth, xdrs, xdr_func, xdr_ptr) - SVCAUTH *auth; - XDR *xdrs; - xdrproc_t xdr_func; - caddr_t xdr_ptr; +svcauth_null_wrap(SVCAUTH *auth, XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr) { return (xdr_func(xdrs, xdr_ptr)); @@ -170,9 +164,7 @@ struct svc_auth_ops svc_auth_null_ops = { /*ARGSUSED*/ enum auth_stat -_svcauth_null(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_null(struct svc_req *rqst, struct rpc_msg *msg) { return (AUTH_OK); } @@ -192,9 +184,8 @@ _svcauth_null(rqst, msg) */ int -svc_auth_reg(cred_flavor, handler) - int cred_flavor; - enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *); +svc_auth_reg(int cred_flavor, + enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *)) { struct authsvc *asp; diff --git a/freebsd/lib/libc/rpc/svc_auth_des.c b/freebsd/lib/libc/rpc/svc_auth_des.c index a9408019..55f3d3ee 100644 --- a/freebsd/lib/libc/rpc/svc_auth_des.c +++ b/freebsd/lib/libc/rpc/svc_auth_des.c @@ -92,11 +92,11 @@ struct cache_entry { static struct cache_entry *authdes_cache/* [AUTHDES_CACHESZ] */; static short *authdes_lru/* [AUTHDES_CACHESZ] */; -static void cache_init(); /* initialize the cache */ -static short cache_spot(); /* find an entry in the cache */ -static void cache_ref(/*short sid*/); /* note that sid was ref'd */ +static void cache_init(void); /* initialize the cache */ +static short cache_spot(des_block *, char *, struct timeval *); /* find an entry in the cache */ +static void cache_ref(short sid); /* note that sid was ref'd */ -static void invalidate(); /* invalidate entry in cache */ +static void invalidate(char *); /* invalidate entry in cache */ /* * cache statistics @@ -111,9 +111,7 @@ static struct { * Service side authenticator for AUTH_DES */ enum auth_stat -_svcauth_des(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_des(struct svc_req *rqst, struct rpc_msg *msg) { long *ixdr; @@ -272,7 +270,7 @@ _svcauth_des(rqst, msg) debug("timestamp before last seen"); return (AUTH_REJECTEDVERF); /* replay */ } - (void) gettimeofday(¤t, (struct timezone *)NULL); + (void)gettimeofday(¤t, NULL); current.tv_sec -= window; /* allow for expiration */ if (!BEFORE(¤t, ×tamp)) { debug("timestamp expired"); @@ -357,7 +355,7 @@ _svcauth_des(rqst, msg) * Initialize the cache */ static void -cache_init() +cache_init(void) { int i; @@ -380,7 +378,7 @@ cache_init() * Find the lru victim */ static short -cache_victim() +cache_victim(void) { return (authdes_lru[AUTHDES_CACHESZ-1]); } @@ -389,8 +387,7 @@ cache_victim() * Note that sid was referenced */ static void -cache_ref(sid) - short sid; +cache_ref(short sid) { int i; short curr; @@ -412,10 +409,7 @@ cache_ref(sid) * return the spot in the cache. */ static short -cache_spot(key, name, timestamp) - des_block *key; - char *name; - struct timeval *timestamp; +cache_spot(des_block *key, char *name, struct timeval *timestamp) { struct cache_entry *cp; int i; @@ -463,12 +457,8 @@ struct bsdcred { * the credential. */ int -authdes_getucred(adc, uid, gid, grouplen, groups) - struct authdes_cred *adc; - uid_t *uid; - gid_t *gid; - int *grouplen; - gid_t *groups; +authdes_getucred(struct authdes_cred *adc, uid_t *uid, gid_t *gid, + int *grouplen, gid_t *groups) { unsigned sid; int i; @@ -527,8 +517,7 @@ authdes_getucred(adc, uid, gid, grouplen, groups) } static void -invalidate(cred) - char *cred; +invalidate(char *cred) { if (cred == NULL) { return; diff --git a/freebsd/lib/libc/rpc/svc_auth_unix.c b/freebsd/lib/libc/rpc/svc_auth_unix.c index bd052b77..53459786 100644 --- a/freebsd/lib/libc/rpc/svc_auth_unix.c +++ b/freebsd/lib/libc/rpc/svc_auth_unix.c @@ -58,9 +58,7 @@ __FBSDID("$FreeBSD$"); * Unix longhand authenticator */ enum auth_stat -_svcauth_unix(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) { enum auth_stat stat; XDR xdrs; @@ -149,9 +147,7 @@ done: */ /*ARGSUSED*/ enum auth_stat -_svcauth_short(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_short(struct svc_req *rqst, struct rpc_msg *msg) { return (AUTH_REJECTEDCRED); } diff --git a/freebsd/lib/libc/rpc/svc_dg.c b/freebsd/lib/libc/rpc/svc_dg.c index 0d75191c..377ce5f2 100644 --- a/freebsd/lib/libc/rpc/svc_dg.c +++ b/freebsd/lib/libc/rpc/svc_dg.c @@ -104,10 +104,7 @@ static const char svc_dg_err4[] = "cannot set IP_RECVDSTADDR"; static const char __no_mem_str[] = "out of memory"; SVCXPRT * -svc_dg_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_dg_create(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct svc_dg_data *su = NULL; @@ -190,8 +187,7 @@ freedata_nowarn: /*ARGSUSED*/ static enum xprt_stat -svc_dg_stat(xprt) - SVCXPRT *xprt; +svc_dg_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } @@ -252,9 +248,7 @@ svc_dg_recvfrom(int fd, char *buf, int buflen, } static bool_t -svc_dg_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su = su_data(xprt); XDR *xdrs = &(su->su_xdrs); @@ -337,9 +331,7 @@ svc_dg_sendto(int fd, char *buf, int buflen, } static bool_t -svc_dg_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su = su_data(xprt); XDR *xdrs = &(su->su_xdrs); @@ -380,10 +372,7 @@ svc_dg_reply(xprt, msg) } static bool_t -svc_dg_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_dg_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct svc_dg_data *su; @@ -394,10 +383,7 @@ svc_dg_getargs(xprt, xdr_args, args_ptr) } static bool_t -svc_dg_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_dg_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { XDR *xdrs = &(su_data(xprt)->su_xdrs); @@ -406,8 +392,7 @@ svc_dg_freeargs(xprt, xdr_args, args_ptr) } static void -svc_dg_destroy(xprt) - SVCXPRT *xprt; +svc_dg_destroy(SVCXPRT *xprt) { struct svc_dg_data *su = su_data(xprt); @@ -423,24 +408,19 @@ svc_dg_destroy(xprt) (void) mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen); if (xprt->xp_ltaddr.buf) (void) mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen); - if (xprt->xp_tp) - (void) free(xprt->xp_tp); + free(xprt->xp_tp); svc_xprt_free(xprt); } static bool_t /*ARGSUSED*/ -svc_dg_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_dg_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static void -svc_dg_ops(xprt) - SVCXPRT *xprt; +svc_dg_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -538,9 +518,7 @@ static const char alloc_err[] = "could not allocate cache "; static const char enable_err[] = "cache already enabled"; int -svc_dg_enablecache(transp, size) - SVCXPRT *transp; - u_int size; +svc_dg_enablecache(SVCXPRT *transp, u_int size) { struct svc_dg_data *su = su_data(transp); struct cl_cache *uc; @@ -595,9 +573,7 @@ static const char cache_set_err2[] = "victim alloc failed"; static const char cache_set_err3[] = "could not allocate new rpc buffer"; static void -cache_set(xprt, replylen) - SVCXPRT *xprt; - size_t replylen; +cache_set(SVCXPRT *xprt, size_t replylen) { cache_ptr victim; cache_ptr *vicp; @@ -685,11 +661,7 @@ cache_set(xprt, replylen) * return 1 if found, 0 if not found and set the stage for cache_set() */ static int -cache_get(xprt, msg, replyp, replylenp) - SVCXPRT *xprt; - struct rpc_msg *msg; - char **replyp; - size_t *replylenp; +cache_get(SVCXPRT *xprt, struct rpc_msg *msg, char **replyp, size_t *replylenp) { u_int loc; cache_ptr ent; diff --git a/freebsd/lib/libc/rpc/svc_generic.c b/freebsd/lib/libc/rpc/svc_generic.c index 4d7a23a4..0643ae22 100644 --- a/freebsd/lib/libc/rpc/svc_generic.c +++ b/freebsd/lib/libc/rpc/svc_generic.c @@ -74,13 +74,14 @@ extern int __svc_vc_setflag(SVCXPRT *, int); * It creates a link list of all the handles it could create. * If svc_create() is called multiple times, it uses the handle * created earlier instead of creating a new handle every time. + * + * prognum - Program number + * versnum - Version number + * nettype - Networktype token */ int -svc_create(dispatch, prognum, versnum, nettype) - void (*dispatch)(struct svc_req *, SVCXPRT *); - rpcprog_t prognum; /* Program number */ - rpcvers_t versnum; /* Version number */ - const char *nettype; /* Networktype token */ +svc_create(void (*dispatch)(struct svc_req *, SVCXPRT *), + rpcprog_t prognum, rpcvers_t versnum, const char *nettype) { struct xlist { SVCXPRT *xprt; /* Server handle */ @@ -123,7 +124,8 @@ svc_create(dispatch, prognum, versnum, nettype) if (l == NULL) { warnx("svc_create: no memory"); mutex_unlock(&xprtlist_lock); - return (0); + num = 0; + goto done; } l->xprt = xprt; l->next = xprtlist; @@ -133,6 +135,7 @@ svc_create(dispatch, prognum, versnum, nettype) } mutex_unlock(&xprtlist_lock); } +done: __rpc_endconf(handle); /* * In case of num == 0; the error messages are generated by the @@ -145,13 +148,14 @@ svc_create(dispatch, prognum, versnum, nettype) * The high level interface to svc_tli_create(). * It tries to create a server for "nconf" and registers the service * with the rpcbind. It calls svc_tli_create(); + * + * prognum - Program number + * versnum - Version number + * ncofn - Netconfig structure for the network */ SVCXPRT * -svc_tp_create(dispatch, prognum, versnum, nconf) - void (*dispatch)(struct svc_req *, SVCXPRT *); - rpcprog_t prognum; /* Program number */ - rpcvers_t versnum; /* Version number */ - const struct netconfig *nconf; /* Netconfig structure for the network */ +svc_tp_create(void (*dispatch)(struct svc_req *, SVCXPRT *), + rpcprog_t prognum, rpcvers_t versnum, const struct netconfig *nconf) { SVCXPRT *xprt; @@ -186,14 +190,16 @@ svc_tp_create(dispatch, prognum, versnum, nconf) * is set to 8. * * If sendsz or recvsz are zero, their default values are chosen. + * + * fd - Connection end point + * nconf - Netconfig struct for nettoken + * bindaddr - Local bind address + * sendsz - Max sendsize + * recvxz - Max recvsize */ SVCXPRT * -svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz) - int fd; /* Connection end point */ - const struct netconfig *nconf; /* Netconfig struct for nettoken */ - const struct t_bind *bindaddr; /* Local bind address */ - u_int sendsz; /* Max sendsize */ - u_int recvsz; /* Max recvsize */ +svc_tli_create(int fd, const struct netconfig *nconf, + const struct t_bind *bindaddr, u_int sendsz, u_int recvsz) { SVCXPRT *xprt = NULL; /* service handle */ bool_t madefd = FALSE; /* whether fd opened here */ diff --git a/freebsd/lib/libc/rpc/svc_raw.c b/freebsd/lib/libc/rpc/svc_raw.c index 7f9c4eb4..772e523f 100644 --- a/freebsd/lib/libc/rpc/svc_raw.c +++ b/freebsd/lib/libc/rpc/svc_raw.c @@ -84,7 +84,7 @@ static bool_t svc_raw_control(SVCXPRT *, const u_int, void *); char *__rpc_rawcombuf = NULL; SVCXPRT * -svc_raw_create() +svc_raw_create(void) { struct svc_raw_private *srp; /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */ @@ -127,17 +127,14 @@ svc_raw_create() /*ARGSUSED*/ static enum xprt_stat -svc_raw_stat(xprt) -SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */ +svc_raw_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } /*ARGSUSED*/ static bool_t -svc_raw_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_raw_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_raw_private *srp; XDR *xdrs; @@ -161,9 +158,7 @@ svc_raw_recv(xprt, msg) /*ARGSUSED*/ static bool_t -svc_raw_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_raw_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_raw_private *srp; XDR *xdrs; @@ -203,10 +198,7 @@ svc_raw_reply(xprt, msg) /*ARGSUSED*/ static bool_t -svc_raw_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_raw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct svc_raw_private *srp; @@ -224,10 +216,7 @@ svc_raw_getargs(xprt, xdr_args, args_ptr) /*ARGSUSED*/ static bool_t -svc_raw_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_raw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct svc_raw_private *srp; XDR *xdrs; @@ -247,24 +236,19 @@ svc_raw_freeargs(xprt, xdr_args, args_ptr) /*ARGSUSED*/ static void -svc_raw_destroy(xprt) -SVCXPRT *xprt; +svc_raw_destroy(SVCXPRT *xprt) { } /*ARGSUSED*/ static bool_t -svc_raw_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_raw_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static void -svc_raw_ops(xprt) - SVCXPRT *xprt; +svc_raw_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; diff --git a/freebsd/lib/libc/rpc/svc_run.c b/freebsd/lib/libc/rpc/svc_run.c index 85506c5c..4e6ed628 100644 --- a/freebsd/lib/libc/rpc/svc_run.c +++ b/freebsd/lib/libc/rpc/svc_run.c @@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$"); #include "mt_misc.h" void -svc_run() +svc_run(void) { fd_set readfds, cleanfds; struct timeval timeout; @@ -91,7 +91,7 @@ svc_run() * more work to do. */ void -svc_exit() +svc_exit(void) { rwlock_wrlock(&svc_fd_lock); FD_ZERO(&svc_fdset); diff --git a/freebsd/lib/libc/rpc/svc_simple.c b/freebsd/lib/libc/rpc/svc_simple.c index da3f1ebf..28da2898 100644 --- a/freebsd/lib/libc/rpc/svc_simple.c +++ b/freebsd/lib/libc/rpc/svc_simple.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); /* * This interface creates a virtual listener for all the services - * started thru rpc_reg(). It listens on the same endpoint for + * started through rpc_reg(). It listens on the same endpoint for * all the services and then executes the corresponding service * for the given prognum and procnum. */ @@ -94,16 +94,18 @@ static const char __no_mem_str[] = "out of memory"; * is also limited by the recvsize for that transport, even if it is * a COTS transport. This may be wrong, but for cases like these, they * should not use the simplified interfaces like this. + * + * prognum - program number + * versnum - version number + * procnum - procedure number + * progname - Server routine + * inproc, outproc - in/out XDR procedures + * nettype - nettype */ - int -rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) - rpcprog_t prognum; /* program number */ - rpcvers_t versnum; /* version number */ - rpcproc_t procnum; /* procedure number */ - char *(*progname)(char *); /* Server routine */ - xdrproc_t inproc, outproc; /* in/out XDR procedures */ - char *nettype; /* nettype */ +rpc_reg(rpcprog_t prognum, rpcvers_t versnum, rpcproc_t procnum, + char *(*progname)(char *), xdrproc_t inproc, xdrproc_t outproc, + char *nettype) { struct netconfig *nconf; int done = FALSE; @@ -166,10 +168,8 @@ rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) if (((xdrbuf = malloc((unsigned)recvsz)) == NULL) || ((netid = strdup(nconf->nc_netid)) == NULL)) { warnx(rpc_reg_err, rpc_reg_msg, __no_mem_str); - if (xdrbuf != NULL) - free(xdrbuf); - if (netid != NULL) - free(netid); + free(xdrbuf); + free(netid); SVC_DESTROY(svcxprt); break; } @@ -231,7 +231,7 @@ rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) mutex_unlock(&proglst_lock); if (done == FALSE) { - warnx("%s cant find suitable transport for %s", + warnx("%s can't find suitable transport for %s", rpc_reg_msg, nettype); return (-1); } @@ -244,9 +244,7 @@ rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) */ static void -universal(rqstp, transp) - struct svc_req *rqstp; - SVCXPRT *transp; +universal(struct svc_req *rqstp, SVCXPRT *transp) { rpcprog_t prog; rpcvers_t vers; @@ -276,7 +274,7 @@ universal(rqstp, transp) /* decode arguments into a CLEAN buffer */ xdrbuf = pl->p_xdrbuf; /* Zero the arguments: reqd ! */ - (void) memset(xdrbuf, 0, sizeof (pl->p_recvsz)); + (void) memset(xdrbuf, 0, (size_t)pl->p_recvsz); /* * Assuming that sizeof (xdrbuf) would be enough * for the arguments; if not then the program diff --git a/freebsd/lib/libc/rpc/svc_vc.c b/freebsd/lib/libc/rpc/svc_vc.c index 5b17ca4b..5b4c7bd3 100644 --- a/freebsd/lib/libc/rpc/svc_vc.c +++ b/freebsd/lib/libc/rpc/svc_vc.c @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include "reentrant.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <sys/poll.h> #include <sys/socket.h> @@ -125,12 +124,9 @@ struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ * 0 => use the system default. */ SVCXPRT * -svc_vc_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_vc_create(int fd, u_int sendsize, u_int recvsize) { - SVCXPRT *xprt; + SVCXPRT *xprt = NULL; struct cf_rendezvous *r = NULL; struct __rpc_sockinfo si; struct sockaddr_storage sslocal; @@ -188,10 +184,7 @@ cleanup_svc_vc_create: * descriptor as its first input. */ SVCXPRT * -svc_fd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_fd_create(int fd, u_int sendsize, u_int recvsize) { struct sockaddr_storage ss; socklen_t slen; @@ -245,10 +238,7 @@ freedata: } static SVCXPRT * -makefd_xprt(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +makefd_xprt(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct cf_conn *cd; @@ -274,7 +264,7 @@ makefd_xprt(fd, sendsize, recvsize) xprt, read_vc, write_vc); xprt->xp_p1 = cd; xprt->xp_verf.oa_base = cd->verf_body; - svc_vc_ops(xprt); /* truely deals with calls */ + svc_vc_ops(xprt); /* truly deals with calls */ xprt->xp_port = 0; /* this is a connection, not a rendezvouser */ xprt->xp_fd = fd; if (__rpc_fd2sockinfo(fd, &si) && __rpc_sockinfo2netid(&si, &netid)) @@ -287,15 +277,13 @@ done: /*ARGSUSED*/ static bool_t -rendezvous_request(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +rendezvous_request(SVCXPRT *xprt, struct rpc_msg *msg) { int sock, flags; struct cf_rendezvous *r; struct cf_conn *cd; - struct sockaddr_storage addr; - socklen_t len; + struct sockaddr_storage addr, sslocal; + socklen_t len, slen; struct __rpc_sockinfo si; SVCXPRT *newxprt; fd_set cleanfds; @@ -360,6 +348,20 @@ again: __xdrrec_setnonblock(&cd->xdrs, cd->maxrec); } else cd->nonblock = FALSE; + slen = sizeof(struct sockaddr_storage); + if(_getsockname(sock, (struct sockaddr *)(void *)&sslocal, &slen) < 0) { + warnx("svc_vc_create: could not retrieve local addr"); + newxprt->xp_ltaddr.maxlen = newxprt->xp_ltaddr.len = 0; + } else { + newxprt->xp_ltaddr.maxlen = newxprt->xp_ltaddr.len = sslocal.ss_len; + newxprt->xp_ltaddr.buf = mem_alloc((size_t)sslocal.ss_len); + if (newxprt->xp_ltaddr.buf == NULL) { + warnx("svc_vc_create: no mem for local addr"); + newxprt->xp_ltaddr.maxlen = newxprt->xp_ltaddr.len = 0; + } else { + memcpy(newxprt->xp_ltaddr.buf, &sslocal, (size_t)sslocal.ss_len); + } + } gettimeofday(&cd->last_recv_time, NULL); @@ -368,16 +370,14 @@ again: /*ARGSUSED*/ static enum xprt_stat -rendezvous_stat(xprt) - SVCXPRT *xprt; +rendezvous_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } static void -svc_vc_destroy(xprt) - SVCXPRT *xprt; +svc_vc_destroy(SVCXPRT *xprt) { assert(xprt != NULL); @@ -386,8 +386,7 @@ svc_vc_destroy(xprt) } static void -__svc_vc_dodestroy(xprt) - SVCXPRT *xprt; +__svc_vc_dodestroy(SVCXPRT *xprt) { struct cf_conn *cd; struct cf_rendezvous *r; @@ -410,28 +409,20 @@ __svc_vc_dodestroy(xprt) mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen); if (xprt->xp_ltaddr.buf) mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen); - if (xprt->xp_tp) - free(xprt->xp_tp); - if (xprt->xp_netid) - free(xprt->xp_netid); + free(xprt->xp_tp); + free(xprt->xp_netid); svc_xprt_free(xprt); } /*ARGSUSED*/ static bool_t -svc_vc_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static bool_t -svc_vc_rendezvous_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_rendezvous_control(SVCXPRT *xprt, const u_int rq, void *in) { struct cf_rendezvous *cfp; @@ -459,10 +450,7 @@ svc_vc_rendezvous_control(xprt, rq, in) * fatal for the connection. */ static int -read_vc(xprtp, buf, len) - void *xprtp; - void *buf; - int len; +read_vc(void *xprtp, void *buf, int len) { SVCXPRT *xprt; int sock; @@ -522,10 +510,7 @@ fatal_err: * Any error is fatal and the connection is closed. */ static int -write_vc(xprtp, buf, len) - void *xprtp; - void *buf; - int len; +write_vc(void *xprtp, void *buf, int len) { SVCXPRT *xprt; int i, cnt; @@ -569,8 +554,7 @@ write_vc(xprtp, buf, len) } static enum xprt_stat -svc_vc_stat(xprt) - SVCXPRT *xprt; +svc_vc_stat(SVCXPRT *xprt) { struct cf_conn *cd; @@ -586,9 +570,7 @@ svc_vc_stat(xprt) } static bool_t -svc_vc_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -616,10 +598,7 @@ svc_vc_recv(xprt, msg) } static bool_t -svc_vc_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_vc_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { struct cf_conn *cd; @@ -630,10 +609,7 @@ svc_vc_getargs(xprt, xdr_args, args_ptr) } static bool_t -svc_vc_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - void *args_ptr; +svc_vc_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, void *args_ptr) { XDR *xdrs; @@ -647,9 +623,7 @@ svc_vc_freeargs(xprt, xdr_args, args_ptr) } static bool_t -svc_vc_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -691,8 +665,7 @@ svc_vc_reply(xprt, msg) } static void -svc_vc_ops(xprt) - SVCXPRT *xprt; +svc_vc_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -715,8 +688,7 @@ svc_vc_ops(xprt) } static void -svc_vc_rendezvous_ops(xprt) - SVCXPRT *xprt; +svc_vc_rendezvous_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -730,7 +702,7 @@ svc_vc_rendezvous_ops(xprt) ops.xp_reply = (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort; ops.xp_freeargs = - (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort, + (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort; ops.xp_destroy = svc_vc_destroy; ops2.xp_control = svc_vc_rendezvous_control; } diff --git a/freebsd/lib/libc/stdio/fgetln.c b/freebsd/lib/libc/stdio/fgetln.c index 1a7b0514..7d9f6a53 100644 --- a/freebsd/lib/libc/stdio/fgetln.c +++ b/freebsd/lib/libc/stdio/fgetln.c @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -39,6 +39,8 @@ static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; __FBSDID("$FreeBSD$"); #include "namespace.h" +#include <errno.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -63,6 +65,10 @@ __slbexpand(FILE *fp, size_t newsize) #endif if (fp->_lb._size >= newsize) return (0); + if (newsize > INT_MAX) { + errno = ENOMEM; + return (-1); + } if ((p = realloc(fp->_lb._base, newsize)) == NULL) return (-1); fp->_lb._base = p; @@ -119,7 +125,7 @@ fgetln(FILE *fp, size_t *lenp) * As a bonus, though, we can leave off the __SMOD. * * OPTIMISTIC is length that we (optimistically) expect will - * accomodate the `rest' of the string, on each trip through the + * accommodate the `rest' of the string, on each trip through the * loop below. */ #define OPTIMISTIC 80 @@ -156,13 +162,14 @@ fgetln(FILE *fp, size_t *lenp) } *lenp = len; #ifdef notdef - fp->_lb._base[len] = 0; + fp->_lb._base[len] = '\0'; #endif FUNLOCKFILE(fp); return ((char *)fp->_lb._base); error: *lenp = 0; /* ??? */ + fp->_flags |= __SERR; FUNLOCKFILE(fp); return (NULL); /* ??? */ } diff --git a/freebsd/lib/libc/stdio/local.h b/freebsd/lib/libc/stdio/local.h index a9994b5f..664ca3b3 100644 --- a/freebsd/lib/libc/stdio/local.h +++ b/freebsd/lib/libc/stdio/local.h @@ -56,8 +56,8 @@ extern int _ftello(FILE *, fpos_t *); extern int _fseeko(FILE *, off_t, int, int); extern int __fflush(FILE *fp); extern void __fcloseall(void); +extern wint_t __fgetwc_mbs(FILE *, mbstate_t *, int *, locale_t); #ifndef __rtems__ -extern wint_t __fgetwc(FILE *, locale_t); extern wint_t __fputwc(wchar_t, FILE *, locale_t); #endif /* __rtems__ */ extern int __sflush(FILE *); @@ -104,6 +104,13 @@ extern size_t __fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp); extern int __sdidinit; +static inline wint_t +__fgetwc(FILE *fp, locale_t locale) +{ + int nread; + + return (__fgetwc_mbs(fp, &fp->_mbstate, &nread, locale)); +} /* * Prepare the given FILE for writing, and return 0 iff it diff --git a/freebsd/lib/libc/stdlib/strtoimax.c b/freebsd/lib/libc/stdlib/strtoimax.c index d7103b3a..e8a4f455 100644 --- a/freebsd/lib/libc/stdlib/strtoimax.c +++ b/freebsd/lib/libc/stdlib/strtoimax.c @@ -17,7 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/freebsd/lib/libc/stdlib/strtonum.c b/freebsd/lib/libc/stdlib/strtonum.c index c55cb7d7..528380b7 100644 --- a/freebsd/lib/libc/stdlib/strtonum.c +++ b/freebsd/lib/libc/stdlib/strtonum.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ + * $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */ #include <sys/cdefs.h> @@ -26,17 +26,17 @@ __FBSDID("$FreeBSD$"); #include <limits.h> #include <stdlib.h> -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 +#define INVALID 1 +#define TOOSMALL 2 +#define TOOLARGE 3 long long strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp) { long long ll = 0; - char *ep; int error = 0; + char *ep; struct errval { const char *errstr; int err; @@ -49,9 +49,9 @@ strtonum(const char *numstr, long long minval, long long maxval, ev[0].err = errno; errno = 0; - if (minval > maxval) + if (minval > maxval) { error = INVALID; - else { + } else { ll = strtoll(numstr, &ep, 10); if (errno == EINVAL || numstr == ep || *ep != '\0') error = INVALID; diff --git a/freebsd/lib/libc/stdlib/strtoumax.c b/freebsd/lib/libc/stdlib/strtoumax.c index 4098ce81..e16dbf47 100644 --- a/freebsd/lib/libc/stdlib/strtoumax.c +++ b/freebsd/lib/libc/stdlib/strtoumax.c @@ -17,7 +17,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/freebsd/lib/libc/string/strsep.c b/freebsd/lib/libc/string/strsep.c index e2560e95..221eda29 100644 --- a/freebsd/lib/libc/string/strsep.c +++ b/freebsd/lib/libc/string/strsep.c @@ -12,7 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/freebsd/lib/libc/xdr/xdr.c b/freebsd/lib/libc/xdr/xdr.c index 561f179b..c529bb95 100644 --- a/freebsd/lib/libc/xdr/xdr.c +++ b/freebsd/lib/libc/xdr/xdr.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr.c,v 1.22 2000/07/06 03:10:35 christos Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,8 +43,6 @@ __FBSDID("$FreeBSD$"); /* * xdr.c, Generic XDR routines implementation. * - * Copyright (C) 1986, Sun Microsystems, Inc. - * * These are the "generic" xdr routines used to serialize and de-serialize * most common data items. See xdr.h for more info on the interface to * xdr. @@ -78,9 +78,7 @@ static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 }; * Not a filter, but a convenient utility nonetheless */ void -xdr_free(proc, objp) - xdrproc_t proc; - void *objp; +xdr_free(xdrproc_t proc, void *objp) { XDR x; @@ -103,9 +101,7 @@ xdr_void(void) * XDR integers */ bool_t -xdr_int(xdrs, ip) - XDR *xdrs; - int *ip; +xdr_int(XDR *xdrs, int *ip) { long l; @@ -133,9 +129,7 @@ xdr_int(xdrs, ip) * XDR unsigned integers */ bool_t -xdr_u_int(xdrs, up) - XDR *xdrs; - u_int *up; +xdr_u_int(XDR *xdrs, u_int *up) { u_long l; @@ -165,9 +159,7 @@ xdr_u_int(xdrs, up) * same as xdr_u_long - open coded to save a proc call! */ bool_t -xdr_long(xdrs, lp) - XDR *xdrs; - long *lp; +xdr_long(XDR *xdrs, long *lp) { switch (xdrs->x_op) { case XDR_ENCODE: @@ -186,9 +178,7 @@ xdr_long(xdrs, lp) * same as xdr_long - open coded to save a proc call! */ bool_t -xdr_u_long(xdrs, ulp) - XDR *xdrs; - u_long *ulp; +xdr_u_long(XDR *xdrs, u_long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: @@ -208,9 +198,7 @@ xdr_u_long(xdrs, ulp) * same as xdr_u_int32_t - open coded to save a proc call! */ bool_t -xdr_int32_t(xdrs, int32_p) - XDR *xdrs; - int32_t *int32_p; +xdr_int32_t(XDR *xdrs, int32_t *int32_p) { long l; @@ -239,9 +227,7 @@ xdr_int32_t(xdrs, int32_p) * same as xdr_int32_t - open coded to save a proc call! */ bool_t -xdr_u_int32_t(xdrs, u_int32_p) - XDR *xdrs; - u_int32_t *u_int32_p; +xdr_u_int32_t(XDR *xdrs, u_int32_t *u_int32_p) { u_long l; @@ -270,9 +256,7 @@ xdr_u_int32_t(xdrs, u_int32_p) * same as xdr_int32_t - open coded to save a proc call! */ bool_t -xdr_uint32_t(xdrs, u_int32_p) - XDR *xdrs; - uint32_t *u_int32_p; +xdr_uint32_t(XDR *xdrs, uint32_t *u_int32_p) { u_long l; @@ -300,9 +284,7 @@ xdr_uint32_t(xdrs, u_int32_p) * XDR short integers */ bool_t -xdr_short(xdrs, sp) - XDR *xdrs; - short *sp; +xdr_short(XDR *xdrs, short *sp) { long l; @@ -330,9 +312,7 @@ xdr_short(xdrs, sp) * XDR unsigned short integers */ bool_t -xdr_u_short(xdrs, usp) - XDR *xdrs; - u_short *usp; +xdr_u_short(XDR *xdrs, u_short *usp) { u_long l; @@ -361,9 +341,7 @@ xdr_u_short(xdrs, usp) * XDR 16-bit integers */ bool_t -xdr_int16_t(xdrs, int16_p) - XDR *xdrs; - int16_t *int16_p; +xdr_int16_t(XDR *xdrs, int16_t *int16_p) { long l; @@ -391,9 +369,7 @@ xdr_int16_t(xdrs, int16_p) * XDR unsigned 16-bit integers */ bool_t -xdr_u_int16_t(xdrs, u_int16_p) - XDR *xdrs; - u_int16_t *u_int16_p; +xdr_u_int16_t(XDR *xdrs, u_int16_t *u_int16_p) { u_long l; @@ -421,9 +397,7 @@ xdr_u_int16_t(xdrs, u_int16_p) * XDR unsigned 16-bit integers */ bool_t -xdr_uint16_t(xdrs, u_int16_p) - XDR *xdrs; - uint16_t *u_int16_p; +xdr_uint16_t(XDR *xdrs, uint16_t *u_int16_p) { u_long l; @@ -452,9 +426,7 @@ xdr_uint16_t(xdrs, u_int16_p) * XDR a char */ bool_t -xdr_char(xdrs, cp) - XDR *xdrs; - char *cp; +xdr_char(XDR *xdrs, char *cp) { int i; @@ -470,9 +442,7 @@ xdr_char(xdrs, cp) * XDR an unsigned char */ bool_t -xdr_u_char(xdrs, cp) - XDR *xdrs; - u_char *cp; +xdr_u_char(XDR *xdrs, u_char *cp) { u_int u; @@ -488,9 +458,7 @@ xdr_u_char(xdrs, cp) * XDR booleans */ bool_t -xdr_bool(xdrs, bp) - XDR *xdrs; - bool_t *bp; +xdr_bool(XDR *xdrs, bool_t *bp) { long lb; @@ -518,9 +486,7 @@ xdr_bool(xdrs, bp) * XDR enumerations */ bool_t -xdr_enum(xdrs, ep) - XDR *xdrs; - enum_t *ep; +xdr_enum(XDR *xdrs, enum_t *ep) { /* * enums are treated as ints @@ -542,10 +508,7 @@ xdr_enum(xdrs, ep) * cp points to the opaque object and cnt gives the byte length. */ bool_t -xdr_opaque(xdrs, cp, cnt) - XDR *xdrs; - caddr_t cp; - u_int cnt; +xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt) { u_int rndup; static int crud[BYTES_PER_XDR_UNIT]; @@ -594,11 +557,7 @@ xdr_opaque(xdrs, cp, cnt) * If *cpp is NULL maxsize bytes are allocated */ bool_t -xdr_bytes(xdrs, cpp, sizep, maxsize) - XDR *xdrs; - char **cpp; - u_int *sizep; - u_int maxsize; +xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) { char *sp = *cpp; /* sp is the actual string pointer */ u_int nodesize; @@ -650,9 +609,7 @@ xdr_bytes(xdrs, cpp, sizep, maxsize) * Implemented here due to commonality of the object. */ bool_t -xdr_netobj(xdrs, np) - XDR *xdrs; - struct netobj *np; +xdr_netobj(XDR *xdrs, struct netobj *np) { return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ)); @@ -670,12 +627,14 @@ xdr_netobj(xdrs, np) * If there is no specific or default routine an error is returned. */ bool_t -xdr_union(xdrs, dscmp, unp, choices, dfault) - XDR *xdrs; - enum_t *dscmp; /* enum to decide which arm to work on */ - char *unp; /* the union itself */ - const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */ - xdrproc_t dfault; /* default xdr routine */ +xdr_union(XDR *xdrs, enum_t *dscmp, char *unp, const struct xdr_discrim *choices, xdrproc_t dfault) +/* + * XDR *xdrs; + * enum_t *dscmp; // enum to decide which arm to work on + * char *unp; // the union itself + * const struct xdr_discrim *choices; // [value, xdr proc] for each arm + * xdrproc_t dfault; // default xdr routine + */ { enum_t dscm; @@ -719,10 +678,7 @@ xdr_union(xdrs, dscmp, unp, choices, dfault) * of the string as specified by a protocol. */ bool_t -xdr_string(xdrs, cpp, maxsize) - XDR *xdrs; - char **cpp; - u_int maxsize; +xdr_string(XDR *xdrs, char **cpp, u_int maxsize) { char *sp = *cpp; /* sp is the actual string pointer */ u_int size; @@ -786,9 +742,7 @@ xdr_string(xdrs, cpp, maxsize) * routines like clnt_call */ bool_t -xdr_wrapstring(xdrs, cpp) - XDR *xdrs; - char **cpp; +xdr_wrapstring(XDR *xdrs, char **cpp) { return xdr_string(xdrs, cpp, LASTUNSIGNED); } @@ -805,9 +759,7 @@ xdr_wrapstring(xdrs, cpp) * XDR 64-bit integers */ bool_t -xdr_int64_t(xdrs, llp) - XDR *xdrs; - int64_t *llp; +xdr_int64_t(XDR *xdrs, int64_t *llp) { u_long ul[2]; @@ -838,9 +790,7 @@ xdr_int64_t(xdrs, llp) * XDR unsigned 64-bit integers */ bool_t -xdr_u_int64_t(xdrs, ullp) - XDR *xdrs; - u_int64_t *ullp; +xdr_u_int64_t(XDR *xdrs, u_int64_t *ullp) { u_long ul[2]; @@ -870,9 +820,7 @@ xdr_u_int64_t(xdrs, ullp) * XDR unsigned 64-bit integers */ bool_t -xdr_uint64_t(xdrs, ullp) - XDR *xdrs; - uint64_t *ullp; +xdr_uint64_t(XDR *xdrs, uint64_t *ullp) { u_long ul[2]; @@ -903,9 +851,7 @@ xdr_uint64_t(xdrs, ullp) * XDR hypers */ bool_t -xdr_hyper(xdrs, llp) - XDR *xdrs; - longlong_t *llp; +xdr_hyper(XDR *xdrs, longlong_t *llp) { /* @@ -920,9 +866,7 @@ xdr_hyper(xdrs, llp) * XDR unsigned hypers */ bool_t -xdr_u_hyper(xdrs, ullp) - XDR *xdrs; - u_longlong_t *ullp; +xdr_u_hyper(XDR *xdrs, u_longlong_t *ullp) { /* @@ -937,9 +881,7 @@ xdr_u_hyper(xdrs, ullp) * XDR longlong_t's */ bool_t -xdr_longlong_t(xdrs, llp) - XDR *xdrs; - longlong_t *llp; +xdr_longlong_t(XDR *xdrs, longlong_t *llp) { /* @@ -954,9 +896,7 @@ xdr_longlong_t(xdrs, llp) * XDR u_longlong_t's */ bool_t -xdr_u_longlong_t(xdrs, ullp) - XDR *xdrs; - u_longlong_t *ullp; +xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp) { /* diff --git a/freebsd/lib/libc/xdr/xdr_array.c b/freebsd/lib/libc/xdr/xdr_array.c index eb0eefa0..2b9fa580 100644 --- a/freebsd/lib/libc/xdr/xdr_array.c +++ b/freebsd/lib/libc/xdr/xdr_array.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_array.c,v 1.12 2000/01/22 22:19:18 mycroft Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,8 +43,6 @@ __FBSDID("$FreeBSD$"); /* * xdr_array.c, Generic XDR routines impelmentation. * - * Copyright (C) 1984, Sun Microsystems, Inc. - * * These are the "non-trivial" xdr primitives used to serialize and de-serialize * arrays. See xdr.h for more info on the interface to xdr. */ @@ -66,13 +66,15 @@ __FBSDID("$FreeBSD$"); * xdr procedure to call to handle each element of the array. */ bool_t -xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc) - XDR *xdrs; - caddr_t *addrp; /* array pointer */ - u_int *sizep; /* number of elements */ - u_int maxsize; /* max numberof elements */ - u_int elsize; /* size in bytes of each element */ - xdrproc_t elproc; /* xdr routine to handle each element */ +xdr_array(XDR *xdrs, caddr_t *addrp, u_int *sizep, u_int maxsize, u_int elsize, xdrproc_t elproc) +/* + * XDR *xdrs; + * caddr_t *addrp; // array pointer + * u_int *sizep; // number of elements + * u_int maxsize; // max numberof elements + * u_int elsize; // size in bytes of each element + * xdrproc_t elproc; // xdr routine to handle each element + */ { u_int i; caddr_t target = *addrp; @@ -144,12 +146,7 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc) * > xdr_elem: routine to XDR each element */ bool_t -xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem) - XDR *xdrs; - char *basep; - u_int nelem; - u_int elemsize; - xdrproc_t xdr_elem; +xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) { u_int i; char *elptr; diff --git a/freebsd/lib/libc/xdr/xdr_float.c b/freebsd/lib/libc/xdr/xdr_float.c index 4ff153b3..3c99f192 100644 --- a/freebsd/lib/libc/xdr/xdr_float.c +++ b/freebsd/lib/libc/xdr/xdr_float.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_float.c,v 1.23 2000/07/17 04:59:51 matt Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,15 +43,12 @@ __FBSDID("$FreeBSD$"); /* * xdr_float.c, Generic XDR routines implementation. * - * Copyright (C) 1984, Sun Microsystems, Inc. - * * These are the "floating point" xdr routines used to (de)serialize * most common data items. See xdr.h for more info on the interface to * xdr. */ #include "namespace.h" -#include <sys/types.h> #include <rtems/bsd/sys/param.h> #include <stdio.h> @@ -63,16 +62,8 @@ __FBSDID("$FreeBSD$"); * This routine works on machines with IEEE754 FP and Vaxen. */ -#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ - defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \ - defined(__arm__) || defined(__ppc__) || defined(__ia64__) || \ - defined(__arm26__) || defined(__sparc64__) || defined(__amd64__) #include <machine/endian.h> #define IEEEFP -#else /* __rtems__ */ -#include <machine/endian.h> -#define IEEEFP -#endif #if defined(__vax__) @@ -106,15 +97,13 @@ static struct sgl_limits { #endif /* vax */ bool_t -xdr_float(xdrs, fp) - XDR *xdrs; - float *fp; +xdr_float(XDR *xdrs, float *fp) { #ifndef IEEEFP struct ieee_single is; struct vax_single vs, *vsp; struct sgl_limits *lim; - int i; + u_int i; #endif switch (xdrs->x_op) { @@ -123,9 +112,8 @@ xdr_float(xdrs, fp) return (XDR_PUTINT32(xdrs, (int32_t *)fp)); #else vs = *((struct vax_single *)fp); - for (i = 0, lim = sgl_limits; - i < sizeof(sgl_limits)/sizeof(struct sgl_limits); - i++, lim++) { + for (i = 0, lim = sgl_limits; i < nitems(sgl_limits); + i++, lim++) { if ((vs.mantissa2 == lim->s.mantissa2) && (vs.exp == lim->s.exp) && (vs.mantissa1 == lim->s.mantissa1)) { @@ -147,9 +135,8 @@ xdr_float(xdrs, fp) vsp = (struct vax_single *)fp; if (!XDR_GETINT32(xdrs, (int32_t *)&is)) return (FALSE); - for (i = 0, lim = sgl_limits; - i < sizeof(sgl_limits)/sizeof(struct sgl_limits); - i++, lim++) { + for (i = 0, lim = sgl_limits; i < nitems(sgl_limits); + i++, lim++) { if ((is.exp == lim->ieee.exp) && (is.mantissa == lim->ieee.mantissa)) { *vsp = lim->s; @@ -208,9 +195,7 @@ static struct dbl_limits { bool_t -xdr_double(xdrs, dp) - XDR *xdrs; - double *dp; +xdr_double(XDR *xdrs, double *dp) { #ifdef IEEEFP int32_t *i32p; @@ -220,7 +205,7 @@ xdr_double(xdrs, dp) struct ieee_double id; struct vax_double vd; struct dbl_limits *lim; - int i; + u_int i; #endif switch (xdrs->x_op) { @@ -242,9 +227,8 @@ xdr_double(xdrs, dp) return (rv); #else vd = *((struct vax_double *)dp); - for (i = 0, lim = dbl_limits; - i < sizeof(dbl_limits)/sizeof(struct dbl_limits); - i++, lim++) { + for (i = 0, lim = dbl_limits; i < nitems(dbl_limits); + i++, lim++) { if ((vd.mantissa4 == lim->d.mantissa4) && (vd.mantissa3 == lim->d.mantissa3) && (vd.mantissa2 == lim->d.mantissa2) && @@ -284,9 +268,8 @@ xdr_double(xdrs, dp) lp = (int32_t *)&id; if (!XDR_GETINT32(xdrs, lp++) || !XDR_GETINT32(xdrs, lp)) return (FALSE); - for (i = 0, lim = dbl_limits; - i < sizeof(dbl_limits)/sizeof(struct dbl_limits); - i++, lim++) { + for (i = 0, lim = dbl_limits; i < nitems(dbl_limits); + i++, lim++) { if ((id.mantissa2 == lim->ieee.mantissa2) && (id.mantissa1 == lim->ieee.mantissa1) && (id.exp == lim->ieee.exp)) { diff --git a/freebsd/lib/libc/xdr/xdr_mem.c b/freebsd/lib/libc/xdr/xdr_mem.c index c97e752f..c7dafbae 100644 --- a/freebsd/lib/libc/xdr/xdr_mem.c +++ b/freebsd/lib/libc/xdr/xdr_mem.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_mem.c,v 1.15 2000/01/22 22:19:18 mycroft Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,8 +43,6 @@ __FBSDID("$FreeBSD$"); /* * xdr_mem.h, XDR implementation using memory buffers. * - * Copyright (C) 1984, Sun Microsystems, Inc. - * * If you have some data to be interpreted as external data representation * or to be converted to external data representation in a memory buffer, * then this is the package for you. @@ -100,11 +100,7 @@ static const struct xdr_ops xdrmem_ops_unaligned = { * memory buffer. */ void -xdrmem_create(xdrs, addr, size, op) - XDR *xdrs; - char *addr; - u_int size; - enum xdr_op op; +xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op) { xdrs->x_op = op; @@ -116,16 +112,13 @@ xdrmem_create(xdrs, addr, size, op) /*ARGSUSED*/ static void -xdrmem_destroy(xdrs) - XDR *xdrs; +xdrmem_destroy(XDR *xdrs) { } static bool_t -xdrmem_getlong_aligned(xdrs, lp) - XDR *xdrs; - long *lp; +xdrmem_getlong_aligned(XDR *xdrs, long *lp) { if (xdrs->x_handy < sizeof(int32_t)) @@ -137,9 +130,7 @@ xdrmem_getlong_aligned(xdrs, lp) } static bool_t -xdrmem_putlong_aligned(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrmem_putlong_aligned(XDR *xdrs, const long *lp) { if (xdrs->x_handy < sizeof(int32_t)) @@ -151,9 +142,7 @@ xdrmem_putlong_aligned(xdrs, lp) } static bool_t -xdrmem_getlong_unaligned(xdrs, lp) - XDR *xdrs; - long *lp; +xdrmem_getlong_unaligned(XDR *xdrs, long *lp) { u_int32_t l; @@ -167,9 +156,7 @@ xdrmem_getlong_unaligned(xdrs, lp) } static bool_t -xdrmem_putlong_unaligned(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrmem_putlong_unaligned(XDR *xdrs, const long *lp) { u_int32_t l; @@ -183,10 +170,7 @@ xdrmem_putlong_unaligned(xdrs, lp) } static bool_t -xdrmem_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrmem_getbytes(XDR *xdrs, char *addr, u_int len) { if (xdrs->x_handy < len) @@ -198,10 +182,7 @@ xdrmem_getbytes(xdrs, addr, len) } static bool_t -xdrmem_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrmem_putbytes(XDR *xdrs, const char *addr, u_int len) { if (xdrs->x_handy < len) @@ -213,8 +194,7 @@ xdrmem_putbytes(xdrs, addr, len) } static u_int -xdrmem_getpos(xdrs) - XDR *xdrs; +xdrmem_getpos(XDR *xdrs) { /* XXX w/64-bit pointers, u_int not enough! */ @@ -222,9 +202,7 @@ xdrmem_getpos(xdrs) } static bool_t -xdrmem_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrmem_setpos(XDR *xdrs, u_int pos) { char *newaddr = xdrs->x_base + pos; char *lastaddr = (char *)xdrs->x_private + xdrs->x_handy; @@ -237,11 +215,9 @@ xdrmem_setpos(xdrs, pos) } static int32_t * -xdrmem_inline_aligned(xdrs, len) - XDR *xdrs; - u_int len; +xdrmem_inline_aligned(XDR *xdrs, u_int len) { - int32_t *buf = 0; + int32_t *buf = NULL; if (xdrs->x_handy >= len) { xdrs->x_handy -= len; @@ -253,9 +229,7 @@ xdrmem_inline_aligned(xdrs, len) /* ARGSUSED */ static int32_t * -xdrmem_inline_unaligned(xdrs, len) - XDR *xdrs; - u_int len; +xdrmem_inline_unaligned(XDR *xdrs, u_int len) { return (0); diff --git a/freebsd/lib/libc/xdr/xdr_rec.c b/freebsd/lib/libc/xdr/xdr_rec.c index a204b44b..a7eb890e 100644 --- a/freebsd/lib/libc/xdr/xdr_rec.c +++ b/freebsd/lib/libc/xdr/xdr_rec.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_rec.c,v 1.18 2000/07/06 03:10:35 christos Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -42,8 +44,6 @@ __FBSDID("$FreeBSD$"); * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking" * layer above tcp (for rpc's use). * - * Copyright (C) 1984, Sun Microsystems, Inc. - * * These routines interface XDRSTREAMS to a tcp/ip connection. * There is a record marking layer between the xdr stream * and the tcp transport level. A record is composed on one or more @@ -108,7 +108,7 @@ static const struct xdr_ops xdrrec_ops = { * meet the needs of xdr and rpc based on tcp. */ -#define LAST_FRAG ((u_int32_t)(1 << 31)) +#define LAST_FRAG ((u_int32_t)(1U << 31)) typedef struct rec_strm { char *tcp_handle; @@ -163,15 +163,18 @@ static bool_t realloc_stream(RECSTREAM *, int); * calls expect that they take an opaque handle rather than an fd. */ void -xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) - XDR *xdrs; - u_int sendsize; - u_int recvsize; - void *tcp_handle; - /* like read, but pass it a tcp_handle, not sock */ - int (*readit)(void *, void *, int); - /* like write, but pass it a tcp_handle, not sock */ - int (*writeit)(void *, void *, int); +xdrrec_create(XDR *xdrs, u_int sendsize, u_int recvsize, void *tcp_handle, + int (*readit)(void *, void *, int), int (*writeit)(void *, void *, int)) +/* + * XDR *xdrs; + * u_int sendsize; + * u_int recvsize; + * void *tcp_handle; + * // like read, but pass it a tcp_handle, not sock + * int (*readit)(void *, void *, int); + * // like write, but pass it a tcp_handle, not sock + * int (*writeit)(void *, void *, int); + */ { RECSTREAM *rstrm = mem_alloc(sizeof(RECSTREAM)); @@ -231,9 +234,7 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) */ static bool_t -xdrrec_getlong(xdrs, lp) - XDR *xdrs; - long *lp; +xdrrec_getlong(XDR *xdrs, long *lp) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); int32_t *buflp = (int32_t *)(void *)(rstrm->in_finger); @@ -255,9 +256,7 @@ xdrrec_getlong(xdrs, lp) } static bool_t -xdrrec_putlong(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrrec_putlong(XDR *xdrs, const long *lp) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); int32_t *dest_lp = ((int32_t *)(void *)(rstrm->out_finger)); @@ -279,10 +278,7 @@ xdrrec_putlong(xdrs, lp) } static bool_t /* must manage buffers, fragments, and records */ -xdrrec_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrrec_getbytes(XDR *xdrs, char *addr, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); int current; @@ -307,10 +303,7 @@ xdrrec_getbytes(xdrs, addr, len) } static bool_t -xdrrec_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrrec_putbytes(XDR *xdrs, const char *addr, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); size_t current; @@ -333,8 +326,7 @@ xdrrec_putbytes(xdrs, addr, len) } static u_int -xdrrec_getpos(xdrs) - XDR *xdrs; +xdrrec_getpos(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; off_t pos; @@ -360,9 +352,7 @@ xdrrec_getpos(xdrs) } static bool_t -xdrrec_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrrec_setpos(XDR *xdrs, u_int pos) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; u_int currpos = xdrrec_getpos(xdrs); @@ -399,9 +389,7 @@ xdrrec_setpos(xdrs, pos) } static int32_t * -xdrrec_inline(xdrs, len) - XDR *xdrs; - u_int len; +xdrrec_inline(XDR *xdrs, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; int32_t *buf = NULL; @@ -431,8 +419,7 @@ xdrrec_inline(xdrs, len) } static void -xdrrec_destroy(xdrs) - XDR *xdrs; +xdrrec_destroy(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; @@ -451,8 +438,7 @@ xdrrec_destroy(xdrs) * this procedure to guarantee proper record alignment. */ bool_t -xdrrec_skiprecord(xdrs) - XDR *xdrs; +xdrrec_skiprecord(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); enum xprt_stat xstat; @@ -487,8 +473,7 @@ xdrrec_skiprecord(xdrs) * after consuming the rest of the current record. */ bool_t -xdrrec_eof(xdrs) - XDR *xdrs; +xdrrec_eof(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); @@ -511,9 +496,7 @@ xdrrec_eof(xdrs) * pipelined procedure calls.) TRUE => immmediate flush to tcp connection. */ bool_t -xdrrec_endofrecord(xdrs, sendnow) - XDR *xdrs; - int sendnow; +xdrrec_endofrecord(XDR *xdrs, bool_t sendnow) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); u_long len; /* fragment length */ @@ -537,10 +520,7 @@ xdrrec_endofrecord(xdrs, sendnow) * Return true if a record is available in the buffer, false if not. */ bool_t -__xdrrec_getrec(xdrs, statp, expectdata) - XDR *xdrs; - enum xprt_stat *statp; - bool_t expectdata; +__xdrrec_getrec(XDR *xdrs, enum xprt_stat *statp, bool_t expectdata) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); ssize_t n; @@ -620,9 +600,7 @@ __xdrrec_getrec(xdrs, statp, expectdata) } bool_t -__xdrrec_setnonblock(xdrs, maxrec) - XDR *xdrs; - int maxrec; +__xdrrec_setnonblock(XDR *xdrs, int maxrec) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); @@ -637,9 +615,7 @@ __xdrrec_setnonblock(xdrs, maxrec) * Internal useful routines */ static bool_t -flush_out(rstrm, eor) - RECSTREAM *rstrm; - bool_t eor; +flush_out(RECSTREAM *rstrm, bool_t eor) { u_int32_t eormask = (eor == TRUE) ? LAST_FRAG : 0; u_int32_t len = (u_int32_t)((u_long)(rstrm->out_finger) - @@ -657,8 +633,7 @@ flush_out(rstrm, eor) } static bool_t /* knows nothing about records! Only about input buffers */ -fill_input_buf(rstrm) - RECSTREAM *rstrm; +fill_input_buf(RECSTREAM *rstrm) { char *where; u_int32_t i; @@ -680,10 +655,7 @@ fill_input_buf(rstrm) } static bool_t /* knows nothing about records! Only about input buffers */ -get_input_bytes(rstrm, addr, len) - RECSTREAM *rstrm; - char *addr; - int len; +get_input_bytes(RECSTREAM *rstrm, char *addr, int len) { size_t current; @@ -713,8 +685,7 @@ get_input_bytes(rstrm, addr, len) } static bool_t /* next two bytes of the input stream are treated as a header */ -set_input_fragment(rstrm) - RECSTREAM *rstrm; +set_input_fragment(RECSTREAM *rstrm) { u_int32_t header; @@ -739,9 +710,7 @@ set_input_fragment(rstrm) } static bool_t /* consumes input bytes; knows nothing about records! */ -skip_input_bytes(rstrm, cnt) - RECSTREAM *rstrm; - long cnt; +skip_input_bytes(RECSTREAM *rstrm, long cnt) { u_int32_t current; @@ -761,8 +730,7 @@ skip_input_bytes(rstrm, cnt) } static u_int -fix_buf_size(s) - u_int s; +fix_buf_size(u_int s) { if (s < 100) @@ -774,9 +742,7 @@ fix_buf_size(s) * Reallocate the input buffer for a non-block stream. */ static bool_t -realloc_stream(rstrm, size) - RECSTREAM *rstrm; - int size; +realloc_stream(RECSTREAM *rstrm, int size) { ptrdiff_t diff; char *buf; diff --git a/freebsd/lib/libc/xdr/xdr_reference.c b/freebsd/lib/libc/xdr/xdr_reference.c index 44615daa..1c9dc5e5 100644 --- a/freebsd/lib/libc/xdr/xdr_reference.c +++ b/freebsd/lib/libc/xdr/xdr_reference.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_reference.c,v 1.13 2000/01/22 22:19:18 mycroft Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,8 +43,6 @@ __FBSDID("$FreeBSD$"); /* * xdr_reference.c, Generic XDR routines impelmentation. * - * Copyright (C) 1987, Sun Microsystems, Inc. - * * These are the "non-trivial" xdr primitives used to serialize and de-serialize * "pointers". See xdr.h for more info on the interface to xdr. */ @@ -67,11 +67,13 @@ __FBSDID("$FreeBSD$"); * proc is the routine to handle the referenced structure. */ bool_t -xdr_reference(xdrs, pp, size, proc) - XDR *xdrs; - caddr_t *pp; /* the pointer to work on */ - u_int size; /* size of the object pointed to */ - xdrproc_t proc; /* xdr routine to handle the object */ +xdr_reference(XDR *xdrs, caddr_t *pp, u_int size, xdrproc_t proc) +/* + * XDR *xdrs; + * caddr_t *pp; // the pointer to work on + * u_int size; // size of the object pointed to + * xdrproc_t proc; // xdr routine to handle the object + */ { caddr_t loc = *pp; bool_t stat; @@ -124,11 +126,7 @@ xdr_reference(xdrs, pp, size, proc) * */ bool_t -xdr_pointer(xdrs,objpp,obj_size,xdr_obj) - XDR *xdrs; - char **objpp; - u_int obj_size; - xdrproc_t xdr_obj; +xdr_pointer(XDR *xdrs, char **objpp, u_int obj_size, xdrproc_t xdr_obj) { bool_t more_data; diff --git a/freebsd/lib/libc/xdr/xdr_sizeof.c b/freebsd/lib/libc/xdr/xdr_sizeof.c index dc401400..4e669cbe 100644 --- a/freebsd/lib/libc/xdr/xdr_sizeof.c +++ b/freebsd/lib/libc/xdr/xdr_sizeof.c @@ -1,38 +1,38 @@ #include <machine/rtems-bsd-user-space.h> -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 +/*- + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * xdr_sizeof.c * - * Copyright 1990 Sun Microsystems, Inc. - * * General purpose routine to see how much space something will use * when serialized using XDR. */ @@ -49,9 +49,7 @@ __FBSDID("$FreeBSD$"); /* ARGSUSED */ static bool_t -x_putlong(xdrs, longp) - XDR *xdrs; - long *longp; +x_putlong(XDR *xdrs, const long *longp) { xdrs->x_handy += BYTES_PER_XDR_UNIT; return (TRUE); @@ -59,36 +57,28 @@ x_putlong(xdrs, longp) /* ARGSUSED */ static bool_t -x_putbytes(xdrs, bp, len) - XDR *xdrs; - char *bp; - u_int len; +x_putbytes(XDR *xdrs, const char *bp, u_int len) { xdrs->x_handy += len; return (TRUE); } static u_int -x_getpostn(xdrs) - XDR *xdrs; +x_getpostn(XDR *xdrs) { return (xdrs->x_handy); } /* ARGSUSED */ static bool_t -x_setpostn(xdrs, pos) - XDR *xdrs; - u_int pos; +x_setpostn(XDR *xdrs, u_int pos) { /* This is not allowed */ return (FALSE); } static int32_t * -x_inline(xdrs, len) - XDR *xdrs; - u_int len; +x_inline(XDR *xdrs, u_int len) { if (len == 0) { return (NULL); @@ -115,15 +105,14 @@ x_inline(xdrs, len) } static int -harmless() +harmless(void) { /* Always return FALSE/NULL, as the case may be */ return (0); } static void -x_destroy(xdrs) - XDR *xdrs; +x_destroy(XDR *xdrs) { xdrs->x_handy = 0; xdrs->x_base = 0; @@ -135,9 +124,7 @@ x_destroy(xdrs) } unsigned long -xdr_sizeof(func, data) - xdrproc_t func; - void *data; +xdr_sizeof(xdrproc_t func, void *data) { XDR x; struct xdr_ops ops; diff --git a/freebsd/lib/libc/xdr/xdr_stdio.c b/freebsd/lib/libc/xdr/xdr_stdio.c index 5267c604..3bbdb464 100644 --- a/freebsd/lib/libc/xdr/xdr_stdio.c +++ b/freebsd/lib/libc/xdr/xdr_stdio.c @@ -2,33 +2,35 @@ /* $NetBSD: xdr_stdio.c,v 1.14 2000/01/22 22:19:19 mycroft Exp $ */ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. +/*- + * Copyright (c) 2010, Oracle America, Inc. * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * * Neither the name of the "Oracle America, Inc." nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,8 +43,6 @@ __FBSDID("$FreeBSD$"); /* * xdr_stdio.c, XDR implementation on standard i/o file. * - * Copyright (C) 1984, Sun Microsystems, Inc. - * * This set of routines implements a XDR on a stdio stream. * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes * from the stream. @@ -85,10 +85,7 @@ static const struct xdr_ops xdrstdio_ops = { * Operation flag is set to op. */ void -xdrstdio_create(xdrs, file, op) - XDR *xdrs; - FILE *file; - enum xdr_op op; +xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op) { xdrs->x_op = op; @@ -103,17 +100,14 @@ xdrstdio_create(xdrs, file, op) * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. */ static void -xdrstdio_destroy(xdrs) - XDR *xdrs; +xdrstdio_destroy(XDR *xdrs) { (void)fflush((FILE *)xdrs->x_private); /* XXX: should we close the file ?? */ } static bool_t -xdrstdio_getlong(xdrs, lp) - XDR *xdrs; - long *lp; +xdrstdio_getlong(XDR *xdrs, long *lp) { u_int32_t temp; @@ -124,9 +118,7 @@ xdrstdio_getlong(xdrs, lp) } static bool_t -xdrstdio_putlong(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrstdio_putlong(XDR *xdrs, const long *lp) { int32_t mycopy = htonl((u_int32_t)*lp); @@ -136,10 +128,7 @@ xdrstdio_putlong(xdrs, lp) } static bool_t -xdrstdio_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrstdio_getbytes(XDR *xdrs, char *addr, u_int len) { if ((len != 0) && (fread(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) @@ -148,10 +137,7 @@ xdrstdio_getbytes(xdrs, addr, len) } static bool_t -xdrstdio_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrstdio_putbytes(XDR *xdrs, const char *addr, u_int len) { if ((len != 0) && (fwrite(addr, (size_t)len, 1, @@ -161,17 +147,14 @@ xdrstdio_putbytes(xdrs, addr, len) } static u_int -xdrstdio_getpos(xdrs) - XDR *xdrs; +xdrstdio_getpos(XDR *xdrs) { return ((u_int) ftell((FILE *)xdrs->x_private)); } static bool_t -xdrstdio_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrstdio_setpos(XDR *xdrs, u_int pos) { return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? @@ -180,9 +163,7 @@ xdrstdio_setpos(xdrs, pos) /* ARGSUSED */ static int32_t * -xdrstdio_inline(xdrs, len) - XDR *xdrs; - u_int len; +xdrstdio_inline(XDR *xdrs, u_int len) { /* diff --git a/freebsd/lib/libipsec/pfkey.c b/freebsd/lib/libipsec/pfkey.c index c8ebfbf5..abb0cee1 100644 --- a/freebsd/lib/libipsec/pfkey.c +++ b/freebsd/lib/libipsec/pfkey.c @@ -1647,7 +1647,7 @@ pfkey_recv(so) /* read real message */ reallen = PFKEY_UNUNIT64(buf.sadb_msg_len); - if ((newmsg = CALLOC(reallen, struct sadb_msg *)) == 0) { + if ((newmsg = CALLOC(reallen, struct sadb_msg *)) == NULL) { __ipsec_set_strerror(strerror(errno)); return NULL; } diff --git a/freebsd/lib/libipsec/pfkey_dump.c b/freebsd/lib/libipsec/pfkey_dump.c index 8c4d5213..7a5c2f21 100644 --- a/freebsd/lib/libipsec/pfkey_dump.c +++ b/freebsd/lib/libipsec/pfkey_dump.c @@ -189,6 +189,9 @@ static struct val2str str_alg_enc[] = { #ifdef SADB_X_EALG_AESCTR { SADB_X_EALG_AESCTR, "aes-ctr", }, #endif +#ifdef SADB_X_EALG_AESGCM16 + { SADB_X_EALG_AESGCM16, "aes-gcm-16", }, +#endif #ifdef SADB_X_EALG_CAMELLIACBC { SADB_X_EALG_CAMELLIACBC, "camellia-cbc", }, #endif diff --git a/freebsd/lib/libipsec/policy_parse.y b/freebsd/lib/libipsec/policy_parse.y index 9e2f979c..46e54e55 100644 --- a/freebsd/lib/libipsec/policy_parse.y +++ b/freebsd/lib/libipsec/policy_parse.y @@ -88,7 +88,6 @@ static caddr_t policy_parse(char *msg, int msglen); extern void __policy__strbuffer__init__(char *msg); extern void __policy__strbuffer__free__(void); -extern int yyparse(void); extern int yylex(void); extern char *__libipsecyytext; /*XXX*/ diff --git a/freebsd/lib/libkvm/kvm.h b/freebsd/lib/libkvm/kvm.h index 912f1d4b..8b661807 100644 --- a/freebsd/lib/libkvm/kvm.h +++ b/freebsd/lib/libkvm/kvm.h @@ -34,7 +34,7 @@ #define _KVM_H_ #include <sys/cdefs.h> -#include <sys/_types.h> +#include <sys/types.h> #include <nlist.h> /* Default version symbol. */ @@ -51,6 +51,14 @@ typedef __ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif +typedef uint64_t kvaddr_t; /* An address in a target image. */ + +struct kvm_nlist { + const char *n_name; + unsigned char n_type; + kvaddr_t n_value; +}; + typedef struct __kvm kvm_t; struct kinfo_proc; @@ -74,21 +82,27 @@ char **kvm_getargv(kvm_t *, const struct kinfo_proc *, int); int kvm_getcptime(kvm_t *, long *); char **kvm_getenvv(kvm_t *, const struct kinfo_proc *, int); char *kvm_geterr(kvm_t *); -char *kvm_getfiles(kvm_t *, int, int, int *); int kvm_getloadavg(kvm_t *, double [], int); int kvm_getmaxcpu(kvm_t *); +int kvm_getncpus(kvm_t *); void *kvm_getpcpu(kvm_t *, int); +uint64_t kvm_counter_u64_fetch(kvm_t *, u_long); struct kinfo_proc * kvm_getprocs(kvm_t *, int, int, int *); int kvm_getswapinfo(kvm_t *, struct kvm_swap *, int, int); +int kvm_native(kvm_t *); int kvm_nlist(kvm_t *, struct nlist *); +int kvm_nlist2(kvm_t *, struct kvm_nlist *); kvm_t *kvm_open (const char *, const char *, const char *, int, const char *); kvm_t *kvm_openfiles (const char *, const char *, const char *, int, char *); +kvm_t *kvm_open2 + (const char *, const char *, int, char *, + int (*)(const char *, kvaddr_t *)); ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t); -ssize_t kvm_uread - (kvm_t *, const struct kinfo_proc *, unsigned long, char *, size_t); +ssize_t kvm_read_zpcpu(kvm_t *, unsigned long, void *, size_t, int); +ssize_t kvm_read2(kvm_t *, kvaddr_t, void *, size_t); ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t); __END_DECLS diff --git a/freebsd/lib/libmemstat/memstat.c b/freebsd/lib/libmemstat/memstat.c index 536b47fb..e7e7d53f 100644 --- a/freebsd/lib/libmemstat/memstat.c +++ b/freebsd/lib/libmemstat/memstat.c @@ -256,6 +256,13 @@ memstat_get_size(const struct memory_type *mtp) } uint64_t +memstat_get_rsize(const struct memory_type *mtp) +{ + + return (mtp->mt_rsize); +} + +uint64_t memstat_get_memalloced(const struct memory_type *mtp) { diff --git a/freebsd/lib/libmemstat/memstat.h b/freebsd/lib/libmemstat/memstat.h index cca75b32..8394dc1c 100644 --- a/freebsd/lib/libmemstat/memstat.h +++ b/freebsd/lib/libmemstat/memstat.h @@ -124,6 +124,7 @@ uint64_t memstat_get_countlimit(const struct memory_type *mtp); uint64_t memstat_get_byteslimit(const struct memory_type *mtp); uint64_t memstat_get_sizemask(const struct memory_type *mtp); uint64_t memstat_get_size(const struct memory_type *mtp); +uint64_t memstat_get_rsize(const struct memory_type *mtp); uint64_t memstat_get_memalloced(const struct memory_type *mtp); uint64_t memstat_get_memfreed(const struct memory_type *mtp); uint64_t memstat_get_numallocs(const struct memory_type *mtp); diff --git a/freebsd/lib/libmemstat/memstat_internal.h b/freebsd/lib/libmemstat/memstat_internal.h index 2416e09b..9fdc2281 100644 --- a/freebsd/lib/libmemstat/memstat_internal.h +++ b/freebsd/lib/libmemstat/memstat_internal.h @@ -51,6 +51,7 @@ struct memory_type { uint64_t mt_byteslimit; /* 0, or maximum bytes. */ uint64_t mt_sizemask; /* malloc: allocated size bitmask. */ uint64_t mt_size; /* uma: size of objects. */ + uint64_t mt_rsize; /* uma: real size of objects. */ /* * Zone or type information that includes all caches and any central diff --git a/freebsd/lib/libmemstat/memstat_uma.c b/freebsd/lib/libmemstat/memstat_uma.c index 1be0ada7..9c5e4024 100644 --- a/freebsd/lib/libmemstat/memstat_uma.c +++ b/freebsd/lib/libmemstat/memstat_uma.c @@ -214,6 +214,7 @@ retry: } mtp->mt_size = uthp->uth_size; + mtp->mt_rsize = uthp->uth_rsize; mtp->mt_memalloced = mtp->mt_numallocs * uthp->uth_size; mtp->mt_memfreed = mtp->mt_numfrees * uthp->uth_size; mtp->mt_bytes = mtp->mt_memalloced - mtp->mt_memfreed; @@ -438,6 +439,7 @@ memstat_kvm_uma(struct memory_type_list *list, void *kvm_handle) } skip_percpu: mtp->mt_size = kz.uk_size; + mtp->mt_rsize = kz.uk_rsize; mtp->mt_memalloced = mtp->mt_numallocs * mtp->mt_size; mtp->mt_memfreed = mtp->mt_numfrees * mtp->mt_size; mtp->mt_bytes = mtp->mt_memalloced - mtp->mt_memfreed; @@ -449,7 +451,7 @@ skip_percpu: kz.uk_ipers; mtp->mt_byteslimit = mtp->mt_countlimit * mtp->mt_size; mtp->mt_count = mtp->mt_numallocs - mtp->mt_numfrees; - for (ubp = LIST_FIRST(&uz.uz_full_bucket); ubp != + for (ubp = LIST_FIRST(&uz.uz_buckets); ubp != NULL; ubp = LIST_NEXT(&ub, ub_link)) { ret = kread(kvm, ubp, &ub, sizeof(ub), 0); mtp->mt_zonefree += ub.ub_cnt; diff --git a/freebsd/lib/libutil/expand_number.c b/freebsd/lib/libutil/expand_number.c index 893a1d77..b004f5fc 100644 --- a/freebsd/lib/libutil/expand_number.c +++ b/freebsd/lib/libutil/expand_number.c @@ -37,31 +37,24 @@ __FBSDID("$FreeBSD$"); #include <libutil.h> #include <stdint.h> -/* - * Convert an expression of the following forms to a uint64_t. - * 1) A positive decimal number. - * 2) A positive decimal number followed by a 'b' or 'B' (mult by 1). - * 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10). - * 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20). - * 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30). - * 6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40). - * 7) A positive decimal number followed by a 'p' or 'P' (mult by 1 << 50). - * 8) A positive decimal number followed by a 'e' or 'E' (mult by 1 << 60). - */ int expand_number(const char *buf, uint64_t *num) { + char *endptr; + uintmax_t umaxval; uint64_t number; unsigned shift; - char *endptr; - - number = strtoumax(buf, &endptr, 0); + int serrno; - if (endptr == buf) { - /* No valid digits. */ - errno = EINVAL; + serrno = errno; + errno = 0; + umaxval = strtoumax(buf, &endptr, 0); + if (umaxval > UINT64_MAX) + errno = ERANGE; + if (errno != 0) return (-1); - } + errno = serrno; + number = umaxval; switch (tolower((unsigned char)*endptr)) { case 'e': @@ -97,7 +90,6 @@ expand_number(const char *buf, uint64_t *num) errno = ERANGE; return (-1); } - *num = number << shift; return (0); } diff --git a/freebsd/lib/libutil/humanize_number.c b/freebsd/lib/libutil/humanize_number.c index da5c5197..3bb729a9 100644 --- a/freebsd/lib/libutil/humanize_number.c +++ b/freebsd/lib/libutil/humanize_number.c @@ -4,6 +4,7 @@ /* * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. + * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org> * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -52,15 +53,26 @@ humanize_number(char *buf, size_t len, int64_t quotient, { const char *prefixes, *sep; int i, r, remainder, s1, s2, sign; + int divisordeccut; int64_t divisor, max; size_t baselen; - assert(buf != NULL); - assert(suffix != NULL); - assert(scale >= 0); - assert(scale < maxscale || (((scale & (HN_AUTOSCALE | HN_GETSCALE)) != 0))); - assert(!((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))); + /* Since so many callers don't check -1, NUL terminate the buffer */ + if (len > 0) + buf[0] = '\0'; + /* validate args */ + if (buf == NULL || suffix == NULL) + return (-1); + if (scale < 0) + return (-1); + else if (scale >= maxscale && + ((scale & ~(HN_AUTOSCALE|HN_GETSCALE)) != 0)) + return (-1); + if ((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES)) + return (-1); + + /* setup parameters */ remainder = 0; if (flags & HN_IEC_PREFIXES) { @@ -75,34 +87,32 @@ humanize_number(char *buf, size_t len, int64_t quotient, * an assertion earlier). */ divisor = 1024; + divisordeccut = 973; /* ceil(.95 * 1024) */ if (flags & HN_B) prefixes = "B\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; else prefixes = "\0\0\0Ki\0Mi\0Gi\0Ti\0Pi\0Ei"; } else { baselen = 1; - if (flags & HN_DIVISOR_1000) + if (flags & HN_DIVISOR_1000) { divisor = 1000; - else + divisordeccut = 950; + if (flags & HN_B) + prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + } else { divisor = 1024; - - if (flags & HN_B) - prefixes = "B\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; - else - prefixes = "\0\0\0k\0\0M\0\0G\0\0T\0\0P\0\0E"; + divisordeccut = 973; /* ceil(.95 * 1024) */ + if (flags & HN_B) + prefixes = "B\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + else + prefixes = "\0\0\0K\0\0M\0\0G\0\0T\0\0P\0\0E"; + } } #define SCALE2PREFIX(scale) (&prefixes[(scale) * 3]) - if (scale < 0 || (scale >= maxscale && - (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0)) - return (-1); - - if (buf == NULL || suffix == NULL) - return (-1); - - if (len > 0) - buf[0] = '\0'; if (quotient < 0) { sign = -1; quotient = -quotient; @@ -134,8 +144,8 @@ humanize_number(char *buf, size_t len, int64_t quotient, * divide once more. */ for (i = 0; - (quotient >= max || (quotient == max - 1 && remainder >= 950)) && - i < maxscale; i++) { + (quotient >= max || (quotient == max - 1 && + remainder >= divisordeccut)) && i < maxscale; i++) { remainder = quotient % divisor; quotient /= divisor; } @@ -150,20 +160,22 @@ humanize_number(char *buf, size_t len, int64_t quotient, } /* If a value <= 9.9 after rounding and ... */ - if (quotient <= 9 && remainder < 950 && i > 0 && flags & HN_DECIMAL) { - /* baselen + \0 + .N */ - if (len < baselen + 1 + 2) - return (-1); - s1 = (int)quotient + ((remainder + 50) / 1000); - s2 = ((remainder + 50) / 100) % 10; + /* + * XXX - should we make sure there is enough space for the decimal + * place and if not, don't do HN_DECIMAL? + */ + if (((quotient == 9 && remainder < divisordeccut) || quotient < 9) && + i > 0 && flags & HN_DECIMAL) { + s1 = (int)quotient + ((remainder * 10 + divisor / 2) / + divisor / 10); + s2 = ((remainder * 10 + divisor / 2) / divisor) % 10; r = snprintf(buf, len, "%d%s%d%s%s%s", sign * s1, localeconv()->decimal_point, s2, sep, SCALE2PREFIX(i), suffix); } else r = snprintf(buf, len, "%" PRId64 "%s%s%s", - sign * (quotient + (remainder + 50) / 1000), + sign * (quotient + (remainder + divisor / 2) / divisor), sep, SCALE2PREFIX(i), suffix); return (r); } - diff --git a/freebsd/lib/libutil/libutil.h b/freebsd/lib/libutil/libutil.h index 60ba3235..b20ffa29 100644 --- a/freebsd/lib/libutil/libutil.h +++ b/freebsd/lib/libutil/libutil.h @@ -102,6 +102,8 @@ struct kinfo_file * kinfo_getfile(pid_t _pid, int *_cntp); struct kinfo_vmentry * kinfo_getvmmap(pid_t _pid, int *_cntp); +struct kinfo_vmobject * + kinfo_getvmobject(int *_cntp); struct kinfo_proc * kinfo_getallproc(int *_cntp); struct kinfo_proc * @@ -162,16 +164,21 @@ int pw_tmp(int _mfd); #endif #ifdef _GRP_H_ -int gr_copy(int __ffd, int _tfd, const struct group *_gr, struct group *_old_gr); -struct group *gr_dup(const struct group *gr); -int gr_equal(const struct group *gr1, const struct group *gr2); +int gr_copy(int __ffd, int _tfd, const struct group *_gr, + struct group *_old_gr); +struct group * + gr_dup(const struct group *_gr); +struct group * + gr_add(const struct group *_gr, const char *_newmember); +int gr_equal(const struct group *_gr1, const struct group *_gr2); void gr_fini(void); int gr_init(const char *_dir, const char *_master); int gr_lock(void); -char *gr_make(const struct group *gr); +char *gr_make(const struct group *_gr); int gr_mkdb(void); +struct group * + gr_scan(const char *_line); int gr_tmp(int _mdf); -struct group *gr_scan(const char *line); #endif #ifdef _UFS_UFS_QUOTA_H_ |