blob: ec8d8a7435208e432b81b8daf29be868ec408921 [file] [log] [blame]
Peter Tysera79c6bb2009-04-24 15:59:46 -05001#include <stdio.h>
wdenka0ebde52004-09-08 22:03:11 +00002#include <stdlib.h>
3#include <unistd.h>
4#include <sys/socket.h>
Wolfgang Denkb8664ab2009-04-04 16:14:51 +02005#include <netinet/in.h>
wdenka0ebde52004-09-08 22:03:11 +00006
7int main (int argc, char *argv[])
8{
9 int s, len, o, port = 6666;
10 char buf[512];
11 struct sockaddr_in addr;
Mike Frysingerb35beab2009-01-09 04:38:17 -050012 socklen_t addr_len = sizeof addr;
wdenka0ebde52004-09-08 22:03:11 +000013
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;
Peter Tysera79c6bb2009-04-24 15:59:46 -050033 if (write (1, buf, len) != len)
34 fprintf(stderr, "WARNING: serial characters dropped\n");
wdenka0ebde52004-09-08 22:03:11 +000035 }
36
37 return 0;
38}