3 #include <sys/socket.h>
6 int main (int argc, char *argv[])
8 int s, len, o, port = 6666;
10 struct sockaddr_in addr;
11 socklen_t addr_len = sizeof addr;
14 port = atoi (argv[1]);
16 s = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
20 setsockopt (3, SOL_SOCKET, SO_REUSEADDR, &o, len);
22 addr.sin_family = AF_INET;
23 addr.sin_port = htons (port);
24 addr.sin_addr.s_addr = INADDR_ANY; /* receive broadcasts */
26 bind (s, (struct sockaddr *) &addr, sizeof addr);
29 len = recvfrom (s, buf, sizeof buf, 0, (struct sockaddr *) &addr, &addr_len);