xref: /openbmc/u-boot/tools/ncb.c (revision ccb71dfa)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/socket.h>
5 #include <netinet/in.h>
6 
main(int argc,char * argv[])7 int main (int argc, char *argv[])
8 {
9 	int s, len, o, port = 6666;
10 	char buf[512];
11 	struct sockaddr_in addr;
12 	socklen_t addr_len = sizeof addr;
13 
14 	if (argc > 1)
15 		port = atoi (argv[1]);
16 
17 	s = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
18 
19 	o = 1;
20 	len = 4;
21 	setsockopt (3, SOL_SOCKET, SO_REUSEADDR, &o, len);
22 
23 	addr.sin_family = AF_INET;
24 	addr.sin_port = htons (port);
25 	addr.sin_addr.s_addr = INADDR_ANY;	/* receive broadcasts */
26 
27 	bind (s, (struct sockaddr *) &addr, sizeof addr);
28 
29 	for (;;) {
30 		len = recvfrom (s, buf, sizeof buf, 0, (struct sockaddr *) &addr, &addr_len);
31 		if (len < 0)
32 			break;
33 		if (write (1, buf, len) != len)
34 			fprintf(stderr, "WARNING: serial characters dropped\n");
35 	}
36 
37 	return 0;
38 }
39