D
D
DenisVladimirovich2017-04-29 02:49:39
linux
DenisVladimirovich, 2017-04-29 02:49:39

How to get whole string from USHORT and char*?

The bottom line is that you need to get the full IP:PORT address. If I can take the IP, then connect to the port - no.

char *address = inet_ntoa(addr_c.sin_addr);
      std::cout << address << std::endl;
      USHORT port = ntohs(addr_c.sin_port);
      char *act = address + (unsigned char)port;
      std::cout << act << std::endl;

How to do it correctly, getting at least 127.0.0.1: (port here) at the output?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2017-04-29
@jcmvbkbc

char *address = inet_ntoa(addr_c.sin_addr);
      USHORT port = ntohs(addr_c.sin_port);
      std::ostringstream addr_port;

      addr_port << address << ":(" << port << ")";
      std::cout << addr_port.str() << std::endl;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question