]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/ncb.c
tools: Add ifdtool to .gitignore
[people/ms/u-boot.git] / tools / ncb.c
CommitLineData
eea8be86 1#include <stdio.h>
eedcd078
WD
2#include <stdlib.h>
3#include <unistd.h>
4#include <sys/socket.h>
ecf3fb22 5#include <netinet/in.h>
eedcd078
WD
6
7int main (int argc, char *argv[])
8{
9 int s, len, o, port = 6666;
10 char buf[512];
11 struct sockaddr_in addr;
fadad157 12 socklen_t addr_len = sizeof addr;
eedcd078
WD
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;
eea8be86
PT
33 if (write (1, buf, len) != len)
34 fprintf(stderr, "WARNING: serial characters dropped\n");
eedcd078
WD
35 }
36
37 return 0;
38}