![]() |
| | #1 |
| Registered User Join Date: Jun 2008
Posts: 11
| is getaddrinfo really necessary? Code: ...
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
// Resolve the server address and port
iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
if ( iResult != 0 ) {
printf("getaddrinfo failed: %d\n", iResult);
WSACleanup();
return 1;
}
// Create a SOCKET for connecting to server
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ListenSocket == INVALID_SOCKET) {
printf("socket failed: %ld\n", WSAGetLastError());
freeaddrinfo(result);
WSACleanup();
return 1;
}
// Setup the TCP listening socket
iResult = bind( ListenSocket, result->ai_addr, (int)result->ai_addrlen);
if (iResult == SOCKET_ERROR) {
printf("bind failed: %d\n", WSAGetLastError());
freeaddrinfo(result);
closesocket(ListenSocket);
WSACleanup();
return 1;
}
freeaddrinfo(result);
...
|
| sunjayc99 is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| No, because "result" is filled out by getaddrinfo and required by subsequent functions.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Registered User Join Date: Jun 2008
Posts: 11
| sorry, i guess i didn't phrase my question correctly. what i meant was, couldn't i just use something like: Code: ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCPIP); Code: bind(ListenSocket, myaddr, sizeof(myaddr)); |
| sunjayc99 is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,785
| getaddrinfo looks up the hostname into the internal format used by Winsock (according to MSDN). If you've already initialized that hostname, then sure, but otherwise no.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why create a wrapper fo getaddrinfo() | Overworked_PhD | Linux Programming | 2 | 11-10-2007 01:37 AM |
| getaddrinfo() | Cactus_Hugger | Windows Programming | 1 | 07-24-2006 02:41 AM |
| using gethostbyname , getaddrinfo & WSAAsyncGetHostByName | hanhao | Networking/Device Communication | 2 | 04-04-2004 01:07 AM |
| Resolving Hostname Using getaddrinfo(...) :: Winsock | kuphryn | Windows Programming | 1 | 05-03-2002 08:35 PM |