1 /***********************************************************************
5 * Simple command-line program for sending commands to L2TP daemon
7 * Copyright (C) 2002 by Roaring Penguin Software Inc.
9 * This software may be distributed under the terms of the GNU General
10 * Public License, Version 2, or (at your option) any later version.
14 ***********************************************************************/
16 static char const RCSID
[] =
17 "$Id: cmd-control.c,v 1.1.48.1 2005/08/08 12:05:25 honor Exp $";
19 #include <sys/socket.h>
21 #include <sys/types.h>
31 /**********************************************************************
34 * cmd -- command to send to server
36 * file descriptor for channel to server
38 * Sends a command to the server
39 ***********************************************************************/
41 send_cmd(char const *cmd
)
43 struct sockaddr_un addr
;
47 /* Do not send zero-length command */
53 memset(&addr
, 0, sizeof(addr
));
54 addr
.sun_family
= AF_LOCAL
;
55 strncpy(addr
.sun_path
, "/var/run/l2tpctrl", sizeof(addr
.sun_path
) - 1);
57 fd
= socket(AF_LOCAL
, SOCK_STREAM
, 0);
62 if (connect(fd
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
67 v
[0].iov_base
= (char *) cmd
;
68 v
[0].iov_len
= strlen(cmd
);
76 main(int argc
, char *argv
[])
83 fprintf(stderr
, "Usage: %s command\n", argv
[0]);
87 fd
= send_cmd(argv
[1]);
93 n
= read(fd
, buf
, sizeof(buf
));