Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inetd problem

Status
Not open for further replies.

cag27

Programmer
Mar 1, 2001
9
US
My question encompasses quite a few different forums, but since I'm having problems with Perl on a Red Hat Linux machine, I'll try here first.

Basically, I have a Linux server program (written in Perl)making a socket connection with a Windows NT client program (written in Visual Basic). Once the client connects to the server, the client passes information read from a file through the socket connection to the server.

When I originally wrote the code for the server, I specifically created the server socket, accepted the client connection, and used "recv" to get data from the client (using the IO::Socket and Net::hostent modules) -- that worked fine. Now, I need to use inetd on the server side to complete the steps I had previously specifically coded, and I am not receiving data through the socket connection.

hosts.allow and hosts.deny are fine, and I added the following line to inetd.conf:

mrpt stream tcp nowait root /usr/sbin/tcpd /solid/socket.pl

and the following line was added to /etc/services:

mrpt port #/tcp (where 'port #' is the actual numeric
port number)

I have spent the last two days searching for information on inetd, and I can not figure out what is preventing the client data from making it over to the server. I do think the roadblock has to do with how data is received (or in this case, not received) on the server side. In my original version (non-inetd) I used the following code:

....

use IO::Socket;
use Net::hostent;

#length of the input buffer
my $buffer = 10000;

#line read from the client
my $array_list = "";

....

#create a new socket
my $sock = new IO::Socket::INET(
LocalAddr => 'bug',
LocalPort => $PORT,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);

#output an error message if socket could not be created
die "Could not create socket: $!\n" unless $sock;

#accept a connection to the socket
my $new_sock = $sock->accept(0);

....

while( defined(<$new_sock>) )
{
recv($new_sock, $array_list, $buffer, 0);
....
}

....

close($sock);

How would I convert this code for use with the inetd configuration? Any suggestions would be greatly appreciated.

Thank you,
Carrie
 
This should have been included in my previous post -- what I'm looking for is the &quot;inetd&quot; equivalent of the <$new_sock> handle in the above code; I am not sure how to refer to the server-side socket using the inetd configuration. Thanks again,

Carrie
 
Carrie,

This is probably a stupid question, since from what you're writing you know somewhat more than I do about inetd, but --- did you tell inetd to read inetd.conf again with the kill -1 command? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I did update inetd with the 'kill' command -- the client/server socket connection itself works fine (the two machines are communicating), I just can't figure out how to pass data from the VB client to the Linux server. In researching this, I did come across a website which said:

&quot;INETD COMMENTS:
For each service listed in /etc/inetd.conf the inetd(1M) process, and that is a process is started at boot time, executes the socket(3N), bind(3N), listen(3N) and accept(3N) calls as discussed above. Inetd also handles many of the daemon issues (signal handling, set process group and controlling tty) which we've studiously avoided.

The inetd(1M) process spawns the appropriate server application (with fork(2) and exec(2)) when a client connects to the service port. The daemon continues to listen for further connections to the service while the spawned child process handles the request which just came in.

The server application (ie. the child spawned by inetd(1M)) is started with stdin and stdout connected to the remote host.port of the client process which made the connection. Any input/output by the server appliation on stdin/stdout are sent/received by the client application. You have Inter Process Communication (or IPC)!

This means, any application written to use stdin/stdout can be a server application. Writing a server application should therefore be fairly simple.&quot;

I'm interpreting this to mean that I should be able to use <STDIN> as the file handle on the server side, but I could not get that to work, either. I am truly stumped! I'm going to continue working on this, and if I stumble upon the answer, I'll post it.

Thanks,
Carrie

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top