2 * S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen "Daode" Nurpmeso.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 #endif /* HAVE_WORDEXP */
52 #elif defined (USE_OPENSSL)
53 #include <openssl/ssl.h>
54 #include <openssl/err.h>
55 #include <openssl/x509v3.h>
56 #include <openssl/x509.h>
57 #include <openssl/rand.h>
60 #include <sys/socket.h>
62 #include <netinet/in.h>
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
65 #endif /* HAVE_ARPA_INET_H */
66 #endif /* HAVE_SOCKETS */
72 * Mail -- a mail program
77 static void makemessage(void);
78 static void append(struct message
*mp
);
79 static char *globname(char *name
);
80 static size_t length_of_line(const char *line
, size_t linesize
);
81 static char *fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
82 FILE *fp
, int appendnl
, size_t n
);
83 static enum okay
get_header(struct message
*mp
);
86 * Set up the input pointers while copying the mail file into /tmp.
89 setptr(FILE *ibuf
, off_t offset
)
95 int maybe
, inhead
, thiscnt
;
97 size_t linesize
= 0, filesize
;
102 memset(&this, 0, sizeof this);
103 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
104 filesize
= mailsize
- offset
;
105 offset
= ftell(mb
.mb_otf
);
107 if (fgetline(&linebuf
, &linesize
, &filesize
, &count
, ibuf
, 0)
109 this.m_xsize
= this.m_size
;
110 this.m_xlines
= this.m_lines
;
111 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
120 if (linebuf
[0] == '\0')
123 fwrite(linebuf
, sizeof *linebuf
, count
, mb
.mb_otf
);
124 if (ferror(mb
.mb_otf
)) {
128 if (linebuf
[count
- 1] == '\n')
129 linebuf
[count
- 1] = '\0';
130 if (maybe
&& linebuf
[0] == 'F' && is_head(linebuf
, count
)) {
131 this.m_xsize
= this.m_size
;
132 this.m_xlines
= this.m_lines
;
133 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
137 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
140 this.m_block
= mailx_blockof(offset
);
141 this.m_offset
= mailx_offsetof(offset
);
143 } else if (linebuf
[0] == 0) {
146 for (cp
= linebuf
, cp2
= "status";; cp
++) {
147 if ((c
= *cp2
++) == 0) {
148 while (c
= *cp
++, whitechar(c
));
151 while ((c
= *cp
++) != '\0')
153 this.m_flag
|= MREAD
;
155 this.m_flag
&= ~MNEW
;
158 if (*cp
!= c
&& *cp
!= upperconv(c
))
161 for (cp
= linebuf
, cp2
= "x-status";; cp
++) {
162 if ((c
= *cp2
++) == 0) {
163 while (c
= *cp
++, whitechar(c
));
166 while ((c
= *cp
++) != '\0')
168 this.m_flag
|= MFLAGGED
;
170 this.m_flag
|=MANSWERED
;
172 this.m_flag
|=MDRAFTED
;
175 if (*cp
!= c
&& *cp
!= upperconv(c
))
180 this.m_size
+= count
;
182 maybe
= linebuf
[0] == 0;
188 * Drop the passed line onto the passed output buffer.
189 * If a write error occurs, return -1, else the count of
190 * characters written, including the newline.
193 putline(FILE *obuf
, char *linebuf
, size_t count
)
195 fwrite(linebuf
, sizeof *linebuf
, count
, obuf
);
203 * Read up a line from the specified input into the line
204 * buffer. Return the number of characters read. Do not
205 * include the newline at the end.
207 * n is the number of characters already read.
210 readline_restart(FILE *ibuf
, char **linebuf
, size_t *linesize
, size_t n
)
216 * Interrupts will cause trouble if we are inside a stdio call. As
217 * this is only relevant if input comes from a terminal, we can simply
218 * bypass it by read() then.
220 if (fileno(ibuf
) == 0 && is_a_tty
[0]) {
221 if (*linebuf
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
222 *linebuf
= srealloc(*linebuf
,
223 *linesize
= LINESIZE
+ n
+ 1);
225 if (n
>= *linesize
- 128)
226 *linebuf
= srealloc(*linebuf
, *linesize
+= 256);
228 sz
= read(0, *linebuf
+ n
, *linesize
- n
- 1);
231 (*linebuf
)[n
] = '\0';
232 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
235 if (sz
< 0 && errno
== EINTR
)
238 if ((*linebuf
)[n
- 1] != '\n') {
239 (*linebuf
)[n
++] = '\n';
240 (*linebuf
)[n
] = '\0';
249 * Not reading from standard input or standard input not
250 * a terminal. We read one char at a time as it is the
251 * only way to get lines with embedded NUL characters in
254 if (fgetline_byone(linebuf
, linesize
, &n
, ibuf
, 1, n
) == NULL
)
257 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
258 (*linebuf
)[--n
] = '\0';
263 * Return a file buffer all ready to read up the
264 * passed message pointer.
267 setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
)
273 if (m
->m_have
& HAVE_HEADER
)
279 if (m
->m_have
& HAVE_BODY
)
291 if (fseek(mp
->mb_itf
, (long)mailx_positionof(m
->m_block
,
292 m
->m_offset
), SEEK_SET
) < 0) {
294 panic(catgets(catd
, CATSET
, 77, "temporary file seek"));
300 setdot(struct message
*mp
)
312 * Take the data out of the passed ghost file and toss it into
313 * a dynamically allocated message structure.
321 message
[msgCount
].m_size
= 0;
322 message
[msgCount
].m_lines
= 0;
326 * Append the passed message descriptor onto the message structure.
329 append(struct message
*mp
)
331 if (msgCount
+ 1 >= msgspace
)
332 message
= srealloc(message
, (msgspace
+= 64) * sizeof *message
);
334 message
[msgCount
- 1] = *mp
;
338 * Delete a file, but only if the file is a plain file.
345 if (stat(name
, &sb
) < 0)
347 if (!S_ISREG(sb
.st_mode
)) {
351 return(unlink(name
));
354 static int sigdepth
; /* depth of holdsigs() */
355 static sigset_t nset
, oset
;
357 * Hold signals SIGHUP, SIGINT, and SIGQUIT.
363 if (sigdepth
++ == 0) {
365 sigaddset(&nset
, SIGHUP
);
366 sigaddset(&nset
, SIGINT
);
367 sigaddset(&nset
, SIGQUIT
);
368 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
373 * Release signals SIGHUP, SIGINT, and SIGQUIT.
380 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
384 * Determine the size of the file possessed by
392 if (fstat(fileno(iob
), &sbuf
) < 0)
398 * Evaluate the string given as a new mailbox name.
399 * Supported meta characters:
400 * % for my system mail box
401 * %user for user's system mail box
402 * # for previous file
403 * & invoker's mbox file
404 * +file file in folder directory
405 * any shell meta character
406 * Return the file name as a dynamic string.
411 char xname
[PATHSIZE
];
412 char foldbuf
[PATHSIZE
];
416 * The order of evaluation is "%" and "#" expand into constants.
417 * "&" can expand into "+". "+" can expand into shell meta characters.
418 * Shell meta characters expand into constants.
419 * This way, we make no recursive expansion.
421 if ((sh
= get_shortcut(name
)) != NULL
)
426 if (name
[1] == ':' && name
[2]) {
430 findmail(name
[1] ? name
+ 1 : myname
, name
[1] != '\0' || uflag
,
431 xname
, sizeof xname
);
432 return savestr(xname
);
436 if (prevfile
[0] == 0) {
437 printf(catgets(catd
, CATSET
, 80, "No previous file\n"));
440 return savestr(prevfile
);
442 if (name
[1] == 0 && (name
= value("MBOX")) == NULL
)
446 if (name
[0] == '@' && which_protocol(mailname
) == PROTO_IMAP
) {
447 snprintf(xname
, sizeof xname
, "%s/%s", protbase(mailname
),
449 name
= savestr(xname
);
451 if (name
[0] == '+' && getfold(foldbuf
, sizeof foldbuf
) >= 0) {
452 snprintf(xname
, sizeof xname
,
453 ((which_protocol(foldbuf
) == PROTO_IMAP
&&
454 strcmp(foldbuf
, protbase(foldbuf
)))
457 name
= savestr(xname
);
458 if (foldbuf
[0] == '%' && foldbuf
[1] == ':')
461 /* catch the most common shell meta character */
462 if (name
[0] == '~' && (name
[1] == '/' || name
[1] == '\0')) {
463 snprintf(xname
, sizeof xname
, "%s%s", homedir
, name
+ 1);
464 name
= savestr(xname
);
466 if (!anyof(name
, "|&;<>~{}()[]*?$`'\"\\"))
468 if (which_protocol(name
) == PROTO_FILE
)
469 return globname(name
);
484 * Some systems (notably Open UNIX 8.0.0) fork a shell for
485 * wordexp() and wait for it; waiting will fail if our SIGCHLD
489 sigaddset(&nset
, SIGCHLD
);
490 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
491 i
= wordexp(name
, &we
, 0);
492 sigprocmask(SIG_UNBLOCK
, &nset
, NULL
);
497 fprintf(stderr
, catgets(catd
, CATSET
, 83,
498 "\"%s\": Expansion buffer overflow.\n"), name
);
503 fprintf(stderr
, catgets(catd
, CATSET
, 242,
504 "Syntax error in \"%s\"\n"), name
);
507 switch (we
.we_wordc
) {
509 cp
= savestr(we
.we_wordv
[0]);
512 fprintf(stderr
, catgets(catd
, CATSET
, 82,
513 "\"%s\": No match.\n"), name
);
517 fprintf(stderr
, catgets(catd
, CATSET
, 84,
518 "\"%s\": Ambiguous.\n"), name
);
523 #else /* !HAVE_WORDEXP */
524 char xname
[PATHSIZE
];
525 char cmdbuf
[PATHSIZE
]; /* also used for file names */
529 extern int wait_status
;
532 if (pipe(pivec
) < 0) {
536 snprintf(cmdbuf
, sizeof cmdbuf
, "echo %s", name
);
537 if ((shell
= value("SHELL")) == NULL
)
539 pid
= start_command(shell
, 0, -1, pivec
[1], "-c", cmdbuf
, NULL
);
547 l
= read(pivec
[0], xname
, sizeof xname
);
556 if (wait_child(pid
) < 0 && WTERMSIG(wait_status
) != SIGPIPE
) {
557 fprintf(stderr
, catgets(catd
, CATSET
, 81,
558 "\"%s\": Expansion failed.\n"), name
);
562 fprintf(stderr
, catgets(catd
, CATSET
, 82,
563 "\"%s\": No match.\n"), name
);
566 if (l
== sizeof xname
) {
567 fprintf(stderr
, catgets(catd
, CATSET
, 83,
568 "\"%s\": Expansion buffer overflow.\n"), name
);
572 for (cp
= &xname
[l
-1]; *cp
== '\n' && cp
> xname
; cp
--)
575 if (strchr(xname
, ' ') && stat(xname
, &sbuf
) < 0) {
576 fprintf(stderr
, catgets(catd
, CATSET
, 84,
577 "\"%s\": Ambiguous.\n"), name
);
580 return savestr(xname
);
581 #endif /* !HAVE_WORDEXP */
585 * Determine the current folder directory name.
588 getfold(char *name
, int size
)
593 if ((folder
= value("folder")) == NULL
)
595 if (*folder
== '/' || ((p
= which_protocol(folder
)) != PROTO_FILE
&&
596 p
!= PROTO_MAILDIR
)) {
597 strncpy(name
, folder
, size
);
600 snprintf(name
, size
, "%s/%s", homedir
, folder
);
606 * Return the name of the dead.letter file.
613 if ((cp
= value("DEAD")) == NULL
|| (cp
= expand(cp
)) == NULL
)
614 cp
= expand("~/dead.letter");
615 else if (*cp
!= '/') {
619 buf
= ac_alloc(sz
= strlen(cp
) + 3);
620 snprintf(buf
, sz
, "~/%s", cp
);
621 snprintf(buf
, sz
, "~/%s", cp
);
629 * line is a buffer with the result of fgets(). Returns the first
630 * newline or the last character read.
633 length_of_line(const char *line
, size_t linesize
)
638 * Last character is always '\0' and was added by fgets.
641 for (i
= 0; i
< linesize
; i
++)
644 return i
< linesize
? i
+ 1 : linesize
;
648 * fgets replacement to handle lines of arbitrary size and with
649 * embedded \0 characters.
650 * line - line buffer. *line be NULL.
651 * linesize - allocated size of line buffer.
652 * count - maximum characters to read. May be NULL.
653 * llen - length_of_line(*line).
655 * appendnl - always terminate line with \n, append if necessary.
658 fgetline(char **line
, size_t *linesize
, size_t *count
, size_t *llen
,
659 FILE *fp
, int appendnl
)
665 * If we have no count, we cannot determine where the
666 * characters returned by fgets() end if there was no
667 * newline. We have to read one character at one.
669 return fgetline_byone(line
, linesize
, llen
, fp
, appendnl
, 0);
670 if (*line
== NULL
|| *linesize
< LINESIZE
)
671 *line
= srealloc(*line
, *linesize
= LINESIZE
);
672 sz
= *linesize
<= *count
? *linesize
: *count
+ 1;
673 if (sz
<= 1 || fgets(*line
, sz
, fp
) == NULL
)
675 * Leave llen untouched; it is used to determine whether
676 * the last line was \n-terminated in some callers.
679 i_llen
= length_of_line(*line
, sz
);
681 while ((*line
)[i_llen
- 1] != '\n') {
682 *line
= srealloc(*line
, *linesize
+= 256);
683 sz
= *linesize
- i_llen
;
684 sz
= (sz
<= *count
? sz
: *count
+ 1);
685 if (sz
<= 1 || fgets(&(*line
)[i_llen
], sz
, fp
) == NULL
) {
687 (*line
)[i_llen
++] = '\n';
688 (*line
)[i_llen
] = '\0';
692 sz
= length_of_line(&(*line
)[i_llen
], sz
);
702 * Read a line, one character at once.
705 fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
706 FILE *fp
, int appendnl
, size_t n
)
710 if (*line
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
711 *line
= srealloc(*line
, *linesize
= LINESIZE
+ n
+ 1);
713 if (n
>= *linesize
- 128)
714 *line
= srealloc(*line
, *linesize
+= 256);
738 get_header(struct message
*mp
)
740 switch (mb
.mb_type
) {
745 return pop3_header(mp
);
748 return imap_header(mp
);
757 get_body(struct message
*mp
)
759 switch (mb
.mb_type
) {
764 return pop3_body(mp
);
767 return imap_body(mp
);
776 static long xwrite(int fd
, const char *data
, size_t sz
);
779 xwrite(int fd
, const char *data
, size_t sz
)
785 if ((wo
= write(fd
, data
+ wt
, sz
- wt
)) < 0) {
797 sclose(struct sock
*sp
)
802 if (sp
->s_onclose
!= NULL
)
804 #if defined (USE_NSS)
807 i
= PR_Close(sp
->s_prfd
) == PR_SUCCESS
? 0 : -1;
810 #elif defined (USE_OPENSSL)
813 SSL_shutdown(sp
->s_ssl
);
816 SSL_CTX_free(sp
->s_ctx
);
831 swrite(struct sock
*sp
, const char *data
)
833 return swrite1(sp
, data
, strlen(data
), 0);
837 swrite1(struct sock
*sp
, const char *data
, int sz
, int use_buffer
)
841 if (use_buffer
> 0) {
845 if (sp
->s_wbuf
== NULL
) {
846 sp
->s_wbufsize
= 4096;
847 sp
->s_wbuf
= smalloc(sp
->s_wbufsize
);
850 while (sp
->s_wbufpos
+ sz
> sp
->s_wbufsize
) {
851 di
= sp
->s_wbufsize
- sp
->s_wbufpos
;
853 if (sp
->s_wbufpos
> 0) {
854 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, di
);
855 ok
= swrite1(sp
, sp
->s_wbuf
,
858 ok
= swrite1(sp
, data
,
865 if (sz
== sp
->s_wbufsize
) {
866 ok
= swrite1(sp
, data
, sp
->s_wbufsize
, -1);
870 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, sz
);
874 } else if (use_buffer
== 0 && sp
->s_wbuf
!= NULL
&&
878 if (swrite1(sp
, sp
->s_wbuf
, x
, -1) != OKAY
)
883 #if defined (USE_NSS)
885 x
= PR_Write(sp
->s_prfd
, data
, sz
);
887 #elif defined (USE_OPENSSL)
889 ssl_retry
: x
= SSL_write(sp
->s_ssl
, data
, sz
);
891 switch (SSL_get_error(sp
->s_ssl
, x
)) {
892 case SSL_ERROR_WANT_READ
:
893 case SSL_ERROR_WANT_WRITE
:
900 x
= xwrite(sp
->s_fd
, data
, sz
);
904 snprintf(o
, sizeof o
, "%s write error",
905 sp
->s_desc
? sp
->s_desc
: "socket");
906 #if defined (USE_NSS)
907 sp
->s_use_ssl
? nss_gen_err("%s", o
) : perror(o
);
908 #elif defined (USE_OPENSSL)
909 sp
->s_use_ssl
? ssl_gen_err("%s", o
) : perror(o
);
912 #endif /* !USE_SSL */
921 sgetline(char **line
, size_t *linesize
, size_t *linelen
, struct sock
*sp
)
930 if (*line
== NULL
|| lp
> &(*line
)[*linesize
- 128]) {
931 size_t diff
= lp
- *line
;
932 *line
= srealloc(*line
, *linesize
+= 256);
935 if (sp
->s_rbufptr
== NULL
||
936 sp
->s_rbufptr
>= &sp
->s_rbuf
[sp
->s_rsz
]) {
937 #if defined (USE_NSS)
939 if ((sp
->s_rsz
= PR_Read(sp
->s_prfd
,
941 sizeof sp
->s_rbuf
)) <= 0) {
944 snprintf(o
, sizeof o
, "%s",
948 nss_gen_err("%s", o
);
953 #elif defined (USE_OPENSSL)
955 ssl_retry
: if ((sp
->s_rsz
= SSL_read(sp
->s_ssl
,
957 sizeof sp
->s_rbuf
)) <= 0) {
960 switch(SSL_get_error(sp
->s_ssl
,
962 case SSL_ERROR_WANT_READ
:
963 case SSL_ERROR_WANT_WRITE
:
966 snprintf(o
, sizeof o
, "%s",
970 ssl_gen_err("%s", o
);
978 again
: if ((sp
->s_rsz
= read(sp
->s_fd
, sp
->s_rbuf
,
979 sizeof sp
->s_rbuf
)) <= 0) {
984 snprintf(o
, sizeof o
, "%s",
993 sp
->s_rbufptr
= sp
->s_rbuf
;
995 } while ((*lp
++ = *sp
->s_rbufptr
++) != '\n');
998 *linelen
= lp
- *line
;
1003 sopen(const char *xserver
, struct sock
*sp
, int use_ssl
,
1004 const char *uhp
, const char *portstr
, int verbose
)
1007 char hbuf
[NI_MAXHOST
];
1008 struct addrinfo hints
, *res0
, *res
;
1010 struct sockaddr_in servaddr
;
1011 struct in_addr
**pptr
;
1014 unsigned short port
= 0;
1018 char *server
= (char *)xserver
;
1022 if ((cp
= strchr(server
, ':')) != NULL
) {
1025 port
= strtol(portstr
, NULL
, 10);
1027 server
= salloc(cp
- xserver
+ 1);
1028 memcpy(server
, xserver
, cp
- xserver
);
1029 server
[cp
- xserver
] = '\0';
1032 memset(&hints
, 0, sizeof hints
);
1033 hints
.ai_socktype
= SOCK_STREAM
;
1035 fprintf(stderr
, "Resolving host %s . . .", server
);
1036 if (getaddrinfo(server
, portstr
, &hints
, &res0
) != 0) {
1037 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1038 "Could not resolve host: %s\n"), server
);
1041 fprintf(stderr
, " done.\n");
1043 for (res
= res0
; res
!= NULL
&& sockfd
< 0; res
= res
->ai_next
) {
1045 if (getnameinfo(res
->ai_addr
, res
->ai_addrlen
,
1046 hbuf
, sizeof hbuf
, NULL
, 0,
1047 NI_NUMERICHOST
) != 0)
1048 strcpy(hbuf
, "unknown host");
1049 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1050 "Connecting to %s:%s . . ."),
1053 if ((sockfd
= socket(res
->ai_family
, res
->ai_socktype
,
1054 res
->ai_protocol
)) >= 0) {
1055 if (connect(sockfd
, res
->ai_addr
, res
->ai_addrlen
)!=0) {
1062 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1067 #else /* USE_IPV6 */
1069 if (strcmp(portstr
, "smtp") == 0)
1071 else if (strcmp(portstr
, "smtps") == 0)
1073 else if (strcmp(portstr
, "imap") == 0)
1075 else if (strcmp(portstr
, "imaps") == 0)
1077 else if (strcmp(portstr
, "pop3") == 0)
1079 else if (strcmp(portstr
, "pop3s") == 0)
1081 else if ((ep
= getservbyname((char *)portstr
, "tcp")) != NULL
)
1084 fprintf(stderr
, tr(251, "Unknown service: %s\n"),
1091 fprintf(stderr
, "Resolving host %s . . .", server
);
1092 if ((hp
= gethostbyname(server
)) == NULL
) {
1093 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1094 "Could not resolve host: %s\n"), server
);
1097 fprintf(stderr
, " done.\n");
1098 pptr
= (struct in_addr
**)hp
->h_addr_list
;
1099 if ((sockfd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
1100 perror(catgets(catd
, CATSET
, 253, "could not create socket"));
1103 memset(&servaddr
, 0, sizeof servaddr
);
1104 servaddr
.sin_family
= AF_INET
;
1105 servaddr
.sin_port
= port
;
1106 memcpy(&servaddr
.sin_addr
, *pptr
, sizeof(struct in_addr
));
1108 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1109 "Connecting to %s:%d . . ."),
1110 inet_ntoa(**pptr
), ntohs(port
));
1111 if (connect(sockfd
, (struct sockaddr
*)&servaddr
, sizeof servaddr
)
1113 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1116 #endif /* USE_IPV6 */
1118 fputs(catgets(catd
, CATSET
, 193, " connected.\n"), stderr
);
1119 memset(sp
, 0, sizeof *sp
);
1125 if ((ok
= ssl_open(server
, sp
, uhp
)) != OKAY
)
1132 #endif /* HAVE_SOCKETS */