Hi
Is there a way to create a local socket (AF_UNIX) from the shell?
How can I set it's path?
Thanks,
Saul
Is there a way to create a local socket (AF_UNIX) from the shell?
How can I set it's path?
Thanks,
Saul
I don't know what this means (and I'm not talking about the use of "it's"Quote:>How can I set it's path?
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Example: get the current time and date from the "daytime" service:
read </dev/tcp/0.0.0.0/13 # daytime port number = 13
print $REPLY
"Udp" may be substituted for the "tcp" to use the UDP protocol instead
of TCP. 0.0.0.0 is the IP address understood to be the local machine;
127.0.0.1 is analogous.
This is one of the most handy -- and least known -- features of ksh88+.
I presume you mean a socket file (that is, with a ls -l listingQuote:>>How can I set it's path?
> I don't know what this means (and I'm not talking about the use of "it's"
> when you meant "its").
exec 3</dev/tcp/0.0.0.0/13
read -u 3
(etcetera)
It's even... fun... to play around with distributed programming with
the high-level sockets capability provided by ksh. Some version of ksh88
don't even document this, even though I have not seen any version past
88b _not_ have it.
=Brian
The following script gets called from the inetd daemon:
#!/usr/bin/ksh
# test.ksh
test) banner test >> /tmp/test.txt
;;
*) banner NOT >> /tmp/test.txt
;;
esac
The service was added to /etc/service:
kshtest 919191/tcp
Also added to inetd.conf (Script running as user kshuser - I'm sure if
the script needs its own name passed as an argument, i tried without
and same results):
kshtest stream tcp nowait kshuser /usr/local/bin/test.ksh test.ksh
-x
Testing setup - The following should place the word text in the file
/tmp/text.txt but I get NOT instead which tells me that no arguments
are seen:
exec 3<>/dev/tcp/192.168.0.1/919191
print -u3 test
> Is there a way to create a local socket (AF_UNIX) from the shell?
> How can I set it's path?
> Thanks,
> Saul
#!/usr/bin/ksh
#test.ksh
while read line
do
case "$line" in
test) banner test >> /tmp/test.txt
;;
*) banner NOT >> /tmp/test.txt
;;
esac
done
> Is there a way to create a local socket (AF_UNIX) from the shell?
> How can I set it's path?
> Thanks,
> Saul
> I don't think so. Since there aren't any shell commands to bind or connect
> to a socket, what would you do with it if you could?
A local socket (AF_LOCAL or AF_UNIX) is always associated with a fileQuote:> >How can I set it's path?
> I don't know what this means
struct sockaddr_un {
sa_family_t sun_family; /* AF_UNIX */
char sun_path[UNIX_PATH_MAX]; /* pathname */
That's a quoate from man 7 unix:Quote:};
oops. I'm not a native english speaker.Quote:> (and I'm not talking about the use of "it's" when you meant "its").
Here's a C program that demonstrates this:
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
int main(int argc, char *argv[])
{
int fd;
struct sockaddr_un addr;
if (argc != 2) {
fprintf(stderr, "usage: %s socket_path\n", argv[0]);
exit(-1);
}
if ((fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "Can't open socket %s\n", strerror(errno));
exit(-1);
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_LOCAL;
strncpy(addr.sun_path, argv[1], sizeof(addr.sun_path) - 1);
if (bind(fd, (void*)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "Can't bind socket %s\n", strerror(errno));
exit(-1);
}
return 0;
After calling bind() a file of type socket is created at the passedQuote:}
Thanks,
Saul
>> I don't know what this means
>A local socket (AF_LOCAL or AF_UNIX) is always associated with a file
>name on the local file system.
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
>The service was added to /etc/service:
>kshtest 919191/tcp
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
>Very easily.
>Example: get the current time and date from the "daytime" service:
>read </dev/tcp/0.0.0.0/13 # daytime port number = 13
>print $REPLY
>"Udp" may be substituted for the "tcp" to use the UDP protocol instead
>of TCP. 0.0.0.0 is the IP address understood to be the local machine;
>127.0.0.1 is analogous.
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
1. creation of local Usenet newsgroups
We have been asked to create some local Usenet newsgroups.
Our System Administrator is in the hospital and we do not know how
he did it previously. Where should we look to determine the proper
procedure? We run NNTP with B news and the NN newsreader on a HP-UX
Unix machine.
Thank you,
Lee
The University of Medicine and Dentistry of New Jersey (USA)
2. Broadband Routing Advocacy Rrquired
3. raw socket creation prob ..
6. Fonts not found using ghostscript
7. adding kernel credential checks for socket creation
8. ? Do cron jobs even if machine is down when due
9. ping, route - socket creation - file permissions
10. Permission denied on socket creation
11. Socket Creation
12. High Volume TCP Socket Creation
13. Finding a socket's local port number