1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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...
     

Share This Page