Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void UdpPortCheck(char * buff, int id, sockaddr_in destination)
- {
- destination.sin_port = htons(id);
- int timeout = 1000;
- SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
- setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
- (char*)&timeout, sizeof(timeout));
- sendto(sock, &buff[0], strlen(&buff[0]), 0,
- (sockaddr*)&destination, sizeof(destination));
- int dest_size = sizeof(destination);
- if (recvfrom(sock,
- &buff[0],
- sizeof(buff) - 1,
- 0,
- (sockaddr*)&destination,
- &dest_size) !=
- SOCKET_ERROR)
- {
- printf("\t\tPort %i is open\n", id);
- }
- else if (WSAGetLastError() == WSAETIMEDOUT)
- {
- printf("\t\tPort %i is open\n", id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement