Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRT socket addr with inaccurate socket type. #3986

Open
suzp1984 opened this issue Mar 16, 2024 · 1 comment
Open

SRT socket addr with inaccurate socket type. #3986

suzp1984 opened this issue Mar 16, 2024 · 1 comment
Assignees
Labels
EnglishNative This issue is conveyed exclusively in English. SRT It's about SRT protocol.

Comments

@suzp1984
Copy link
Contributor

suzp1984 commented Mar 16, 2024

hints.ai_socktype = SOCK_STREAM;

SRT use UDP socket, so the socket type should be SOCK_STREAM, this api is used to get the addrinfo with TCP type. It's not accurate, at least no perfect.
The usual steps to create a socket (TCP/UDP) is: socket(domain, type, protocol) -> bind(socket, const struct sockaddr*, address_len); I found create a UDP socket and bind with a TCP struct sockaddr is ok. It seem the system api is tolerant with this mistake, I also no idea whether it's a mistake or not. But I guess gives the socket a more accurate addr would be better.

Here is the code to verify bind socket with a struct sockaddr with different type.

#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family   = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags    = AI_NUMERICHOST;

    struct addrinfo* r = NULL;

    if(getaddrinfo("0.0.0.0", "10080", (const struct addrinfo*)&hints, &r)) {
        printf("getaddrinfo hints=(%d,%d,%d) failed\n", hints.ai_family, hints.ai_socktype, hints.ai_flags);
        return -1;
    }

    printf("getaddrinfo r=(%d,%d,%d) success\n", r->ai_family, r->ai_socktype, r->ai_flags);


    int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);

    if (bind(s, r->ai_addr, r->ai_addrlen)) {
        printf("bind socket failed\n");
        return -2;
    }


    getchar();
    
    close(s);
    
    free(r);
    r = NULL;

    return 0;
}

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Mar 16, 2024
@winlinvip
Copy link
Member

I'm unsure about the correct parameter to use with the getaddrinfo function, which is utilized to obtain an address for binding a socket. Please conduct further research and study on this issue. If you confirm that this issue needs correction, please submit a pull request.

I appreciate your effort in researching and providing examples concerning this issue. However, it seems that more work is needed to fully understand the problem. I recommend reading and studying further, and doing more work to clarify this issue, until you can determine whether it is a bug.

@winlinvip winlinvip self-assigned this Mar 18, 2024
@winlinvip winlinvip added the SRT It's about SRT protocol. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EnglishNative This issue is conveyed exclusively in English. SRT It's about SRT protocol.
Projects
None yet
Development

No branches or pull requests

2 participants