0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the "License"). You may not use this file except
0N/A * in compliance with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * src/OPENSOLARIS.LICENSE
0N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing
0N/A * permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * HEADER in each file and include the License file at
0N/A * usr/src/OPENSOLARIS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your
0N/A * own identifying information: Portions Copyright [yyyy]
0N/A * [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
0N/A/*
0N/A * getpeername test
0N/A */
0N/A
0N/A
0N/A#include <sys/types.h>
0N/A#include <sys/socket.h>
0N/A#include <netinet/in.h>
0N/A#include <netinet/tcp.h>
0N/A#include <arpa/inet.h>
0N/A#include <netdb.h>
0N/A#include <string.h>
0N/A#include <unistd.h>
0N/A#include <stdlib.h>
0N/A#include <stdio.h>
0N/A#include <fcntl.h>
0N/A#include <errno.h>
0N/A
0N/A#include "libmicro.h"
0N/A
0N/A#define FIRSTPORT 12345
0N/A
0N/Astatic int sock = -1;
0N/A
0N/Aint
0N/Abenchmark_init()
0N/A{
0N/A (void) sprintf(lm_usage, "notes: measures getpeername()\n");
0N/A lm_tsdsize = 0;
0N/A
0N/A return (0);
0N/A}
0N/A
0N/Aint
0N/Abenchmark_initrun()
0N/A{
0N/A int j;
0N/A int opt = 1;
0N/A int result;
0N/A socklen_t size;
0N/A struct hostent *host;
0N/A struct sockaddr_in adds;
0N/A int sock2, sock3;
0N/A
0N/A sock2 = socket(AF_INET, SOCK_STREAM, 0);
0N/A if (sock2 == -1) {
0N/A perror("socket");
0N/A exit(1);
0N/A }
0N/A
0N/A if (setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR,
0N/A &opt, sizeof (int)) == -1) {
0N/A perror("setsockopt");
0N/A exit(1);
0N/A }
0N/A
0N/A if ((host = gethostbyname("localhost")) == NULL) {
0N/A perror("gethostbyname");
0N/A exit(1);
0N/A }
0N/A
0N/A j = FIRSTPORT;
0N/A for (;;) {
0N/A (void) memset(&adds, 0, sizeof (struct sockaddr_in));
0N/A adds.sin_family = AF_INET;
0N/A adds.sin_port = htons(j++);
0N/A (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
0N/A sizeof (struct in_addr));
0N/A
0N/A if (bind(sock2, (struct sockaddr *)&adds,
0N/A sizeof (struct sockaddr_in)) == 0) {
0N/A break;
0N/A }
0N/A
0N/A if (errno != EADDRINUSE) {
0N/A perror("bind");
0N/A exit(1);
0N/A }
0N/A }
0N/A
0N/A if (listen(sock2, 5) == -1) {
0N/A perror("listen");
0N/A exit(1);
0N/A }
0N/A
0N/A sock3 = socket(AF_INET, SOCK_STREAM, 0);
0N/A if (sock3 == -1) {
0N/A perror("socket");
0N/A exit(1);
0N/A }
0N/A
0N/A if (fcntl(sock3, F_SETFL, O_NDELAY) == -1) {
0N/A perror("fcntl");
0N/A exit(1);
0N/A }
0N/A
0N/A result = connect(sock3, (struct sockaddr *)&adds,
0N/A sizeof (struct sockaddr_in));
0N/A if ((result == -1) && (errno != EINPROGRESS)) {
0N/A perror("connect");
0N/A exit(1);
0N/A }
0N/A
0N/A size = sizeof (struct sockaddr);
0N/A sock = accept(sock2, (struct sockaddr *)&adds, &size);
0N/A if (sock == -1) {
0N/A perror("accept");
0N/A exit(1);
0N/A }
0N/A
0N/A return (0);
0N/A}
0N/A
0N/A/*ARGSUSED*/
0N/Aint
0N/Abenchmark(void *tsd, result_t *res)
0N/A{
0N/A int i;
0N/A struct sockaddr_in adds;
0N/A socklen_t size;
0N/A
0N/A for (i = 0; i < lm_optB; i++) {
0N/A size = sizeof (struct sockaddr_in);
0N/A if (getpeername(sock, (struct sockaddr *)&adds, &size) == -1) {
0N/A perror("getpeername");
0N/A exit(1);
0N/A res->re_errors++;
0N/A }
0N/A }
0N/A res->re_count = i;
0N/A
0N/A return (0);
0N/A}