0N/A/*
1612N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * This software is available to you under a choice of one of two
0N/A * licenses. You may choose to be licensed under the terms of the GNU
0N/A * General Public License (GPL) Version 2, available from the file
0N/A * COPYING in the main directory of this source tree, or the
0N/A * OpenIB.org BSD license below:
0N/A *
0N/A * Redistribution and use in source and binary forms, with or
0N/A * without modification, are permitted provided that the following
0N/A * conditions are met:
0N/A *
0N/A * - Redistributions of source code must retain the above
0N/A * copyright notice, this list of conditions and the following
0N/A * disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above
1472N/A * copyright notice, this list of conditions and the following
1472N/A * disclaimer in the documentation and/or other materials
1472N/A * provided with the distribution.
0N/A *
0N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0N/A * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1879N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1879N/A * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1879N/A * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1879N/A * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1879N/A * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0N/A * SOFTWARE.
0N/A */
0N/A/*
0N/A * OFED Solaris ioctl wrapper
0N/A */
0N/A#if defined(__SVR4) && defined(__sun)
0N/A
0N/A#include <stdio.h>
0N/A#include <string.h>
0N/A#include <stdlib.h>
0N/A#include <errno.h>
0N/A#include <strings.h>
0N/A#include <unistd.h>
0N/A#include <stropts.h>
0N/A#include <sys/rds.h>
0N/A
0N/Aint
0N/Asol_ioctl(int fd, int opt_val, struct rds_info_arg *argp, socklen_t *ulen,
0N/A int *item_size)
0N/A{
0N/A int len;
0N/A struct rds_info_arg arg = *argp;
0N/A
1612N/A /* 1st call gets the length of the data available */
0N/A *ulen = 0;
0N/A bzero(&arg, sizeof (struct rds_info_arg));
1612N/A arg.lenp = (uint64_t)(uintptr_t)ulen;
0N/A arg.datap = NULL;
0N/A *item_size = ioctl(fd, opt_val, &arg);
0N/A argp->lenp = arg.lenp;
0N/A argp->datap = arg.datap;
1612N/A if ((*item_size < 0) && (errno != ENOSPC))
0N/A return (1);
0N/A
0N/A do {
0N/A if (*ulen == 0)
1612N/A return (0);
0N/A if (arg.datap)
1612N/A arg.datap = (uint64_t)(uintptr_t)realloc(
1612N/A (char *)(uintptr_t)arg.datap, *ulen);
1612N/A else
1612N/A arg.datap = (uint64_t)(uintptr_t)malloc(*ulen);
1612N/A
0N/A if (arg.datap == NULL)
0N/A return (2);
0N/A
0N/A /* 2nd call gets the data */
0N/A len = *ulen;
0N/A *item_size = ioctl(fd, opt_val, &arg);
0N/A argp->lenp = arg.lenp;
0N/A argp->datap = arg.datap;
0N/A if ((*item_size < 0) && (errno != ENOSPC)) {
0N/A return (3);
0N/A }
0N/A } while (*ulen > len);
0N/A return (0);
0N/A}
0N/A#endif
0N/A