1 /* dbgcli.c - printf over UDP debugging client
3 Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
5 This code is licensed to you under the terms of the GNU GPL, version 2;
6 see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 #include <netinet/in.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
18 #define DEBUG_PORT 18194
24 struct sockaddr_in si_me
, si_other
;
27 socklen_t slen
= sizeof(si_other
);
30 fd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
36 if (setsockopt(fd
, SOL_SOCKET
, SO_BROADCAST
, &one
, sizeof(one
)) == -1) {
37 perror("setsockopt(SO_BROADCAST)");
41 memset((char *) &si_me
, 0, sizeof(si_me
));
42 si_me
.sin_family
= AF_INET
;
43 si_me
.sin_port
= htons(DEBUG_PORT
);
44 si_me
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
46 if (bind(fd
, (struct sockaddr
*)&si_me
, sizeof(si_me
)) == -1) {
52 len
= recvfrom(fd
, buf
, BUFLEN
, 0, (struct sockaddr
*)&si_other
, &slen
);