- if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
- uint16_t portStart = 0, portEnd = 0;
- printf("Enter port range: Start:");
- scanf("%hu", &portStart);
- scanf("%hu", &portEnd);
+ uint16_t portStart = 0, portEnd = 0;
+ printf("Enter port range: Start:");
+ scanf("%hu", &portStart);
+ scanf("%hu", &portEnd);
- SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
+ SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
- setsockopt(s, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
+ setsockopt(s, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
- struct sockaddr_in bindaddr = { AF_INET };
+ struct sockaddr_in bindaddr = { AF_INET };
- if (bind(s, &bindaddr, 16) != NO_ERROR)
+ if (bind(s, &bindaddr, 16) != NO_ERROR)
- struct sockaddr_in sendaddr = { AF_INET };
- sendaddr.sin_addr.s_addr = INADDR_BROADCAST;
- for (uint16_t i = portStart; i <= portEnd; ++i)
- sendaddr.sin_port = htons(i);
- char buffer[] = { 0x56, 0x43, 0x4D, 0x50, 0xFF, 0xFF, 0xFF, 0xFF, i & 0xFF, i >> 8 & 0xFF, 'i' };
- sendto(s, buffer, sizeof(buffer), 0, &sendaddr, sizeof(sendaddr));
+ struct sockaddr_in sendaddr = { AF_INET };
+ sendaddr.sin_addr.s_addr = INADDR_BROADCAST;
+ for (uint16_t i = portStart; i <= portEnd; ++i)
+ sendaddr.sin_port = htons(i);
+ char buffer[] = { 0x56, 0x43, 0x4D, 0x50, 0xFF, 0xFF, 0xFF, 0xFF, i & 0xFF, i >> 8 & 0xFF, 'i' };
+ sendto(s, buffer, sizeof(buffer), 0, &sendaddr, sizeof(sendaddr));
- struct sockaddr_in recvaddr = { 0 };
- int size = sizeof(recvaddr);
- char *recvBuff = calloc(532, sizeof(char));
- int recvlen = recvfrom(s, recvBuff, 532, 0, &recvaddr, &size);
- if (*(int *)buf == 0x3430504D) // MP04
- char *ip = inet_ntoa(recvaddr.sin_addr);
- uint16_t port = ntohs(recvaddr.sin_port);
+ struct sockaddr_in recvaddr = { 0 };
+ int size = sizeof(recvaddr);
+ char *recvBuff = calloc(532, sizeof(char));
+ int recvlen = recvfrom(s, recvBuff, 532, 0, &recvaddr, &size);
+ if (*(int *)buf == 0x3430504D) // MP04
+ char *ip = inet_ntoa(recvaddr.sin_addr);
+ uint16_t port = ntohs(recvaddr.sin_port);
- memmove(version, buf, sizeof(version));
+ memmove(version, buf, sizeof(version));
- int strlen = *(int *)buf;
- char *servername = alloca(strlen + 1);
- strncpy(servername, buf, strlen);
- servername[strlen] = 0;
+ int strlen = *(int *)buf;
+ char *servername = alloca(strlen + 1);
+ strncpy(servername, buf, strlen);
+ servername[strlen] = 0;
- char *gamemode = alloca(strlen + 1);
- strncpy(gamemode, buf, strlen);
+ char *gamemode = alloca(strlen + 1);
+ strncpy(gamemode, buf, strlen);
- char *mapname = alloca(strlen + 1);
- strncpy(mapname, buf, strlen);
+ char *mapname = alloca(strlen + 1);
+ strncpy(mapname, buf, strlen);
- printf("%s:%hu|%s|%s|%s|%s\n", ip, port, version, servername, gamemode, mapname);
+ printf("%s:%hu|%s|%s|%s|%s\n", ip, port, version, servername, gamemode, mapname);