HP3000-L Archives

June 1996, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jeff Kell <[log in to unmask]>
Reply To:
Jeff Kell <[log in to unmask]>
Date:
Fri, 14 Jun 1996 13:55:04 EDT
Content-Type:
text/plain
Parts/Attachments:
text/plain (84 lines)
On Fri, 14 Jun 1996 10:14:10 -0700 Dan Hollis said:
>The MPE domain cannot redirect socket descriptors. E.g. you can't connect
>STDIN/STDOUT to a socket. Also, the MPE domain has no access to UDP, and
>it is very difficult to get the remote address (e.g. client) of a
>connection. You can do it, but it requires priv mode.
>
>Also, POSIX domain sockets are (AFAIK) only available from NM code. This
>means POSIX domain sockets from SPL and the like is not possible.
 
Also, opening call sockets on ports < 1024 requires PM with BSD, MPE or not
(as far as I know); not based on you being "root".
 
But my main point was the subtle differences in socket vs file descriptors.
I dug around in the archives and found the details in a e-mail exchange I had
with Mike Belshe while he was at CSY with regard to the apparent behavior in
unix whereby "files" and "sockets" seem rather similar:
 
Jeff Kell ([log in to unmask]) wrote:
: I don't know which "standards" define exactly what behavior, but the
: following code snippet is from the FreeBSD distribution whois.c which
: does the "questionable" fdopen().
 
:         if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
:                 perror("whois: connect");
:                 exit(1);
:         }
:         sfi = fdopen(s, "r");
:         sfo = fdopen(s, "w");
:         if (sfi == NULL || sfo == NULL) {
:                 perror("whois: fdopen");
:                 (void)close(s);
:                 exit(1);
:         }
:         while (argc-- > 1)
:                 (void)fprintf(sfo, "%s ", *argv++);
:         (void)fprintf(sfo, "%s\r\n", *argv);
:         (void)fflush(sfo);
:         while ((ch = getc(sfi)) != EOF)
:                 putchar(ch);
:         exit(0);
 
: In other words, they get to use file I/O on the sockets.  In contrast,
: the FreeBSD "finger" does an fdopen() then uses read() and write(), and
: as you mentioned, this works fine.
 
Looks like you are right.  I wrote a little program with the following:
 
   int sock;    /* socket descriptor */
   FILE *fp;    /* file pointer to use with socket */
 
   .
   .
   .
 
   fp = fdopen(sock, "rw");
 
   write(sock,"write works\n",12);
   send(fileno(fp),"send to fileno(fp) works\n",25, 0);
   send(sock,"send to sock works\n",19, 0);
   fprintf(fp,"if this works I will be amazed\n");
   fwrite("fwrite works\n",  sizeof(char), 13, fp);
 
Output:
hpcsyn22-ttyp2(/users/mbelshe) % telnet romeo 8000
Trying...
Connected to romeo.cup.hp.com.
Escape character is '^]'.
write works
send to fileno(fp) works
send to sock works
Connection closed by foreign host.
 
So I'd guess you are right.  The sockets calls are not accessible via
the buffered IO calls (fwrite, fprintf, etc).
 
File an SR!
 
Mike
 
---
Mike Belshe
[log in to unmask]
HP CSY Networking Lab

ATOM RSS1 RSS2