Hi,
There is a small bug in socket.c, this bug makes socket not take
the right portnumber depending on your endian (little or big).
Anyway here is the patch to appli to socket.c
--------------------------------------------------------------------------
*** socket.c.org Wed Dec 21 13:55:59 1994
--- socket.c Wed Jan 25 20:03:35 1995
***************
*** 149,155 ****
if(NINTEGERP(portnum))
err("not a port number", portnum);
! sin.sin_port = INTEGER(portnum);
sin.sin_addr.s_addr = INADDR_ANY;
if((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
err(sys_errlist[errno], portnum);
--- 149,155 ----
if(NINTEGERP(portnum))
err("not a port number", portnum);
! sin.sin_port = htons(INTEGER(portnum));
sin.sin_addr.s_addr = INADDR_ANY;
if((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
err(sys_errlist[errno], portnum);
***************
*** 168,174 ****
/* now we're ready to create the object */
NEWCELL(ys, tc_sockhandle);
LSOCKHANDLE(ys) = (struct socket_handle*)must_malloc(sizeof (struct
socket_handle));
! SOCKHANDLE(ys)->portnum = sin.sin_port;
SOCKHANDLE(ys)->hostname = (char*)must_malloc(strlen("localhost")+1);
strcpy(SOCKHANDLE(ys)->hostname, "localhost");
SOCKHANDLE(ys)->handle = s;
--- 168,174 ----
/* now we're ready to create the object */
NEWCELL(ys, tc_sockhandle);
LSOCKHANDLE(ys) = (struct socket_handle*)must_malloc(sizeof (struct
socket_handle));
! SOCKHANDLE(ys)->portnum = ntohs(sin.sin_port);
SOCKHANDLE(ys)->hostname = (char*)must_malloc(strlen("localhost")+1);
strcpy(SOCKHANDLE(ys)->hostname, "localhost");
SOCKHANDLE(ys)->handle = s;
***************
*** 220,229 ****
if(NINTEGERP(portnum)) err("bad port number", portnum);
hp = gethostbyname(hn = CHARS(hostname));
if(!hp) err("unknown or misspelled host name", hostname);
bzero((char*)&server,sizeof server);
bcopy(hp->h_addr,(char*)&server.sin_addr, hp->h_length);
server.sin_family = hp->h_addrtype;
! server.sin_port = INTEGER(portnum);
if((s = socket(AF_INET,SOCK_STREAM,0)) < 0)
err(sys_errlist[errno], NIL);
if(connect(s, (struct sockaddr *)&server, sizeof server) < 0)
--- 220,234 ----
if(NINTEGERP(portnum)) err("bad port number", portnum);
hp = gethostbyname(hn = CHARS(hostname));
if(!hp) err("unknown or misspelled host name", hostname);
+ #ifdef SUNOS5
+ memset (&server, 0, sizeof server);
+ memcpy ((char*)&server.sin_addr, hp->h_addr, hp->h_length);
+ #else
bzero((char*)&server,sizeof server);
bcopy(hp->h_addr,(char*)&server.sin_addr, hp->h_length);
+ #endif
server.sin_family = hp->h_addrtype;
! server.sin_port = htons(INTEGER(portnum));
if((s = socket(AF_INET,SOCK_STREAM,0)) < 0)
err(sys_errlist[errno], NIL);
if(connect(s, (struct sockaddr *)&server, sizeof server) < 0)
***************
*** 240,246 ****
break;
default: err(sys_errlist[errno], NIL);
}
! return makesp(s, hn, server.sin_port);
}
PRIMITIVE shutdown_connection(SCM skt)
--- 245,251 ----
break;
default: err(sys_errlist[errno], NIL);
}
! return makesp(s, hn, ntohs(server.sin_port));
}
PRIMITIVE shutdown_connection(SCM skt)
-----------------------------------------------------------------------
and this is a simple client program, to verify you e-mail address
#!/users/furrer/scheme/bin/stk -file
;; simple program that does a vrfy of the given mail address
;; through the maildelivery host
;;; remove the window
(wm 'withdraw *root*)
;;; configuration
(define mail-host "ltidec1.epfl.ch")
(define smtp-port 25)
;;; verify args
(define (usage)
(format #t "usage: ~a mailaddr\n" *program-name*)
(define mail-addr "furrer_at_di")
(format #t "using ~a as default mail address\n" mail-addr))
(if (not (= *argc* 1))
(usage)
(define mail-addr (list-ref *argv* 0)))
;;; socket connection
(require "socket")
(define sock (open-client-socket mail-host smtp-port))
(define sock-in-port (car sock))
(define sock-out-port (cadr sock))
;;; read until welcome message
(display "connected...\n")
(do
((line (read-line sock-in-port) (read-line sock-in-port)))
((string=? "220" (substring line 0 3)) #t)
(display line))
;;; send command
(display "sending command\n")
(display (string-append "vrfy " mail-addr "\n") sock-out-port)
;;; display answer
(display "displaying answer\n")
(display (read-line sock-in-port))
;;; close connection
(close-port sock-in-port)
(close-port sock-out-port)
(bye)
---------------------------
enjoy,
Marc.
--
Furrer Marc EPFL DI-LTI, 1015 Lausanne, Suisse
Marc.Furrer_at_di.epfl.ch +41 21 693 29 07 / 66 00 (Fax)
http://ltiwww.epfl.ch/~furrer
--
You are a wise man my friend.
Not yet sir. But with your help, I am learning.
-- Riker and Data, "The Measure of a Man", stardate 42523.7
--
PGP 2.6 encrypted mail are welcomed, public key on nearest server
Received on Wed Jan 25 1995 - 20:22:25 CET