2

我编写了一个在 Ubuntu LTE 上运行的程序,它应该使用原始套接字将多播消息发送到 239.255.25.25 端口 5004。为了接收多播,我使用的是 UDP 套接字。通过套接字发送的数据是使用 rtp 流中的wireshark 捕获的。现在的问题是,我无法接收带有 UDP 套接字的消息。为了检查接收器是否正确,我构建了一个使用普通 UDP 套接字的发送器。当我现在通过 RAW 和 UDP 套接字发送相同的消息时,我只能接收从 udp 套接字发送的消息。

我是用wireshark来分析包的,raw socket的多播包和udp socket的多播包好像是一样的,但是为什么收不到raw socket发送的包呢?

来自 UDP 和 RAW Socket Sender 的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<features.h>
#include<net/if.h>
#include<linux/if_packet.h>
#include<linux/if_ether.h>
#include<errno.h>
#include<sys/ioctl.h>
#include<net/ethernet.h>
#include<net/if_arp.h>
#include<arpa/inet.h>
#include<netinet/in.h>

#define DEVICE "eth0"


int rawsock;
struct sockaddr_ll sll;
struct ifreq ifr;


unsigned char dataArray[]={0x01, 0x00, 0x5e, 0x7f, 0x19, 0x19, 0x00, 0x0a, 0x5e, 0x56, 0xed, 0x87, 0x08, 0x00, 0x45, 0x00, 0x05, 0x4c, 0x00, 0x00, 0x40, 0x00, 0x01, 0x11, 0xa9, 0xdc, 0xc0, 0xa8, 0x01, 0x04, 0xef, 0xff, 0x19, 0x19, 0x80, 0xda, 0x13, 0x8c, 0x05, 0x38, 0xd0, 0x0e, 0x80, 0xa1, 0xb0, 0x14, 0x9a, 0x7d, 0x01, 0x56, 0xb2, 0x50, 0x00, 0x98, 0x47, 0x40, 0x45, 0x1f, 0x00, 0x00, 0x01, 0xe0, 0x06, 0x2b, 0x80, 0xc0, 0x0a, 0x35, 0x69, 0xf3, 0x0e, 0xbd, 0x15, 0x69, 0xf3, 0x2c, 0x13, 0x00, 0x00, 0x00, 0x01, 0x06, 0x05, 0x11, 0x03, 0x87, 0xf4, 0x4e, 0xcd, 0x0a, 0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, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbc, 0x0e, 0x64, 0xb2, 0x4c, 0x11, 0xe8, 0x39, 0x16, 0x93, 0x5a, 0x74, 0x0d, 0x1c, 0xf6, 0x2b, 0x55, 0x50, 0x14, 0xe5, 0x81, 0xac, 0xe4, 0xf3, 0x02, 0xa4, 0x50, 0x05, 0x9a, 0x4e, 0x37, 0x79, 0x4c, 0x01, 0x13, 0xc5, 0x8c, 0x6f, 0x9b, 0x43, 0x03, 0xe1, 0x82, 0xb2, 0x27, 0x2a, 0xf0, 0x47, 0x40, 0x44, 0x19, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x90, 0x80, 0x80, 0x05, 0x25, 0x69, 0xf3, 0x34, 0xe3, 0xff, 0xf1, 0x4c, 0x80, 0x31, 0x1f, 0xfc, 0x21, 0x0a, 0xd4, 0x13, 0x7c, 0x88, 0x21, 0x08, 0x15, 0xfa, 0xdd, 0xdd, 0x45, 0x25, 0x4a, 0x95, 0x56, 0x02, 0x51, 0x02, 0xb3, 0x39, 0x00, 0x11, 0x06, 0x02, 0xc7, 0xda, 0x4d, 0xad, 0x5f, 0x84, 0xe7, 0x22, 0x5a, 0xb7, 0xca, 0x27, 0x7a, 0xb5, 0x09, 0xd8, 0x83, 0x73, 0x07, 0x6b, 0xb0, 0x34, 0x11, 0x02, 0x18, 0x9d, 0xf5, 0xda, 0x44, 0x73, 0x9b, 0x55, 0xc0, 0x8a, 0x00, 0x77, 0x2b, 0x84, 0xb7, 0x25, 0xc2, 0xa9, 0x43, 0x68, 0x85, 0x67, 0xa4, 0x69, 0xc6, 0x1e, 0x45, 0x75, 0x46, 0xbe, 0x4b, 0x32, 0x2b, 0xef, 0xba, 0x14, 0xd5, 0xc8, 0xb7, 0x97, 0x5a, 0xa4, 0x95, 0x4e, 0xf7, 0x25, 0xf0, 0x96, 0x05, 0xc1, 0x48, 0x32, 0x85, 0x2f, 0x0c, 0x30, 0x57, 0xb3, 0xac, 0x39, 0x19, 0x01, 0x95, 0x52, 0x0d, 0x07, 0x10, 0xf0, 0x46, 0xa8, 0xb4, 0xe8, 0x2b, 0xab, 0xad, 0x73, 0x2d, 0xf9, 0x4c, 0xc8, 0x31, 0x4a, 0xde, 0x7b, 0x01, 0x11, 0x21, 0x7c, 0x29, 0x4f, 0x01, 0x17, 0x17, 0xca, 0x9f, 0x04, 0x6b, 0x37, 0x59, 0x8e, 0x31, 0xbe, 0xba, 0x0d, 0xe9, 0x8b, 0x8d, 0xa5, 0x6a, 0xad, 0x50, 0x60, 0x96, 0x47, 0x00, 0x45, 0x12, 0x1f, 0x4a, 0xd3, 0x59, 0xeb, 0xfb, 0x4d, 0x67, 0xb1, 0xfa, 0x4d, 0x35, 0x9e, 0xbe, 0x82, 0x49, 0xa6, 0x9c, 0xf6, 0x3e, 0x95, 0xa6, 0xb3, 0xd8, 0xfa, 0x56, 0x9a, 0xcf, 0x5f, 0x4a, 0xd3, 0x59, 0xeb, 0xf4, 0x9a, 0x6b, 0x3d, 0x8f, 0xd2, 0x69, 0xac, 0xf6, 0x3f, 0x49, 0xa6, 0xb3, 0xd7, 0xf6, 0x9a, 0x53, 0xd7, 0xd2, 0x41, 0x34, 0xd6, 0x7b, 0x1f, 0x4a, 0xd3, 0x59, 0xeb, 0xfb, 0x4d, 0x67, 0xb1, 0xfa, 0x4d, 0x35, 0x9e, 0xbe, 0x82, 0x49, 0xa6, 0xb3, 0xd8, 0xfd, 0x26, 0x9a, 0xcf, 0x5f, 0xda, 0x6b, 0x3d, 0x8f, 0xa5, 0x69, 0xac, 0xf6, 0x3e, 0x95, 0xa6, 0xb3, 0xd7, 0xd2, 0xb4, 0xd6, 0x7a, 0xfd, 0x26, 0x9a, 0xcf, 0x63, 0xf4, 0x9a, 0x6b, 0x54, 0x74, 0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea};

