DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 20th May 2013
unkmail unkmail is offline
New User
 
Join Date: May 2013
Posts: 6
Thanked 0 Times in 0 Posts
Default OpenBSD multicast

How to send multicast datagram via non-default network interface?
I try this:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <err.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define IFACE_ADDR      "192.168.2.1"
#define MCAST_ADDR      "239.1.2.3"
#define MCAST_PORT      1234

int main(void)
{
        struct sockaddr_in      ifaddr, mcaddr;
        int                     sock, on;
        char                    msg[] = "test test test";

        if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
                err(1, "socket");

        on = 1;
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) == -1)
                err(1, "setsockopt(SO_REUSEADDR)");

        ifaddr.sin_addr.s_addr = inet_addr(IFACE_ADDR);
        if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF,
            &ifaddr.sin_addr.s_addr, sizeof(ifaddr.sin_addr.s_addr)) == -1)
                err(1, "setsockopt(IP_MULTICAST_IF)");

        memset(&mcaddr, 0, sizeof mcaddr);
        mcaddr.sin_family = AF_INET;
        mcaddr.sin_addr.s_addr = inet_addr(MCAST_ADDR);
        mcaddr.sin_port = (unsigned short)htons(MCAST_PORT);

        if (sendto(sock, msg, sizeof msg, 0,
            (struct sockaddr *)&mcaddr, sizeof mcaddr) == -1)
                err(1, "sendto");
        close(sock);
        return (0);
}
but allways get "sendto: No route to host".
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing IPTV Multicast stream tomageeni OpenBSD General 2 18th July 2010 09:28 PM


All times are GMT. The time now is 04:24 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick