Commit | Line | Data |
---|---|---|
06570394 TB |
1 | /* Copyright (C) 2018 Thomas Balzer */ |
2 | ||
3 | /* This file is part of tomd. */ | |
4 | ||
5 | /* tomd is free software: you can redistribute it and/or modify */ | |
6 | /* it under the terms of the GNU General Public License as published by */ | |
7 | /* the Free Software Foundation, either version 3 of the License, or */ | |
8 | /* (at your option) any later version. */ | |
9 | ||
10 | /* tomd is distributed in the hope that it will be useful, */ | |
11 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 | /* GNU General Public License for more details. */ | |
14 | ||
15 | /* You should have received a copy of the GNU General Public License */ | |
16 | /* along with tomd. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include <stdlib.h> | |
19 | #include <stdio.h> | |
20 | #include <sys/un.h> | |
21 | #include <sys/socket.h> | |
22 | #include <unistd.h> | |
23 | ||
24 | static int sfd; | |
25 | ||
26 | static void init(void) | |
27 | { | |
28 | /* init socket connection */ | |
29 | sfd = | |
30 | socket(PF_LOCAL, | |
31 | SOCK_STREAM, | |
32 | 0); | |
33 | if(sfd < 0){ | |
34 | perror("socket"); | |
35 | exit(EXIT_FAILURE); | |
36 | } | |
37 | ||
38 | struct sockaddr_un addr; | |
39 | addr.sun_family = AF_LOCAL; | |
40 | sprintf(addr.sun_path, "/run/user/1000/tomd/socket"); | |
41 | ||
42 | if(connect(sfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) != 0){ | |
43 | perror("connect"); | |
44 | exit(EXIT_FAILURE); | |
45 | } | |
46 | } | |
47 | ||
48 | #define HALLO "hallo there from dumb-client" | |
49 | ||
50 | void write_hallo(void) | |
51 | { | |
52 | printf("writing hallo\n"); | |
53 | ssize_t wrote = | |
54 | write(sfd, HALLO, sizeof HALLO); | |
55 | printf("wrote %d bytes.\n", wrote); | |
56 | } | |
57 | ||
58 | static void header(void) | |
59 | { | |
60 | tomd_p("Tom's Client, Copyright (C) 2018 Thomas Balzer"); | |
61 | tomd_p("GPL v3 or later license."); | |
62 | } | |
63 | ||
64 | int main(int argc, char **argv) | |
65 | { | |
66 | header(); | |
67 | init(); | |
68 | write_hallo(); | |
69 | ||
70 | return EXIT_SUCCESS; | |
71 | } |