unsigned char dataComp[1370];



//UDP Socket Variablen


struct in_addr localInterface;
struct sockaddr_in groupSock;
int udpSock;
char groupAddress[]="239.255.25.25";
int groupPort = 5004;






unsigned char payloadOnly[]={0x80, 0xa1, 0xb0, 0x14, 0x9a, 0x7d, 0x01, 0x56, 0xb2, 0x50, 0x00, 0x98, 0x47, 0x40, 0x45, 0x1f, 0x00, 0x00, 0x01, 0xe0, 0x06, 0x2b, 0x80, 0xc0, 0x0a, 0x35, 0x69, 0xf3, 0x0e, 0xbd, 0x15, 0x69, 0xf3, 0x2c, 0x13, 0x00, 0x00, 0x00, 0x01, 0x06, 0x05, 0x11, 0x03, 0x87, 0xf4, 0x4e, 0xcd, 0x0a, 0x4b, 0xdc, 0xa1, 0x94, 0x3a, 0xc3, 0xd4, 0x9b, 0x17, 0x1f, 0x00, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0xa8, 0xc3, 0x60, 0x3a, 0x81, 0xb5, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xfa, 0xbf, 0x57, 0xea, 0xfd, 0x5f, 0xab, 0xf5, 0x7e, 0xaf, 0xd5, 0xe0, 0xda, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0x96, 0xa9, 0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0xaf, 0xa4, 0x82, 0x69, 0xac, 0xf6, 0x3e, 0x95, 0xa6, 0xb3, 0xd7, 0xd2, 0xb4, 0xd6, 0x7a, 0xfd, 0x26, 0x9a, 0xcf, 0x63, 0xf4, 0x9a, 0x6b};
unsigned char payloadOnly2[]={0x3d, 0x8f, 0xd2, 0x69, 0xac, 0xf5, 0xfd, 0xa6, 0xb3, 0xd8, 0xfa, 0x56, 0x9a, 0xd5, 0x8e, 0x7b, 0x47, 0x00, 0x44, 0x38, 0x88, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbc, 0x0e, 0x64, 0xb2, 0x4c, 0x11, 0xe8, 0x39, 0x16, 0x93, 0x5a, 0x74, 0x0d, 0x1c, 0xf6, 0x2b, 0x55, 0x50, 0x14, 0xe5, 0x81, 0xac, 0xe4, 0xf3, 0x02, 0xa4, 0x50, 0x05, 0x9a, 0x4e, 0x37, 0x79, 0x4c, 0x01, 0x13, 0xc5, 0x8c, 0x6f, 0x9b, 0x43, 0x03, 0xe1, 0x82, 0xb2, 0x27, 0x2a, 0xf0, 0x47, 0x40, 0x44, 0x19, 0x00, 0x00, 0x01, 0xc0, 0x01, 0x90, 0x80, 0x80, 0x05, 0x25, 0x69, 0xf3, 0x34, 0xe3, 0xff, 0xf1, 0x4c, 0x80, 0x31, 0x1f, 0xfc, 0x21, 0x0a, 0xd4, 0x13, 0x7c, 0x88, 0x21, 0x08, 0x15, 0xfa, 0xdd, 0xdd, 0x45, 0x25, 0x4a, 0x95, 0x56, 0x02, 0x51, 0x02, 0xb3, 0x39, 0x00, 0x11, 0x06, 0x02, 0xc7, 0xda, 0x4d, 0xad, 0x5f, 0x84, 0xe7, 0x22, 0x5a, 0xb7, 0xca, 0x27, 0x7a, 0xb5, 0x09, 0xd8, 0x83, 0x73, 0x07, 0x6b, 0xb0, 0x34, 0x11, 0x02, 0x18, 0x9d, 0xf5, 0xda, 0x44, 0x73, 0x9b, 0x55, 0xc0, 0x8a, 0x00, 0x77, 0x2b, 0x84, 0xb7, 0x25, 0xc2, 0xa9, 0x43, 0x68, 0x85, 0x67, 0xa4, 0x69, 0xc6, 0x1e, 0x45, 0x75, 0x46, 0xbe, 0x4b, 0x32, 0x2b, 0xef, 0xba, 0x14, 0xd5, 0xc8, 0xb7, 0x97, 0x5a, 0xa4, 0x95, 0x4e, 0xf7, 0x25, 0xf0, 0x96, 0x05, 0xc1, 0x48, 0x32, 0x85, 0x2f, 0x0c, 0x30, 0x57, 0xb3, 0xac, 0x39, 0x19, 0x01, 0x95, 0x52, 0x0d, 0x07, 0x10, 0xf0, 0x46, 0xa8, 0xb4, 0xe8, 0x2b, 0xab, 0xad, 0x73, 0x2d, 0xf9, 0x4c, 0xc8, 0x31, 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0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea, 0x8e, 0x9d, 0x51, 0xd3, 0xaa, 0x3a, 0x75, 0x47, 0x4e, 0xa8, 0xe9, 0xd5, 0x1d, 0x3a, 0xa3, 0xa7, 0x54, 0x74, 0xea};

