/camera/camlib

To get this branch, use:
bzr branch http://darksoft.org/webbzr/camera/camlib

« back to all changes in this revision

Viewing changes to pfcontrol/fgclient.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-13 01:33:37 UTC
  • Revision ID: csa@dside.dyndns.org-20110213013337-ibm4w4n5a3hu4k7u
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <unistd.h>
 
5
#include <sys/stat.h>
 
6
#include <sys/types.h>
 
7
#include <sys/socket.h>
 
8
#include <sys/un.h>
 
9
#include <errno.h>
 
10
 
 
11
 
 
12
#define read_socket "/tmp/pfserver.socket"
 
13
 
 
14
int main(int argc, char **argv) {
 
15
        char data[2048];
 
16
        int sock;
 
17
        int res;
 
18
 
 
19
        struct sockaddr_un servername;
 
20
        
 
21
        sock = socket (PF_UNIX, SOCK_STREAM, 0);
 
22
 
 
23
        memset(&servername, 0, sizeof(servername));
 
24
        servername.sun_family = AF_UNIX;
 
25
        strncpy(servername.sun_path,read_socket,sizeof(servername.sun_path));
 
26
        servername.sun_path[sizeof(servername.sun_path) - 1]=0;
 
27
 
 
28
        if (connect (sock, (struct sockaddr *) &servername, sizeof (servername)) < 0){
 
29
                fprintf(stderr, "Connection to socket is failed, error: %i\n", errno);
 
30
                exit(-1);
 
31
        }
 
32
 
 
33
        if (argc < 2) {
 
34
            printf("Usage: %s <property> [value]\n", argv[0]);
 
35
            exit(0);
 
36
        }
 
37
 
 
38
        if (argc > 2) {
 
39
            res = snprintf(data, 2048, "%s %s", argv[1], argv[2]);
 
40
            write(sock, data, res);
 
41
        } else {
 
42
            write(sock, argv[1], strlen(argv[1]));
 
43
        }
 
44
 
 
45
        res = read(sock, data, 2048);
 
46
        if (res > 0) {
 
47
            data[res] = 0;
 
48
            puts(data);
 
49
        }
 
50
        
 
51
        close(sock);
 
52
        
 
53
        return 0;
 
54
}