Thanks, I've added this to tcp.scm.
cheers, felix On 11/15/05, Daishi Kato <[EMAIL PROTECTED]> wrote: > As far as I understand, there is no way in tcp.scm, > to get port numbers of connected sockets. > tcp-addresses is available, which returns only IP addresses. > tcp-addresses could be modified so that > it returns four values including port numbers, > however, for backward compatibility I would suggest > tcp-port-numbers that returns two values. > It would be something like this: > > (define (tcp-port-numbers p) > (let ([fd (##sys#tcp-port->fileno p)]) > (values > (or (##net#getsockport fd) > (##sys#signal-hook #:network-error 'tcp-port-numbers > (##sys#string-append "can not compute local port - " strerror) p) ) > (or (##net#getpeerport fd) > (##sys#signal-hook #:network-error 'tcp-port-numbers > (##sys#string-append "can not compute remote port - " strerror) p) ) ) ) ) > > (define ##net#getpeerport > (foreign-lambda* int ([int s]) > "struct sockaddr_in sa;" > "int len = sizeof(struct sockaddr_in);" > "if(getpeername(s, (struct sockaddr *)&sa, (socklen_t *)(&len)) != 0) > return(-1);" > "else return(ntohs(sa.sin_port));") ) > > [just copied from tcp.scm and slightly modified.] > > Any comments? > > Daishi > > > _______________________________________________ > Chicken-users mailing list > [email protected] > http://lists.nongnu.org/mailman/listinfo/chicken-users > _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
