Last active
January 23, 2018 03:16
-
-
Save fortheday/ce96a0e30f9c6b0e2571ad92096de7ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++Builder code | |
struct sockaddr_in addr; | |
SOCKET s; | |
int i; | |
memset(&addr, NULL, sizeof(struct sockaddr)); | |
addr.sin_family = AF_INET; | |
addr.sin_addr.s_addr = INADDR_ANY; | |
addr.sin_port = htons(0); | |
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | |
i = bind(s, (sockaddr *)&addr, sizeof(addr)); | |
if (i == 0) { | |
i = sizeof(struct sockaddr); | |
getsockname(s, (sockaddr *)&addr, &i); | |
ShowMessage(AnsiString(ntohs(addr.sin_port))); | |
} | |
closesocket(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment