You are correct. My test is wrong.

However, the result is the same - it wants a non-zero proto there.

$ sudo ./gaitest
src ai_family 2 ai_socketype 3 ai_protocol 0
socket creation failed, errno = 93
src ai_family 2 ai_socketype 3 ai_protocol 115

No error on the second one, -93 on the first one.

A.
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>


int main(int argc, char **argv)
{
    int fd, gairet;
    struct addrinfo hints;
    struct addrinfo * result = NULL;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_RAW;
    hints.ai_protocol = 0;

    gairet = getaddrinfo("localhost", NULL, &hints, &result);
    if ((gairet !=0) || (result == NULL)) {
        fprintf(stderr, "could not resolve src, errno = %s\n", gai_strerror(gairet));
        return 1;
    }

    printf("src ai_family %d ai_socketype %d ai_protocol %d\n",
           result->ai_family, result->ai_socktype, result->ai_protocol);


    if (
	(fd = socket(result->ai_family, result->ai_socktype, result->ai_protocol)) == -1) {
	fd = -errno;
	printf("socket creation failed, errno = %d\n", -fd);
    }

    freeaddrinfo(result);

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_RAW;
    hints.ai_protocol = 0x73;

    gairet = getaddrinfo("localhost", NULL, &hints, &result);
    if ((gairet !=0) || (result == NULL)) {
        fprintf(stderr, "could not resolve src, errno = %s\n", gai_strerror(gairet));
        return 1;
    }

    printf("src ai_family %d ai_socketype %d ai_protocol %d\n",
           result->ai_family, result->ai_socktype, result->ai_protocol);


    if (
	(fd = socket(result->ai_family, result->ai_socktype, result->ai_protocol)) == -1) {
	fd = -errno;
	printf("l2tpv3_open : socket creation failed, errno = %d", -fd);
    }

    freeaddrinfo(result);

    return 0;
}

Reply via email to