[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multicast sendto bug???



can NOT attach files???
here is the code:
 
obsd34:/temp>cat xxx.c
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <syslog.h>
#include <stdarg.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <net/bpf.h>
#include <net/route.h>
#include <net/if_dl.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <net/if_media.h>
#include <kvm.h>
#include <limits.h>
#include <nlist.h>
#include <net/if_types.h>
#include <setjmp.h>
#define MC_IF   "10.0.0.226"
#define MC_IP   "224.0.0.55"
#define MC_PORT 5555
int McGet(int sock)
{
        struct in_addr          ipaddr;
        u_char                  ttl;
        u_char                  loop;
        int                     size;
        size = sizeof(ttl);
        if (getsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, &size) < 0 )
        {
                perror("IP_MULTICAST_TTL");
                return -1;
        }
        printf("IP_MULTICAST_TTL = %d\n", ttl);
        size = sizeof(loop);
        if (getsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, &size) < 0 )
        {
                perror("IP_MULTICAST_LOOP");
                return -1;
        }
        printf("IP_MULTICAST_LOOP = %d\n", loop);
        size = sizeof(ipaddr);
        if (getsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &ipaddr, &size) < 0) 
        {
                perror("IP_MULTICAST_IF");
                return -1;
        }
        printf("IP_MULTICAST_IF =%s\n", inet_ntoa(ipaddr));
        return 0;
}

int McSet(int sock, int m)
{
        struct ip_mreq          req;
        u_char                  ttl = 1;
        u_char                  loop = 0;
        struct in_addr          ipaddr;
        ipaddr.s_addr = inet_addr(MC_IF);
        if ( m ) {
                memset(&req, 0, sizeof(req));
                req.imr_multiaddr.s_addr = inet_addr(MC_IP);
                req.imr_interface.s_addr = ipaddr.s_addr;
                if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                                 (char *) &req, sizeof(struct ip_mreq)) < 0) 
                {
                        perror("IP_ADD_MEMBERSHIP");
                        return -1;
                }
        }
        if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0 )
        {
                perror("IP_MULTICAST_TTL");
                return -1;
        }
        if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) < 0 )
        {
                perror("IP_MULTICAST_LOOP");
                return -1;
        }
        if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &ipaddr, sizeof(ipaddr)) < 0) 
        {
                perror("IP_MULTICAST_IF");
                return -1;
        }
        return 0;
}
int Test(void)
{
        int                     r;
        int                     sock;
        struct sockaddr_in      sa;
        char                    buf[128];
        if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
                perror("udp socket");
                exit(1);
        }
        bzero((char*)&sa, sizeof(sa));
        sa.sin_family = AF_INET;
        sa.sin_addr.s_addr = inet_addr(MC_IP);
        sa.sin_port = htons(MC_PORT);
        McSet(sock, 0);
        McGet(sock);
        r = sendto(sock, buf, 64, 0, (struct sockaddr *)&sa, sizeof(sa));
        if ( r < 0 ) {
                perror("sendto");
        }
        close(sock);
        return 0;
}
int main(void)
{
        Test();
        exit(0);
}       


burawa <buract@yahoo.com> wrote:
Hello!
 
Attched file is a very simple program to send a multicast packet, it can NOT work in OpenBSD, but works fine in FreeBSD.
I had src/sys updated to the main branch last night, and recompiled the kernel, but
it doesnot work.
 
obsd34:/temp>gcc xxx.c
obsd34:/temp>./a.out
IP_MULTICAST_TTL = 1
IP_MULTICAST_LOOP = 0
IP_MULTICAST_IF =10.0.0.226
sendto: Host is down
obsd34:/temp>route add 224.0.0.55 10.0.0.226
add host 224.0.0.55: gateway 10.0.0.226
obsd34:/temp>./a.out
IP_MULTICAST_TTL = 1
IP_MULTICAST_LOOP = 0
IP_MULTICAST_IF =10.0.0.226
obsd34:/temp>route delete 224.0.0.55 
delete host 224.0.0.55
obsd34:/temp>./a.out
IP_MULTICAST_TTL = 1
IP_MULTICAST_LOOP = 0
IP_MULTICAST_IF =10.0.0.226
sendto: Host is down
 
 
It seems that the route dest 224.0.0.55 must be add, why?
I do NOT have to add this route in FreeBSD, 
and no document says I have to add it.
 
 
Any suggestion?
Thanks
 


Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.

> ATTACHMENT part 2 application/octet-stream name=xxx.c
Yahoo! Finance Tax Center - File online. File on time.