source: network-demos/mcast/mcast_route.c @ 0fe6b0d

4.11network-demos-4-10-branch
Last change on this file since 0fe6b0d was 046d88c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/19/07 at 21:52:02

2007-09-19 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile, README, init.c, listener.c, mcast.c, mcast_params.h, mcast_route.c, rootfs/etc/host.conf, rootfs/etc/hosts: New files.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  Based upon
3 *    http://www.rtems.com/ml/rtems-users/2005/may/msg00022.html
4 */
5
6/*
7
8http://ntrg.cs.tcd.ie/undergrad/4ba2/multicast/antony/index.html
9
10Every IP multicast group has a group address. IP multicast provides only
11open groups: That is, it is not necessary to be a member of a group in
12order to send datagrams to the group.
13
14Multicast address are like IP addresses used for single hosts, and is
15written in the same way: A.B.C.D. Multicast addresses will never clash
16with host addresses because a portion of the IP address space is
17specifically reserved for multicast. This reserved range consists of
18addresses from 224.0.0.0 to 239.255.255.255. However, the multicast
19addresses from 224.0.0.0 to 224.0.0.255 are reserved for multicast
20routing information; Application programs should use multicast
21addresses outside this range.
22
23*/
24
25/*
26 * Trying to have same effect of this command:
27 *
28 * /sbin/route add -net 239.9.8.0  netmask 255.255.255.0 gw 10.4.10.19 dev eth0
29 */
30
31
32#include <rtems/rtems_bsdnet.h>
33#include <netinet/in.h>
34#include <sys/socket.h>
35#include <net/route.h>
36#include <arpa/inet.h>
37
38#include <stdio.h>
39#include <sys/errno.h>
40
41
42int add_mcast_route(
43  char *multi_address,
44  char *multi_netmask,
45  char *multi_gateway
46)
47{
48  int s;
49  struct sockaddr_in address;
50  struct sockaddr_in netmask;
51  struct sockaddr_in gateway;
52
53  memset(&address,0,sizeof(address));
54  address.sin_len = sizeof(address);
55  address.sin_family = AF_INET;
56  address.sin_addr.s_addr = inet_addr( multi_address );
57
58  memset(&netmask,0,sizeof(netmask));
59  netmask.sin_len = sizeof(netmask);
60  netmask.sin_family = AF_INET;
61  netmask.sin_addr.s_addr = inet_addr( multi_netmask );
62
63  memset(&gateway,0,sizeof(gateway));
64  gateway.sin_len = sizeof(gateway);
65  gateway.sin_family = AF_INET;
66  gateway.sin_addr.s_addr = inet_addr( multi_gateway );
67
68  s = rtems_bsdnet_rtrequest(
69    RTM_DELETE,
70    (struct sockaddr *)&address,
71    (struct sockaddr *)&gateway,
72    (struct sockaddr *)&netmask,
73    (RTF_GATEWAY | RTF_MULTICAST | RTF_STATIC),
74    NULL
75  );
76  if ( s == -1 ) {
77    fprintf( stderr, "RTM_DELETE failed errno=%d (%s)\n",
78        errno, strerror(errno) );
79  }
80
81  s = rtems_bsdnet_rtrequest(
82    RTM_ADD,
83    (struct sockaddr *)&address,
84    (struct sockaddr *)&gateway,
85    (struct sockaddr *)&netmask,
86    (RTF_UP | RTF_GATEWAY | RTF_MULTICAST | RTF_STATIC),
87    NULL
88  );
89  if ( s == -1 ) {
90    fprintf( stderr, "RTM_ADD failed errno=%d (%s)\n",
91        errno, strerror(errno) );
92    return -1;
93  }
94  fprintf( stderr, "Route added\n" );
95  return 0;
96}
Note: See TracBrowser for help on using the repository browser.