ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Максим <arteev@protei.ru>
To: community@altlinux.ru
Subject: Re: [Comm] Програмиирование: multicast в TCP/IP
Date: Tue, 13 Apr 2004 15:16:30 +0400
Message-ID: <407BCC0E.8040205@protei.ru> (raw)
In-Reply-To: <20040413150039.5c692721.Egor.Orlov@avalon.ru>

Egor S. Orlov пишет:

>On Tue, 13 Apr 2004 12:26:43 +0400
>Максим <arteev@protei.ru> wrote:
>
>  
>
>>Не работает multicast в ALTLinux 2.2 Master. Помогите !!! Как это исправить?
>>
>>    
>>
>
>что именно не работает?
>маршрут в таблицу маршрутизации добавили?
>
>
>  
>
Есть код программы :

#include <iostream>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <unistd.h>


#define STDTRACE(i) std::cout << __FILE__ << ":"<< __LINE__ << 
std::endl; Error(i);

int Socket;
socklen_t nlen;
struct sockaddr_in Address,sto,From;
struct in_addr addr;
char Buf[512];
const short port = 100;
void Error(int i);

int main(int argc, char **argv)
{

 bzero((char *)&sto,sizeof(sto));
 addr.s_addr=inet_addr("225.0.0.1");
 sto.sin_family=AF_INET;
 sto.sin_port=htons(port);
 sto.sin_addr=addr;
 nlen=sizeof(sockaddr_in);

 int ttl=7,one=1;
 struct ip_mreq mreq;

 if((Socket=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP))==-1)
   {
    STDTRACE(0);
    }

 Address.sin_family=AF_INET;
 Address.sin_port=htons(port);
 Address.sin_addr.s_addr=INADDR_ANY;

 if(bind(Socket,(struct sockaddr *)&Address,sizeof(Address))==-1)
   {
    STDTRACE(1);
   }

 if(setsockopt(Socket,IPPROTO_IP,IP_MULTICAST_TTL,&ttl,sizeof(ttl))==-1)
   {
    STDTRACE(2);
   }

 if(setsockopt(Socket,IPPROTO_IP,IP_MULTICAST_TTL,&ttl,sizeof(ttl))==-1)
   {
    STDTRACE(2);
   }

 bzero((char *)&mreq,sizeof(mreq));
 mreq.imr_multiaddr.s_addr=inet_addr("225.0.0.1");
 mreq.imr_interface.s_addr=INADDR_ANY;

 if(setsockopt(Socket,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq))==-1)
   {
    STDTRACE(2); //Вот здесь выскакивает ошибка !!!!
   }

 setsockopt(Socket,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
 while(1)
    sleep(1);
}

void Error(int i)
{
 char *errors[7]={"Error of socket",
                    "Error of bind:port already busy",
                    "Error of setsockopt",
                    "Error of sending",
                    "Error of gethostname",
                    "Error of gethostbyname",
                    "Error of ioctl"};

    std::cout << errors[i] << "  " <<strerror(errno) << std::endl;
 _exit(-1);
}
[у@t multicast]# ./a.out
multi.cpp:60
Error of setsockopt  No such device
[у@t multicast]#

Не знаю что делать !!! :-( 
но ifconfig говорит
eth0   Link encap:Ethernet  HWaddr 00:30:4F:13:11:96
          inet addr:192.168.100.1  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING *MULTICAST *MTU:1500  Metric:1
          RX packets:621375 errors:0 dropped:0 overruns:0 frame:0
          TX packets:99469 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:85635384 (81.6 Mb)  TX bytes:24663737 (23.5 Mb)
          Interrupt:11 Base address:0x7000
А именно при добавлении группы 225.0.0.1, как показано в коде, 
выскакивает ошибка.



  reply	other threads:[~2004-04-13 11:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-13  8:26 Максим
2004-04-13 11:00 ` Egor S. Orlov
2004-04-13 11:16   ` Максим [this message]
2004-04-13 11:29     ` Egor S. Orlov
2004-04-13 11:36       ` Максим

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=407BCC0E.8040205@protei.ru \
    --to=arteev@protei.ru \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git