Send broadcast messages C linux

Discussion in 'DD-WRT Firmware' started by FuMi22, Apr 2, 2008.

  1. FuMi22

    FuMi22 LI Guru Member

    Hi

    How i can send broadcast UDP messages? I try to do this with sockets..

    ------------------

    if ((peerfd1 = socket(PF_INET, SOCK_DGRAM, 0 )) == -1)
    return -1;
    if((setsockopt(peerfd1,SOL_SOCKET,SO_BROADCAST,&broadcast,sizeof broadcast)) == -1)
    return -1;
    setsockopt(peerfd1,SOL_SOCKET,SO_RCVBUF, (char *) &sockopt,sizeof(sockopt));
    bs1.sin_family = PF_INET;
    bs1.sin_port = htons(6430);
    bs1.sin_addr.s_addr = INADDR_ANY;
    ip = inet_ntoa(bs1.sin_addr);
    if( bind(peerfd1, (struct sockaddr*)&bs1, sizeof(bs1)) != 1) {
    des1.sin_family = PF_INET;
    des1.sin_addr.s_addr = INADDR_BROADCAST; <------
    des1.sin_port = htons(6430);
    sendto(peerfd1,(char *) packet,N,0,(struct sockaddr*)&des1,sizeof(des1));
    close(peerfd1);
    }

    -------------

    This not work.. If I set:
    des1.sin_addr.s_addr = "192.168.1.100" --> IP of my PC

    I recive the packet but not when i try to send broadcast...
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice