Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!columbia!garfield!ji From: ji@garfield.columbia.edu (John Ioannidis) Newsgroups: net.unix-wizards,net.unix Subject: Re: Help on sockets needed! Message-ID: <1405@garfield.columbia.edu> Date: Thu, 27-Feb-86 21:50:42 EST Article-I.D.: garfield.1405 Posted: Thu Feb 27 21:50:42 1986 Date-Received: Sat, 1-Mar-86 17:41:18 EST References: <507@asuvax.UUCP> Distribution: net Organization: Columbia University CS Department Lines: 236 Xref: watmath net.unix-wizards:16986 net.unix:7229 In article <507@asuvax.UUCP>, system@asuvax.UUCP (Marc Lesure) writes: > Here at Arizona State University we have a class being taught which requires > the students to use sockets. The problem we have is that when these users > start running their software, our VAX hangs and the only way to recover is > to hard crash the VAX. I've looked at the routines the students have > written and they seem to follow what the documentation says (I'm not that > familiar with the socket software). > > Is there an error(s) in the documentation? Are you kidding? errors or omissions in the Unix documentation? > Is there a limit on the number of sockets that can used at any on time? There is only that limit of the #of processes trying to connect to a specific socket. (As specified in the listen(2) call) > Do sockets prevent dead-locking situations? Most probably they create dlock's inside the kernel :-) > > We are running a VAX 11/780 with 4.2bsd. > From the description, I understand that the problem is with Unix domain (AF_UNIX) sockets. Two programs that demonstrate the use of unix-domain sockets are the following. Compile the as follows: $ cc und_send.c -o us $ cc und_recv.c -o ur and execute them : $ ur& $ us Then, you'll (hopefully!) get the following output, which comes from ur: Accepted! Lenght:110 Family: 1 Path: yourself Got peer! Lenght:110 Family: 0 Path: Read: Hello, yourself! Of course, like it says in the manual, the peer's family is always 0 and the path doesn't make sense. Sorry that the programs are not very well commented (the code is obvious :-) ) but I just don't have the time to add them right now. So, enjoy: ----------CUT HERE: und_send.c ------------ #include #include #include /* * I included here and changed the path length from 109 to 108. * Don't ask me why -- it works this way, but didn't with 109!!! */ /* un.h 6.1 83/07/29 */ /* * Definitions for UNIX IPC domain. */ struct sockaddr_un { short sun_family; /* AF_UNIX */ char sun_path[108]; /* path name (gag) [mod by ji] */ }; #ifdef KERNEL int unp_discard(); #endif main() { int sm; struct sockaddr_un myself; struct sockaddr_un yourself; bzero( &myself, sizeof( myself ) ); bzero( &yourself, sizeof( yourself ) ); myself.sun_family = AF_UNIX; yourself.sun_family = AF_UNIX; strcpy( myself.sun_path, "myself" ); strcpy( yourself.sun_path, "yourself" ); sm = socket( AF_UNIX, SOCK_STREAM, 0, 0 ); if( sm < 0 ) { perror( "und_send: socket" ); exit(1); } unlink( "myself" ); if( bind( sm, &myself, sizeof( myself ) ) < 0 ) { perror( "und_send: bind" ); exit( 1 ); } if( connect( sm, &yourself, sizeof( yourself ) ) < 0 ) { perror( "und_send: connect" ); exit( 1 ); } if( write( sm, "Hello, yourself!", 17 )<0 ) perror( "und_send: write" ); } -------------CUT HERE: und_recv.c ----------- #include #include #include /* un.h 6.1 83/07/29 */ /* * Definitions for UNIX IPC domain. */ struct sockaddr_un { short sun_family; /* AF_UNIX */ char sun_path[108]; /* path name (gag) [mod by ji] */ }; #ifdef KERNEL int unp_discard(); #endif main() { /* Now, I am YOURSELF!!! */ int i, sm, as, rfds, mylen, hislen; char buf[80]; struct sockaddr_un myself; struct sockaddr_un yourself; struct sockaddr_un himself; bzero( &myself, sizeof( myself ) ); bzero( &yourself, sizeof( yourself ) ); bzero( &himself, sizeof( himself ) ); yourself.sun_family = AF_UNIX; strcpy( yourself.sun_path, "yourself" ); sm = socket( AF_UNIX, SOCK_STREAM, 0, 0 ); if( sm < 0 ) { perror( "und_recv: socket" ); exit(1); } unlink( "yourself" ); if( bind( sm, &yourself, sizeof( yourself ) ) < 0 ) { perror( "und_recv: bind" ); exit( 1 ); } if( listen( sm, 5 ) < 0 ) { perror( "und_recv: listen" ); exit( 1 ); } /* * SCREAM OF JOY !!!!!!!!!! * The key to success is the following select statement * I saw that in a program our system administrator had * given me quite some time ago, but which did not otherwise * work like I wanted it to. Also note that the select(2) * call is somewhat changed in 4.3, so beware. */ rfds = 1 << sm; select( 20, &rfds, 0, 0, 0 ); mylen = sizeof( myself ); if( ( as=accept( sm, &myself, &mylen )) < 0 ) { perror( "und_recv: accept" ); exit( 1 ); } printf( "Accepted!\n\tLenght:%d\n\tFamily: %d\n\tPath: %s\n\n", mylen, myself.sun_family, myself.sun_path ); hislen = sizeof( himself ); getpeername( as, &himself, &hislen ); printf( "Got peer!\n\tLenght:%d\n\tFamily: %d\n\tPath: ", hislen, himself.sun_family ); for( i=0; i VOICE: +1 212 280 5510 ARPA: ioannidis@cs.columbia.EDU USnail: John Ioannidis ji@garfield.columbia.EDU 450 Computer Science Columbia University, USENET: ...{seismo|topaz}! New York, NY 10027 columbia!garfield!ji ... It's all Greek to me!