Hi,

I was wondering why my daytime server doesn't work when built for
Cygwin, and I have been able to narrow it down to this reproducible
test case:

#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>

int main(void) {
        struct addrinfo *res;
        int s = getaddrinfo(NULL, "daytime", &(const struct addrinfo){.ai_flags 
= AI_PASSIVE, .ai_protocol = IPPROTO_TCP}, &res);
        if(s) {
                fprintf(stderr, "Failed to get address info: %s\n", (s != 
EAI_SYSTEM) ? gai_strerror(s) : strerror(errno));
                exit(EXIT_FAILURE);
        }

        for(const struct addrinfo *tmp = res; tmp; tmp = tmp->ai_next) {
                int fd = socket(tmp->ai_family, tmp->ai_socktype, 
tmp->ai_protocol);
                if(fd == -1) {
                        perror("Failed to create socket");
                } else if(close(fd) == -1) {
                        perror("Failed to close socket");
                }
        }
        freeaddrinfo(res);
}

This code fails with "Failed to create socket: Invalid argument". Does
anyone have an idea why this happens, given that the arguments to
socket() come directly from the call to getaddrinfo()? Remarkably,
changing the service from "daytime" to "http" seems to fix it, which
seems quite strange.

I'm not subscribed, so please CC me on replies.

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to