Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 305204 Details for
Bug 369591
multicast change in behavior
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
multicast receiver that can bind to specific interface
mcreceive.c (text/x-csrc), 4.03 KB, created by
Aleksandar Kostadinov
on 2008-05-13 06:51:34 UTC
(
hide
)
Description:
multicast receiver that can bind to specific interface
Filename:
MIME Type:
Creator:
Aleksandar Kostadinov
Created:
2008-05-13 06:51:34 UTC
Size:
4.03 KB
patch
obsolete
>#include <sys/types.h> /* for type definitions */ >#include <sys/socket.h> /* for socket API calls */ >#include <netinet/in.h> /* for address structs */ >#include <arpa/inet.h> /* for sockaddr_in */ >#include <stdio.h> /* for printf() and fprintf() */ >#include <stdlib.h> /* for atoi() */ >#include <string.h> /* for strlen() */ >#include <unistd.h> /* for close() */ > >#define MAX_LEN 1024 /* maximum receive string size */ >#define MIN_PORT 1024 /* minimum port allowed */ >#define MAX_PORT 65535 /* maximum port allowed */ > >int main(int argc, char *argv[]) { > > int sock; /* socket descriptor */ > int flag_on = 1; /* socket option flag */ > struct sockaddr_in mc_addr; /* socket address structure */ > char recv_str[MAX_LEN+1]; /* buffer to receive string */ > int recv_len; /* length of string received */ > struct ip_mreq mc_req; /* multicast request structure */ > char* mc_addr_str; /* multicast IP address */ > struct in_addr if_addr; /* IP Address Structure */ > char* if_addr_str; /* bind interface address */ > unsigned short mc_port; /* multicast port */ > struct sockaddr_in from_addr; /* packet source */ > unsigned int from_len; /* source addr length */ > > /* validate number of arguments */ > if (argc != 4) { > fprintf(stderr, > "Usage: %s <Multicast IP> <Multicast Port> <Bind Interface Addr>\n", > argv[0]); > exit(1); > } > > mc_addr_str = argv[1]; /* arg 1: multicast ip address */ > mc_port = atoi(argv[2]); /* arg 2: multicast port number */ > if_addr_str = argv[3]; /* arg 3: bind interface ip address */ > > /* validate the port range */ > if ((mc_port < MIN_PORT) || (mc_port > MAX_PORT)) { > fprintf(stderr, "Invalid port number argument %d.\n", > mc_port); > fprintf(stderr, "Valid range is between %d and %d.\n", > MIN_PORT, MAX_PORT); > exit(1); > } > > /* create socket to join multicast group on */ > if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { > perror("socket() failed"); > exit(1); > } > > /* set reuse port to on to allow multiple binds per host */ > if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag_on, > sizeof(flag_on))) < 0) { > perror("setsockopt() failed"); > exit(1); > } > > /* network interface */ > inet_aton(if_addr_str,&if_addr); > > /* construct an IGMP join request structure */ > mc_req.imr_multiaddr.s_addr = inet_addr(mc_addr_str); > mc_req.imr_interface.s_addr = if_addr.s_addr; /* JOIN on the specified interface - not htonl(INADDR_ANY); */ > > /* construct a multicast address structure */ > memset(&mc_addr, 0, sizeof(mc_addr)); > mc_addr.sin_family = AF_INET; > mc_addr.sin_addr.s_addr = mc_req.imr_multiaddr.s_addr; /* Bind to the specific mcast address - not allowed on windows */ /* htonl(INADDR_ANY); */ > mc_addr.sin_port = htons(mc_port); > > /* bind to multicast address to socket */ > if ((bind(sock, (struct sockaddr *) &mc_addr, > sizeof(mc_addr))) < 0) { > perror("bind() failed"); > exit(1); > } > > /* send an ADD MEMBERSHIP message via setsockopt */ > if ((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, > (void*) &mc_req, sizeof(mc_req))) < 0) { > perror("setsockopt() failed"); > exit(1); > } > > for (;;) { /* loop forever */ > > /* clear the receive buffers & structs */ > memset(recv_str, 0, sizeof(recv_str)); > from_len = sizeof(from_addr); > memset(&from_addr, 0, from_len); > > /* block waiting to receive a packet */ > if ((recv_len = recvfrom(sock, recv_str, MAX_LEN, 0, > (struct sockaddr*)&from_addr, &from_len)) < 0) { > perror("recvfrom() failed"); > exit(1); > } > > /* output received string */ > printf("Received %d bytes from %s: ", recv_len, > inet_ntoa(from_addr.sin_addr)); > printf("%s", recv_str); > } > > /* send a DROP MEMBERSHIP message via setsockopt */ > if ((setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, > (void*) &mc_req, sizeof(mc_req))) < 0) { > perror("setsockopt() failed"); > exit(1); > } > > close(sock); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 369591
:
250061
| 305204 |
305466