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 7845475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:14:01+00:00 2026-06-02T17:14:01+00:00

This, I observed, because of the port. port is C++ string. When I hard

  • 0

This, I observed, because of the port. port is C++ string. When I hard code the port number say “4091” I dont see this issue. Any suggestions?

int sockfd;
struct addrinfo hints, *servinfo, *p;
int rv;

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; 
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; 

cout << "port: " << port << endl;

const char * por = port.c_str();

if ((rv = getaddrinfo(NULL, por, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
}
  • 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-06-02T17:14:02+00:00Added an answer on June 2, 2026 at 5:14 pm

    This might look absolute dumb but this is how I fixed it.

        int pp = atoi(port.c_str());
        char buffer[50];
        sprintf( buffer, "%d", pp );   
    
        if ((rv = getaddrinfo(NULL, buffer, &hints, &servinfo)) != 0) {
            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        }
    

    EDIT: The actual issue was that I was reading the port information from a file. when I use the getline() it did not remove the newline char at the end for what ever reason. The above fix (if you call it a fix) no longer needed.

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

Sidebar

Related Questions

I've first observed this issue in a production code, then made a prototype: import
I've searched for this, but my results were unsatisfactory, probably because of how hard
I got the code below from a website,and this way of serial port reading
This is a common question, but the explanations found so far and observed behaviour
Observed: First, 'ctrl+v'+selection always worked before for me. But this time, i got normal
Is there any reason to do use block initialization, like this: x = Observer.new
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I've been stuck on this one for a while and any advice would be
I observed the following behavior while working with the perl code base (on branch
Let's say because of a conditional comment or just being careless the same included

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.