Added boot process information to help someone find out what really happens.
[bootos.git] / tools / dbgcli.c
blob9c352cbaae45eb84258da9dfdf06e6cb97223ad7
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
7 */
9 #include <arpa/inet.h>
10 #include <netinet/in.h>
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <unistd.h>
15 #include <string.h>
17 #define BUFLEN 2048
18 #define DEBUG_PORT 18194
20 char buf[BUFLEN];
22 int main(void)
24 struct sockaddr_in si_me, si_other;
25 int fd;
26 int len;
27 socklen_t slen = sizeof(si_other);
28 int one = 1;
30 fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
31 if (fd == -1) {
32 perror("socket");
33 return 1;
36 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)) == -1) {
37 perror("setsockopt(SO_BROADCAST)");
38 return 1;
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) {
47 perror("bind");
48 return 1;
51 while (1) {
52 len = recvfrom(fd, buf, BUFLEN, 0, (struct sockaddr *)&si_other, &slen);
53 if (len == -1) {
54 perror("recvfrom");
55 return 1;
57 buf[len] = 0;
58 fputs(buf, stdout);
59 fflush(stdout);