home *** CD-ROM | disk | FTP | other *** search
- #include <Events.h>
- #include <memory.h>
- #include <types.h>
- #include <OSUtils.h> /* for SysBeep */
-
- #include <stdio.h>
-
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/errno.h>
- #include <sys/socket.h>
- #include <sys/ioctl.h>
- #include <netinet/in.h>
-
- #include "tcpglue.h"
- #include "socket.internal.h"
-
- static struct timeval pollPlease = {0,0};
- main()
- {
- int status;
- int s,s1,s2;
- struct sockaddr_in me, her, name;
- int namelen;
- int herlen = sizeof(her);
- int bytes;
- char line[1000];
- FILE *inFile, *outFile;
-
- s = s_socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0)
- {
- perror("socket");
- exit(1);
- }
- bzero((char *)&me, sizeof(me));
- me.sin_family = AF_INET;
- me.sin_port = htons(25);
- if (s_bind(s, (caddr_t)&me, sizeof(me), 0) < 0)
- {
- perror("bind");
- exit(1);
- }
-
- #if 1
- if (s_ioctl(s,FIONBIO,0) < 0)
- {
- perror("ioctl(FIONBIO)");
- exit(1);
- }
- #endif
-
- her.sin_family = AF_INET;
- #if 0
- her.sin_addr.s_addr = 0x0d000ce8;
- #else
- her.sin_addr.s_addr = 0x8064660a;
- #endif
- her.sin_port = htons(25);
- if (s_connect(s,(caddr_t)&her,sizeof(her)) < 0)
- {
- if (errno != EINPROGRESS)
- {
- perror("connect");
- exit(1);
- }
- }
-
- if ((inFile = (FILE *)s_fdopen(s,"r")) == NULL)
- {
- perror("fdopen input");
- exit(1);
- }
- if ((outFile = (FILE *)s_fdopen(s,"w")) == NULL)
- {
- perror("fdopen output");
- exit(1);
- }
- (void) getcrlf(line,sizeof(line)-2,inFile);
- errno = 0;
- while (s_fprintf(outFile,"HELO milligan.utcs.utoronto.ca",line) == EOF)
- {
- if (errno != EALREADY)
- {
- perror("fprintf");
- exit(1);
- }
- fprintf(stderr,"fprintf would block\n");
- errno = 0;
- }
- errno = 0;
- while (s_fflush(outFile) == EOF)
- {
- if (errno != EALREADY)
- {
- perror("fflush");
- exit(1);
- }
- fprintf(stderr,"fflush would block\n");
- errno = 0;
- }
- errno = 0;
- while (s_fprintf(outFile,"\015\012",line) == EOF)
- {
- if (errno != EALREADY)
- {
- perror("fprintf");
- exit(1);
- }
- fprintf(stderr,"fprintf would block\n");
- errno = 0;
- }
- errno = 0;
- while (s_fflush(outFile) == EOF)
- {
- if (errno != EALREADY)
- {
- perror("fflush");
- exit(1);
- }
- fprintf(stderr,"fflush would block\n");
- errno = 0;
- }
- (void) getcrlf(line,sizeof(line)-2,inFile);
- }
-
- getcrlf(buf,n,inFile) char *buf; int n; FILE *inFile;
- {
- char c;
- register char *cs;
- int seenCR;
-
- cs = buf;
- seenCR = 0;
- --n;
- while(n > 0)
- {
- errno = 0;
- c = s_fgetc(inFile);
- if (c == EOF)
- {
- /* no input available or still connecting or writing - don't block */
- if (errno == EWOULDBLOCK || errno == EALREADY)
- {
- tcpCheckNotify();
- perror("getc: would block");
- continue;
- }
- else if (errno == 0)
- {
- fprintf(stderr,"getc: end of file");
- exit(1);
- }
- else
- {
- perror("getc");
- exit(1);
- }
- }
- *cs++ = c;
- --n;
- if (seenCR && c == '\012')
- {
- seenCR = 0;
- cs -= 2;
- *cs++ = '\n';
- break;
- }
- seenCR = (c == '\015');
- }
- if (seenCR /* n-1 bytes read and last was CR */)
- {
- ungetc(inFile);
- cs--;
- }
- *cs++ = '\0';
- fprintf(stderr,"'%s'\n",buf);
- return;
- }
-
- perror(s) char *s;
- {
- (void) fprintf(stderr,"%s: error %d\n",s,errno);
- }