unsigned char payloadComp[1328];



int main()
{

    do{

    memmove(dataComp, dataArray,sizeof(dataArray));
    memmove(&dataComp[sizeof(dataArray)],dataArray2,(sizeof(dataArray2)));

    printf("Press Enter for Sending Multicast via RAW Socket...\n");
    getchar();

    //RAW Socket


    if ((rawsock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)))== -1)
    {
        perror("Error creating raw socket: ");
        exit(-1);
    }

    bzero(&sll, sizeof(sll));
    bzero(&ifr, sizeof(ifr));


    strncpy((char *)ifr.ifr_name, DEVICE, IFNAMSIZ);
    if ((ioctl(rawsock, SIOCGIFINDEX, &ifr)) == -1)
    {
        printf("Error getting Interface index !\n");
        exit(-1);
    }


    sll.sll_family = AF_PACKET;
    sll.sll_ifindex = ifr.ifr_ifindex;


    if(sendto(rawsock, dataComp, 1370, 0, (struct sockaddr *)&sll, sizeof(sll)) < 0)
    {
        perror("Sending datagram message error");
    }


 //UDP Socket
    printf("For Sending Multicast via UDP Socket press Enter \n");
    getchar();

    memmove(payloadComp, payloadOnly, sizeof(payloadOnly));
    memmove(&payloadComp[sizeof(payloadOnly)],payloadOnly2,(sizeof(payloadOnly)));

    udpSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if(udpSock < 0)
    {
      perror("Opening datagram socket error");
      return 0;
    }
    else

    memset((char *) &groupSock, 0, sizeof(groupSock));
    groupSock.sin_family = AF_INET;
    groupSock.sin_addr.s_addr = inet_addr(groupAddress); //Multicast Adress
    groupSock.sin_port = htons(groupPort);                 //Port for Multicast
    localInterface.s_addr = inet_addr("192.168.1.4");
    if(setsockopt(udpSock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localInterface, sizeof(localInterface)) < 0)
    {
      perror("Setting local interface error");
      return 0;
    }
    else


    if(sendto(udpSock, payloadComp, 1328, 0, (struct sockaddr*)&groupSock, sizeof(groupSock)) < 0)
    {
        perror("Sending datagram message error");
    }



    }while(1);


    return 0;
}

