* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
static char sccsid
[] = "@(#)mconnect.c 5.4 (Berkeley) 6/29/88";
static struct sgttyb TtyBuf
;
struct sockaddr_in SendmailAddress
;
char *host
, buf
[1000], *index();
(void)signal(SIGINT
, finis
);
if ((s
= socket(AF_INET
, SOCK_STREAM
, 0, 0)) < 0) {
sp
= getservbyname("smtp", "tcp");
SendmailAddress
.sin_port
= sp
->s_port
;
while ((ch
= getopt(argc
, argv
, "hp:r")) != EOF
)
SendmailAddress
.sin_port
= htons(atoi(optarg
));
case 'r': /* raw connection */
TtyBuf
.sg_flags
&= ~CRMOD
;
TtyBuf
.sg_flags
|= CRMOD
;
fputs("usage: mconnect [-hr] [-p port] [host]\n", stderr
);
host
= argc
? *argv
: "localhost";
SendmailAddress
.sin_addr
.s_addr
= inet_addr(host
);
register struct hostent
*hp
= gethostbyname(host
);
fprintf(stderr
, "mconnect: unknown host %s\r\n", host
);
bcopy(hp
->h_addr
, &SendmailAddress
.sin_addr
, hp
->h_length
);
SendmailAddress
.sin_family
= AF_INET
;
printf("connecting to host %s (0x%lx), port 0x%x\r\n", host
,
SendmailAddress
.sin_addr
.s_addr
, SendmailAddress
.sin_port
);
if (connect(s
, &SendmailAddress
, sizeof(SendmailAddress
), 0) < 0) {
/* good connection, fork both sides */
case 0: { /* child -- standard input to sendmail */
while ((c
= fgetc(stdin
)) >= 0) {
default: /* parent -- sendmail to standard output */
while (fgets(buf
, sizeof(buf
), f
) != NULL
) {