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

  • Home
  • SEARCH
  • 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 130273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:55:19+00:00 2026-05-11T05:55:19+00:00

I am trying to implement a function called inet_pton which will convert a string

  • 0

I am trying to implement a function called ‘inet_pton’ which will convert a string representation of an IPv4 or IPv6 (like ‘66.102.1.147’ [google]) into binary network-byte ordered form. Here is the relevant part of my code:

#if defined WIN32 int inet_pton (int af, const char *src, void *dst)  {     const void *data;     size_t      len;     struct      addrinfo hints, *res;      hints.ai_family   = af;     hints.ai_socktype = SOCK_STREAM;      hints.ai_protocol = IPPROTO_UDP;     hints.ai_flags    = AI_NUMERICHOST;      if (getaddrinfo (src, NULL, &hints, &res))     {         std::cout << 'ERROR : inet_pton() in ' << __FILE__ << ' at line ' << __LINE__ << std::endl;         std::cout << '      : getaddrinfo() failed to get IP address info for \'' << src << '\'' << std::endl;         return 0;     } ... 

So src is the incoming IP string. However, I always get an error like

getaddrinfo() failed to get IP address info for ‘66.102.1.147’

Can anyone with winsock experience comment? I also tried another method, the function

WSAStringToAddress ((LPTSTR)src, af, NULL, (LPSOCKADDR) &sa, &address_length) 

But it always returns the error code WSAEINVAL, indicating an invalid IP string. This makes no sense to me. I’m using VS2005 as my IDE.

  • 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. 2026-05-11T05:55:20+00:00Added an answer on May 11, 2026 at 5:55 am

    Well, for a start you’re asking for a stream socket with UDP as a protocol and that just isn’t going to happen.

    Try with:

    hints.ai_family   = af; hints.ai_socktype = 0;  hints.ai_protocol = 0; hints.ai_flags    = AI_NUMERICHOST; 

    and memset it to zero first as it has extra members that you’re not setting…

    Also in my code I pass an empty string for the port or service when I don’t have one rather than a null. The docs don’t seem to specify what to do when you don’t have a value; but either way an empty string works for me.

    Oh, and as always in these situations, it would be useful to know what value WSAGetLastError() returns…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer At the moment, probably the most well known graphics engine… May 12, 2026 at 8:02 am
  • Editorial Team
    Editorial Team added an answer You can use a custom ItemUpdated event handler on the… May 12, 2026 at 8:02 am
  • Editorial Team
    Editorial Team added an answer The reason this works: protected void Page_Load(object sender, EventArgs e)… May 12, 2026 at 8:02 am

Related Questions

I have a pointer to a given class. Lets say, for example, the pointer
On Linux under X11 and using GTK+ you have something called Main Loop. Once
In many embedded applications there is a tradeoff between making the code very efficient
I am using VB.NET and I am trying to come up with some algorithm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.