2 // nclocal - copy stdin to local-domain UNIX socket and output response
6 // gcc nclocal.c -o nclocal
8 // to test, start server:
9 // newlisp -c -d /tmp/mysocket &
11 // verify functioning:
12 // newlisp -e '(net-eval "/tmp/mysocket" 0 "(symbols)")'
15 // echo '(symbols)(exit)' | ./nclocal /tmp/mysocket
17 // for multiline send a [cmd] before and a [/cmd] after the code
18 // each on an extra line.
20 // Copyright (C) 2007 Lutz Mueller <lutz@nuevatec.com>
22 // This program is free software; you can redistribute it and/or modify
23 // it under the terms of the GNU General Public License version 2, 1991,
24 // as published by the Free Software Foundation.
26 // This program is distributed in the hope that it will be useful,
27 // but WITHOUT ANY WARRANTY; without even the implied warranty of
28 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 // GNU General Public License for more details.
31 // You should have received a copy of the GNU General Public License
32 // along with this program; if not, write to the Free Software
33 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 #include <sys/types.h>
42 #include <sys/socket.h>
45 int main(int argc
, char * argv
[])
48 struct sockaddr_un remote_sun
;
54 printf("nclocal - (c) Lutz Mueller, 2007\n");
55 printf("Send stdin to <socket-path> and output response to stdout\n\n");
56 printf("USAGE: nclocal <socket-path> < message-file\n");
62 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1)
68 remote_sun
.sun_family
= AF_UNIX
;
69 strncpy(remote_sun
.sun_path
, sock_path
, sizeof(remote_sun
.sun_path
) - 1);
70 remote_sun
.sun_path
[sizeof (remote_sun
.sun_path
) - 1] = '\0';
72 if (connect(s
, (struct sockaddr
*)&remote_sun
, SUN_LEN(&remote_sun
)) == -1)
78 while(fgets(str
, 100, stdin
), !feof(stdin
))
80 if (send(s
, str
, strlen(str
), 0) == -1)
87 while((t
= recv(s
, str
, 100, 0)) > 0)
93 if(t
< 0) perror("recv");