Home > other >  Winsock2.h Connecting to ip address without passing it on command line
Winsock2.h Connecting to ip address without passing it on command line

Time:12-09

While I was checking basic use for winsock2.h library I asked myself how can i make program that connect automatically to IP address passed in source code without typing the address in command line all the time

CodePudding user response:

As @AlbertShown says in his comment, you can manually provide the results of the getaddrinfo() function to whichever function needs them. You just need to have a look at the results it gives you when you do run it, and make sure and sure the appropriate protocol family, protocol and socket type. Here's an example program using these fields.

However - this is not a useful thing to do. You wrote in a comment that you want to "make things faster" - remember the maxim: "Premature optimization is the root of all evil."

Is your program actually being slowed down by running getaddrinfo()? How much of the program's execution time does calling this function take? Use a profiler, or place a timer in your code, and figure this out. I'm sure you'll find it is a lot less than you think. It is almost certainly not worth bothering avoiding this function call.

  • Related