And here's how you can plumb in a simple shell
script to act as a service called localtest to be launched by inetd on port localtest (1111 in /etc/services) for handling incoming TCP connection requests.
This example is from a recent build of Solaris Express / Open Nevada, though it would be sort of similar for older / different Solaris versions.
On LINUX it'd be a simpler case of just editing /etc/services, and /etc/inetd.conf (or /etc/xinetd.d/localtest or whatever it exactly would be with xinetd) and doing a kill -HUP on the inetd process to get it to restart with the new configuration.
(of course that's assuming inetd is installed and enabled in init.d / system services).
In either case the principle and function is the same though the configuration administration commands on the server side are a little different between Solaris / LINUX.
Code:
bash-3.2# tail -1 /etc/services
localtest 1111/tcp # local test program
Code:
bash-3.2# cat /opt/test/localtest.sh
#!/bin/bash
echo "This is a test."
date
Code:
bash-3.2# cat /opt/test/svc_network_test.xml
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='network/localtest' type='service' version='0'>
<restarter>
<service_fmri value='svc:/network/inetd:default'/>
</restarter>
<property_group name='inetd' type='framework'>
<stability value='Evolving'/>
<propval name='isrpc' type='boolean' value='false'/>
<propval name='name' type='astring' value='localtest'/>
</property_group>
<instance name='stream' enabled='true'>
<exec_method name='inetd_start' type='method' exec='/opt/test/localtest.sh' timeout_seconds='0'>
<method_context>
<method_credential user='root' group='root'/>
</method_context>
</exec_method>
<exec_method name='inetd_disable' type='method' exec=':kill' timeout_seconds='0'>
<method_context/>
</exec_method>
<property_group name='inetd' type='framework'>
<propval name='endpoint_type' type='astring' value='stream'/>
<propval name='proto' type='astring' value='tcp6'/>
<propval name='wait' type='boolean' value='false'/>
</property_group>
</instance>
<stability value='Unstable'/>
<template>
<common_name>
<loctext xml:lang='C'>echo</loctext>
</common_name>
</template>
</service>
</service_bundle>
Code:
bash-3.2# svccfg import svc_network_localtest.xml && echo DONE
Code:
bash-3.2# inetadm -l network/localtest
SCOPE NAME=VALUE
name="localtest"
endpoint_type="stream"
proto="tcp6"
isrpc=FALSE
wait=FALSE
exec="/opt/test/localtest.sh"
user="root"
default bind_addr=""
default bind_fail_max=-1
default bind_fail_interval=-1
default max_con_rate=-1
default max_copies=-1
default con_rate_offline=-1
default failrate_cnt=40
default failrate_interval=60
default inherit_env=TRUE
default tcp_trace=FALSE
default tcp_wrappers=FALSE
default connection_backlog=10
Code:
bash-3.2# netstat -na | grep 1111
*.1111 *.* 0 0 49152 0 LISTEN
*.1111 *.* 0 0 49152 0 LISTEN
Code:
bash-3.2# svcs | grep -i localtest
online 4:19:54 svc:/network/localtest:stream
Code:
bash-3.2# nc 127.0.0.1 1111
This is a test.
Thu Aug 7 04:33:36 PDT 2008
bash-3.2# nc 127.0.0.1 1111
This is a test.
Thu Aug 7 04:33:38 PDT 2008
On SXCE/ON as it turns out (nc) was installed by default right from the distribution media given the installation options I chose, so perhaps you're running a much older Solaris or your sysadmin just didn't install it yet.
In this example nc isn't really needed to do anything unless one were to use it at the client side since the server side's networking is handled completely by inetd and the custom server process that takes input from stdin and sends output to stdout. Any client program / process that TCP connected to the server port would get that data back from the server, nc is just one example of a way to do it on the client side in this case.
And here's a different example of what a client side bash script might do using the same inetd server/service as an example:
Code:
bash-3.2# cat < /dev/tcp/127.0.0.1/1111
This is a test.
Thu Aug 7 04:43:29 PDT 2008
In this case the server and client are on the same machine so I just use 127.0.0.1 the localhost address as the server's address, of course it'd work the same on other IP addresses on the server too.