c0325eef0e08e0c57da9f090254033a37c439828
[tlb/tomd.git] / src / tomc / main.c
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 #include "../../include/macros.h"
25
26 static int sfd;
27
28 static void init(void)
29 {
30 /* init socket connection */
31 sfd =
32 socket(PF_LOCAL,
33 SOCK_STREAM,
34 0);
35 if(sfd < 0){
36 perror("socket");
37 exit(EXIT_FAILURE);
38 }
39
40 struct sockaddr_un addr;
41 addr.sun_family = AF_LOCAL;
42 sprintf(addr.sun_path, "/run/user/1000/tomd/socket");
43
44 if(connect(sfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) != 0){
45 perror("connect");
46 exit(EXIT_FAILURE);
47 }
48 }
49
50 #define HALLO "hallo there from dumb-client"
51
52 void write_hallo(void)
53 {
54 printf("writing hallo\n");
55 ssize_t wrote =
56 write(sfd, HALLO, sizeof HALLO);
57 printf("wrote %d bytes.\n", wrote);
58 }
59
60 static void header(void)
61 {
62 tomd_p("Tom's Client, Copyright (C) 2018 Thomas Balzer");
63 tomd_p("GPL v3 or later license.");
64 }
65
66 int main(int argc, char **argv)
67 {
68 header();
69 init();
70 write_hallo();
71
72 return EXIT_SUCCESS;
73 }