vd09+@ANDREW.CMU.EDU ("Vincent M. Del Vecchio") (09/01/90)
I am trying to write a network daemon-type program which will not be called from inetd, but which other users can telnet to. However, when I try to telnet, I get a connection refused. I can write another program which will connect fine, but telnet seems to be looking for something else. I looked at the code for inetd (which handles these things for most daemons) and it was a bit of a mess, but the only thing that I saw was that I might not have been setting socket options that I needed to. Does anyone have any ideas? The relevant portion of the code follows: #include <string.h> #include <strings.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> main() { struct sockaddr_in sockad, oend; int sock, accepteds, size = sizeof (sockad), osize = sizeof (oend), buf[100]; if ((sock = socket(AF_INET, SOCK_STREAM, 0, 0)) == -1) perror ("creating socket"), exit(1); sockad.sin_family = AF_INET; sockad.sin_port = 3007; /* The port we'll try to telnet to */ sockad.sin_addr.S_un.S_addr = INADDR_ANY; if (bind (sock, &sockad, sizeof (sockad)) == -1) perror ("binding socket"), exit(1); if (getsockname (sock, &sockad, &size) == -1) perror ("Bad address for socket"), exit(1); printf ("%d\\n",sockad.sin_port); if (listen (sock,5) == -1) perror ("listening on socket"), exit(1); printf ("Waiting\\n"); do { errno = 0; osize = sizeof (oend); accepteds = accept(sock, &oend, &osize); } while (accepteds == -1 && errno == EINTR); if (accepteds == -1) perror ("accepting on socket"), exit(1); printf ("Accepted"); process(accepteds); } It's not very well (or at all) commented, but it's fairly short. It prints out the port number 3007, and "Waiting" and then sits... when I try to telnet, it says "Connection refused," and the program doesn't do anything; just keeps waiting. I would very much appreciate any ideas. TIA, and, as I don't read this board normally, please respond via email. If there is interest (please mail me also) I will summarize. +----------------------------------------------------------------------------+ | Vincent Del Vecchio \ vd09+@andrew.cmu.edu | | Box 4872 \ Reserved for another email address. | | 5125 Margaret Morrison St.\ Reserved for a quote | | Pittsburgh, PA 15213 \ Reserved for a standard disclaimer | +----------------------------------------------------------------------------+
cpw%snow-white@LANL.GOV (C. Philip Wood) (09/04/90)
Vincent, Your program (with a dummy process routine) worked for me. Is your telnet particular about the size of a port number? % telnet localhost 3007 Trying 127.0.0.1 ... Connected to localhost. Escape character is '^]'. Connection closed by foreign host. % Phil