Code Monkey home page Code Monkey logo

Comments (1)

chtrading avatar chtrading commented on July 17, 2024

I minimally changed the example
multicast-echo.c
in order to confirm that this is a bug.

The modified version is here:

#include <time.h>
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <iostream>

int main(int argc, char *argv[])
{
    int j = 0;
    struct sockaddr_in mcast_addr;//, send_addr;
    struct ip_mreq im;
    int recv_fd; // , send_fd;
    char *p, *q;

    /* Parse command line arguments */

    if (argc != 2)
        goto usage_error;

    mcast_addr.sin_family = AF_INET;
//    send_addr.sin_family = AF_INET;

    if ((p = strtok(argv[1], ":")) == NULL ||
        inet_aton(p, &mcast_addr.sin_addr) == 0)
        goto usage_error;
    if ((p = strtok(NULL, ":")) == NULL ||
        inet_aton(p, &im.imr_interface) == 0)
        goto usage_error;
    if ((p = strtok(NULL, "")) == NULL)
        goto usage_error;
    mcast_addr.sin_port = htons(strtol(p, &q, 10));
    if (*p == '\0' || *q != '\0')
        goto usage_error;

    im.imr_multiaddr = mcast_addr.sin_addr;

/*    if ((p = strtok(argv[2], ":")) == NULL ||
        inet_aton(p, &send_addr.sin_addr) == 0)
        goto usage_error;
    if ((p = strtok(NULL, "")) == NULL)
        goto usage_error;
    send_addr.sin_port = htons(strtol(p, &q, 10));
    if (*p == '\0' || *q != '\0')
        goto usage_error;
*/

    /* Create and bind sockets */

    recv_fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (recv_fd == -1)
    {
        fprintf(stderr, "socket: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }

   /*
    send_fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (send_fd == -1)
    {
        fprintf(stderr, "socket: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }
    */

    if (setsockopt(recv_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&im, sizeof(im)) == -1)
    {
        fprintf(stderr, "setsockopt: IP_ADD_MEMBERSHIP failed: %s\n",
                strerror(errno));
        return EXIT_FAILURE;
    }

    if (bind(recv_fd, (struct sockaddr *)&mcast_addr, sizeof(mcast_addr)) == -1)
    {
        fprintf(stderr, "bind: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }

/*    if (connect(send_fd, (struct sockaddr *)&send_addr, sizeof(send_addr)) == -1)
    {
        fprintf(stderr, "connect: %s\n", strerror(errno));
        return EXIT_FAILURE;
    }
*/

    /* Echo packets */

    while (1)
    {
        char buf[65536];
        ssize_t len;

        len = recv(recv_fd, buf, sizeof(buf), 0);
	std::cout << "len: " << len << std::endl;
        if (len == -1)
        {
            fprintf(stderr, "recv: %s\n", strerror(errno));
            return EXIT_FAILURE;
        }

	
	j++;
	if(j == 100)
	{
	    std::cout << "***" << std::endl;
	    if (setsockopt(recv_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&im, sizeof(im)) == -1)
	    {
		    return -1;
	    }

	}
	/*
        if (send(send_fd, buf, len, 0) == -1)
        {
            fprintf(stderr, "send: %s\n", strerror(errno));
            return EXIT_FAILURE;
        }
	*/
    }

    close(recv_fd);
  //  close(send_fd);

    return 0;

usage_error:
    fprintf(stderr,
            "Usage: %s <multicast-group>:<interface-addr>:<port> <send-addr>:<port>\n"
            "\n"
            "Receive multicast UDP packets on <interface-addr> addressed to\n"
            "multicast group <multicast-group> at port <port>, and echo a copy of\n"
            "each packets to <send-addr>:<port>.\n",
            argv[0]);

    return 0;
}

The result is the same:

[ch@localhost exasock]$ exasock --debug ./a.out 233.252.14.1:192.168.2.2:10001
a.out: structs.h:487: exa_hashtable_mcast_remove: Assertion `memb_to_insert != ((void *)0)' failed.

I am trying to understand what is happening (debugging).

from exanic-software.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.