来自 UDP 接收器的代码:

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>


#define SOCKET_ERROR        -1
#define BUFFER_SIZE         100
#define PACKETLENGTH        1328


struct sockaddr_in localSock;
struct ip_mreq group;
int sd;
int datalen;
char databuf[PACKETLENGTH];
int i=0;
char addressGroup[]="239.255.25.25";
int groupPort = 5004;





int main(int argc, char *argv[])

{


//Begin Code Multicast UDP
//*************************************************

/* Create a datagram socket on which to receive. */

sd = socket(AF_INET, SOCK_DGRAM, 0);

if(sd < 0)

{

perror("Opening datagram socket error");

exit(1);

}

else

printf("Opening datagram socket for UDP....OK.\n");



/* Enable SO_REUSEADDR to allow multiple instances of this */

/* application to receive copies of the multicast datagrams. */

{

int reuse = 1;

if(setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0)

{

perror("Setting SO_REUSEADDR error");

close(sd);

exit(1);

}

else

printf("Setting SO_REUSEADDR...OK.\n");

}

memset((char *) &localSock, 0, sizeof(localSock));

localSock.sin_family = AF_INET;

localSock.sin_port = htons(groupPort);

localSock.sin_addr.s_addr = INADDR_ANY;

if(bind(sd, (struct sockaddr*)&localSock, sizeof(localSock)))

{

perror("Binding datagram socket error");

close(sd);

exit(1);

}

else

printf("Binding UDP datagram socket...OK.\n");



group.imr_multiaddr.s_addr = inet_addr(addressGroup);

group.imr_interface.s_addr = INADDR_ANY;


if(setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0)

{

perror("Adding multicast group error");

close(sd);

exit(1);

}

else

printf("Adding multicast group...OK.\n");
printf("Now Receiving Packages from %s Multicast Group\n",&addressGroup);

do{

datalen = sizeof(databuf);

if(read(sd, databuf, datalen) < 0)

{

perror("Reading datagram message error");

close(sd);

exit(1);

}

else

{

printf("Reading UDP datagram message...OK.\n");

printf("The UDP message from multicast server is: \"%s\"\n", databuf);

memset(databuf,0,datalen);

i++;
}
}while(i<=9999);


close(sd);
return 0;

}

也许这是 HAL 中的一个错误,因为当我使用wireshark 接收两个包时,似乎它们是相同的,但是 udp 套接字发现它们之间存在差异。但如果这是我的编程错误,我会很高兴。:-) 谢谢您的帮助!

4

1 回答 1

3

tcpdump -vvv告诉我[bad udp cksum af7f!]

于 2011-02-01T19:58:19.257 回答