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

Problem with DGRAM multicasting


During software development on a Axis 100LX I met some strange things
with ethernet multicasting. When sending packets to a network through MC
it was only possible to do a very limited number (116) of sendto's
before there was an WOULDBLOCK error from sendto. The situation becomes
unblocked again when there is some other network transaction on the Axis
(telnet). I include in this mail the concentrated code giving problems.
I hope the problem is reproductible with this information. 

When sending normal UniCast packets, everything seems fine because there
is some kind of ack from the receiver and the situation is each time
unblocked (I suppose).

See here the code

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <string.h>

//#define MCAST

struct sockaddr_in local_address;
struct sockaddr_in remot_address;

#define ERROR_OUT  printf


int main(void){
  int sd, opt, status, cnt = 0, ttl = 1;
  int port = 5454;

#ifdef MCAST
  char *remote_ip = "";
  char *remote_ip = "";

  // Get a INET socket into sd
  if((sd = socket(PF_INET, SOCK_DGRAM, 0)) < 0){
    ERROR_OUT("Error during socket creation: %s\n",strerror(errno));

  if((opt = fcntl(sd,F_GETFL,0)) == -1){
    ERROR_OUT("Could not get socket flags : %s\n",strerror(errno));

  if(fcntl(sd,F_SETFL, opt | O_NONBLOCK) == -1){
    ERROR_OUT("Could not set socket flags : %s\n",strerror(errno));

  // Initialise local port and address (own address) to listen on
  bzero(&local_address, sizeof(local_address));
  local_address.sin_family = AF_INET;
  local_address.sin_port = htons(port);
  local_address.sin_addr.s_addr = INADDR_ANY;

#ifdef MCAST
  if ( setsockopt(sd, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) != 0 ){
    ERROR_OUT("Set ttl failed : %s\n",strerror(errno));

  // Prepare remote-address for sendto
  bzero(&remot_address, sizeof(remot_address));
  remot_address.sin_family = AF_INET;
  remot_address.sin_port = htons(port);
  if ( inet_aton(remote_ip, &remot_address.sin_addr) == 0 )
    ERROR_OUT("Could not convert address (%s)", remote_ip);

#ifdef MCAST
    ERROR_OUT("Wrong address !\n");

    status = sendto(sd, txt, strlen(txt) + 1, 0, 
		    (struct sockaddr*)&remot_address, sizeof(struct sockaddr));
    if ( status < 0 ){
      ERROR_OUT("%d:Error during sendto socket : %s\n",cnt,strerror(errno));
      cnt = 0;

It would be nice to have a solution or work-around for this problem.

Johan Neven <johan.neven@xxxxxxx.be>