/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* mconnect.c - A program to test out SMTP connections.
* Usage: mconnect [host]
* ... SMTP dialog
* ^C or ^D or QUIT
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <sgtty.h>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
union bigsockaddr
{
};
static int raw = 0;
/* ARGSUSED */
static void
int sig;
{
if (raw)
exit(0);
}
int
int argc;
char **argv;
{
register int s;
int pid;
register FILE *f;
int err;
int addr_num = 0;
int addrlen;
while (--argc > 0)
{
register char *p;
p = *++argv;
if (*p == '-')
{
switch (*++p)
{
case 'h': /* host */
break;
case 'p': /* port */
argc--;
break;
case 'r': /* raw connection */
raw = 1;
break;
}
host = p;
}
host = "localhost";
{
exit(0);
}
if (port == 0) {
}
for (;;) {
addrlen = sizeof (struct sockaddr_in);
} else {
addrlen = sizeof (struct sockaddr_in6);
}
if (s < 0)
{
perror("socket");
exit(-1);
}
sizeof (on));
(void) printf("connecting to host %s (%s), port %d\r\n",
else
(void) printf("connecting to host %s (%s), port %d\r\n",
addrlen) >= 0)
break;
(void) printf("connect failed (%s), next address ...\n",
if (IN6_IS_ADDR_V4MAPPED(
INADDRSZ);
addrlen = sizeof (struct sockaddr_in);
} else {
addrlen = sizeof (struct sockaddr_in6);
}
continue;
}
perror("connect");
exit(-1);
}
if (raw) {
}
/* good connection, fork both sides */
(void) printf("connection open\n");
if (pid < 0)
{
perror("fork");
exit(-1);
}
if (pid == 0)
{
/* child -- standard input to sendmail */
int c;
f = fdopen(s, "w");
{
if (!raw && c == '\n')
(void) fputc('\r', f);
(void) fputc(c, f);
if (c == '\n')
(void) fflush(f);
}
(void) shutdown(s, 1);
(void) sleep(10);
}
else
{
/* parent -- sendmail to standard output */
f = fdopen(s, "r");
{
}
}
if (raw)
return (0);
}