vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / multicast.c
blob0d2d14be40f104a169415c5e0fb18a14da1adf93
1 /* -*- c-basic-offset: 8; -*-
3 * Copyright (c) 1993 W. Richard Stevens. All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies. The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
9 */
11 #include "sock.h"
13 void
14 join_mcast(int fd, struct sockaddr_in *sin)
16 #ifdef IP_ADD_MEMBERSHIP /* only include if host supports mcasting */
17 u_long inaddr;
18 struct ip_mreq mreq;
20 inaddr = sin->sin_addr.s_addr;
21 if (IN_MULTICAST(inaddr) == 0)
22 return; /* not a multicast address */
24 mreq.imr_multiaddr.s_addr = inaddr;
25 mreq.imr_interface.s_addr = htonl(INADDR_ANY); /* need way to change */
26 if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
27 sizeof(mreq)) == -1 )
28 err_sys("IP_ADD_MEMBERSHIP error");
30 if (verbose)
31 fprintf(stderr, "multicast group joined\n");
32 #endif /* IP_ADD_MEMBERSHIP */