Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:06:30+00:00 2026-05-26T12:06:30+00:00

I tried to create a UDP socket on mingw, but socket() returns -1 ,

  • 0

I tried to create a UDP socket on mingw, but socket() returns -1, with errno = 0. Strange.
I have included winsock2.h.
Initially I had compilation error undefined reference to socket@12, after setting
-lws2_32 and -lwsock32 to Linker Settings of Code::Block, compilation success.

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
RDF_LOG(kDEBUG, "sockfd %d ", sockfd);
if (sockfd < 0){
    RDF_LOG(kERROR, "ERROR: %s , errno %d\n", strerror(errno), errno);
}

Result –>
sockfd -1
ERROR: No error , errno 0


OK, I change RDF_LOG to fprintf instead.

int tmp = 0;

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
tmp = errno;
fprintf(stderr, "sockfd %d ", sockfd);
if (sockfd < 0){
    fprintf(stderr, "socket: %s , errno %d\n", strerror(tmp), tmp);
}

The result returned is, still, –> sockfd -1 socket: No error , errno 0
Is it possible that mingw does not support errno??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:06:30+00:00Added an answer on May 26, 2026 at 12:06 pm

    The first thing I would do is this:

    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    int tmp = errno;
    RDF_LOG(kDEBUG, "sockfd %d ", sockfd);
    if (sockfd < 0){
        RDF_LOG(kERROR, "ERROR: %s , errno %d\n", strerror(tmp), tmp);
    }
    

    I have no idea what RDF_LOG may be doing to the errno variable and this will tell you whether it changes it or not.

    Another thing to look for is that you have successfully performed your WSAStartup. The following minimal program should hopefully show you how to do this, and provide a starting point for debugging:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <winsock2.h>
    
    int main (void) {
        WSADATA wsaData;
        int listenFd;
    
        if (WSAStartup(MAKEWORD(1,1), &wsaData) == SOCKET_ERROR) {
            printf ("Error initialising WSA.\n");
            return -1;
        }
    
        listenFd = socket (AF_INET, SOCK_STREAM, 0);
        if (listenFd  < 0) {
            printf ("Error %d opening socket.\n", errno);
            return -1;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to find how to create DLL-s on linux using google, but
I tried to create a solver from XML configuration. But the entire process returns
Have anybody ever tried to create thumbnails/previews of MS Office files? I do not
I have development environment with 64-bit SharePoint 2007. I tried to create SharePoint workflow
I want to create a Winsock UDP socket that only sends data to a
I have already created a UDP socket (UDP has been bound) and now i
I tried to create a custom .NET attribute with the code below but accidentally
I tried to create this by following the video at http://www.asp.net/learn/videos/video-7026.aspx where Joe Stagner
I tried to create a Style for DataGridTextColumn with the following code <Style TargetType={x:Type
when I tried to create a shared library file using the cl command in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.