UDP restart using socket leading to null packets

I am implementing a UDP video redirect function. Ideally, incoming video packets should be processed and redirected to the specified output interface (eth0 or eth1). Here's how it is implemented:

  • The user selects an interface from webui. The interface is passed to the backend.

  • Video packets are processed using the OpenCaster package ( here ) .. the following libraries are used to process packets: tsfixcc, tsdiscont, tsvbr2cbr, tstimedwrite, tspcrrestamp and tsudpsend.

  • I modified tsudpsend as follows to support binding the socket to a specific interface, and there is no compilation error, and I think it works fine.

int main (int argc, char *argv[]) {
    char *opt;
    opt = argv[5];
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if(sockfd < 0) {
        perror("socket(): error ");
        return 0;
    }

    struct ifreq ifr;
    memset(&ifr, 0, sizeof(ifr));
    strcpy(ifr.ifr_name, opt);
    if (ioctl(sockfd, SIOCGIFINDEX, &ifr)<0){
        fprintf(stderr,"ioctl(): error ");
    }

    if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, opt, strlen(opt))>0){
        fprintf(stderr,"setsock(): error ");
    }

    fprintf(stderr, "The bind is done on interface %s \n", opt);
    fprintf(stderr, "opt length is %zu \n", strlen(opt));
    if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
        fprintf(stderr,"Server-setsockopt() error for SO_BINDTODEVICE");
        close(sockfd);
        return 1;
    }

    return 0;
}

: (eth0 eth1), NULL-, , .

1054354 1127.215289 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054355 1127.216366 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054356 1127.217405 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054357 1127.218462 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054358 1127.219549 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet

, ? , ?

+2

All Articles