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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:56:30+00:00 2026-05-15T05:56:30+00:00

In my program, I have a list of server address in the following format:

  • 0

In my program, I have a list of “server address” in the following format:

host[:port]

The brackets here, indicate that the port is optional.

  • host can be a hostname, an IPv4 or IPv6 address (possibly in “bracket-enclosed” notation).
  • port, if present can be a numeric port number or a service string (like: “http” or “ssh”).

If port is present and host is an IPv6 address, host must be in “bracket-enclosed” notation (Example: [::1])

Here are some valid examples:

localhost
localhost:11211
127.0.0.1:http
[::1]:11211
::1
[::1]

And an invalid example:

::1:80 // Invalid: Is this the IPv6 address ::1:80 and a default port, or the IPv6 address ::1 and the port 80 ?
::1:http // This is not ambigous, but for simplicity sake, let's consider this is forbidden as well.

My goal is to separate such entries in two parts (obviously host and port). I don’t care if either the host or port are invalid as long as they don’t contain a non-bracket-enclosed : (290.234.34.34.5 is ok for host, it will be rejected in the next process); I just want to separate the two parts, or if there is no port part, to know it somehow.

I tried to do something with std::stringstream but everything I come up to seems hacky and not really elegant.

How would you do this in C++ ?

I don’t mind answers in C but C++ is prefered. Any boost solution is welcome as well.

Thank you.

  • 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-15T05:56:30+00:00Added an answer on May 15, 2026 at 5:56 am

    Have you looked at boost::spirit? It might be overkill for your task, though.

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

Sidebar

Related Questions

I have a C# program that displays a list of patients with medications where
I have a Matlab program that generates a list x = 6.1692 8.1863 5.8092
I have a chat program that displays I list of online users. The message
I have a C# program with an interrupt that processes part of a list
I have a small Java program that reads list of IPs from text file
I have a Java program that is supplied a directory name, gets a list
So I have lots of links like address:port/Bla-bla/bla-bla/file/blabla234times/ created by some server (like VLC)
I have a client/server program that attempts to send and receive an object. There
I have a program on my production server, that returned this error: My main
I have a program which places structures in a linked list based on the

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.