Peter Tyser | a79c6bb | 2009-04-24 15:59:46 -0500 | [diff] [blame] | 1 | #include <stdio.h> |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <sys/socket.h> |
Wolfgang Denk | b8664ab | 2009-04-04 16:14:51 +0200 | [diff] [blame] | 5 | #include <netinet/in.h> |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 6 | |
| 7 | int main (int argc, char *argv[]) |
| 8 | { |
| 9 | int s, len, o, port = 6666; |
| 10 | char buf[512]; |
| 11 | struct sockaddr_in addr; |
Mike Frysinger | b35beab | 2009-01-09 04:38:17 -0500 | [diff] [blame] | 12 | socklen_t addr_len = sizeof addr; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 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; |
Peter Tyser | a79c6bb | 2009-04-24 15:59:46 -0500 | [diff] [blame] | 33 | if (write (1, buf, len) != len) |
| 34 | fprintf(stderr, "WARNING: serial characters dropped\n"); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |