2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program 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 2 of the License, or
8 (at your option) any later version.
10 This program 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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <arpa/inet.h>
27 /** aborts program with a printf like message */
29 die (const char *msg
, ...)
41 HexDump (const uchar
* data
, int Len
)
43 for (int i
= 0; i
< Len
; i
++)
44 printf (" %02X", data
[i
]);
49 main (int ac
, char *ag
[])
54 bool shortlist
= false;
56 if (ac
!= 2 && ac
!= 3)
58 ("Usage: %s [/]ip[:dst-port[:src-port]] [tracelevel] use - as default ip",
60 struct sockaddr_in saddr
;
61 struct sockaddr_in caddr
;
63 pth_event_t timeout
= pth_event (PTH_EVENT_RTIME
, pth_time (10, 0));
68 tracelevel
= atoi (ag
[2]);
71 die ("out of memory");
84 for (c
= b
+ 1; *c
; c
++)
98 t
.SetTraceLevel (tracelevel
);
100 a
= (char *) "224.0.23.12";
102 printf ("Asking %s at port %d from port %d\n\n", a
, dport
, sport
);
104 if (!GetHostIP (&caddr
, a
))
105 die ("Host not found");
106 caddr
.sin_port
= htons (dport
);
107 if (!GetSourceAddress (&caddr
, &saddr
))
108 die ("No route found");
109 saddr
.sin_port
= htons (sport
);
110 sock
= new EIBNetIPSocket (saddr
, 0, &t
);
111 sock
->sendaddr
= caddr
;
112 sock
->recvaddr
= caddr
;
115 die ("IP initialisation failed");
117 EIBnet_SearchRequest req
;
118 EIBnet_SearchResponse resp
;
121 sock
->Send (req
.ToPacket ());
124 p1
= sock
->Get (timeout
);
127 if (parseEIBnet_SearchResponse (*p1
, resp
))
129 printf ("Invalid Search response\n");
132 printf ("Answer from %s at port %d\n",
133 inet_ntoa (resp
.caddr
.sin_addr
),
134 ntohs (resp
.caddr
.sin_port
));
137 printf ("Addr: %s\n", FormatEIBAddr (resp
.individual_addr
) ());
138 printf ("Name: %s\n", resp
.name
);
143 ("Medium: %d\nState: %d\nAddr: %s\nInstallID: %d\nSerial:",
144 resp
.KNXmedium
, resp
.devicestatus
,
145 FormatEIBAddr (resp
.individual_addr
) (), resp
.installid
);
146 HexDump (resp
.serial
, sizeof (resp
.serial
));
147 printf ("Multicast-Addr: %s\nMAC:",
148 inet_ntoa (resp
.multicastaddr
));
149 HexDump (resp
.MAC
, sizeof (resp
.MAC
));
150 printf ("Name: %s\n", resp
.name
);
151 for (int i
= 0; i
< resp
.services (); i
++)
152 printf ("Service %d Version %d\n", resp
.services
[i
].family
,
153 resp
.services
[i
].version
);