File: miniclient.c

package info (click to toggle)
prismstumbler 0.7.0-2.1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,932 kB
  • ctags: 2,275
  • sloc: ansic: 22,108; sh: 2,525; makefile: 438; lex: 381; yacc: 279
file content (106 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* 
 *
 * prismstumbler miniclient 
 * (c) 2003 Florian Boor <florian.boor@kernelconcepts.de>
 *
 */
 
 
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include "../include/prismstumbler.h"

psconfig_t cfg = { 1, "eth0", DT_ORINOCO, 40000, 0 ,0, 1,"\0"};
static int sock = 0;

void stop_signal()
{
	// do something intelligent
	exit(0);
}

void
send_command (command_t cmd)
{
	psmessage_t msg;
	msg.type = msg_command;
	msg.content.command.command = cmd;

	if (write (sock, (void *) &msg, sizeof (psmessage_t)) < 0)
	{
		perror ("err sending command");
	}
}

void
send_config ()
{
	psmessage_t msg;
	msg.type = msg_config;
	msg.content.cfg = cfg;
	
	if (write (sock, (void *) &msg, sizeof (psmessage_t)) < 0)
	{
		perror ("err sending config data");
	}
}


int main()
{
   int length;
   struct sockaddr_un name;
   psmessage_t buf;

	signal (SIGINT, stop_signal);
	signal (SIGTERM, stop_signal);
	signal (SIGCHLD, stop_signal);
   
   /* Create socket from which to read. */
   sock = socket(AF_UNIX, SOCK_STREAM, 0);
   if (sock < 0) {
      perror("opening datagram socket");
      exit(1);
   }
  

   /* Create name. */
   name.sun_family = AF_UNIX;
   strcpy(name.sun_path, PS_SOCKET);
   if (connect(sock, (struct sockaddr *)&name, SUN_LEN(&name))) {
      perror("connecting to socket");
      exit(1);
   }
   

   printf("socket -->%s\n", PS_SOCKET);
   
   send_config();
   send_command(C_DETECT_CARD);
   
   
   /* Read from the socket. */
   for (;;)
   {
   		if (read(sock, (void*)&buf, sizeof(psmessage_t)) < 0)
		{
      		perror("err receiving datagram packet");
   			close(sock);
			exit(1);
		}
			switch (buf.type)
			{
				case (msg_network):
   					printf("-->%s\n", buf.content.net.bssid);
				break;	
				default:
				break;				
			}
		
	}
   close(sock);
   
   exit(0);
}