Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "stdafx.h"
- #include <locale.h>
- #include <WinSock2.h>
- #include <conio.h>
- #pragma comment(lib, "Ws2_32.lib")
- void CheckErrorByCode(int code)
- {
- char Buff[1024];
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, NULL, Buff, sizeof(Buff), NULL);
- printf(" %s", Buff);
- }
- int main(int argc, char** argv) {
- setlocale(LC_ALL, "Polish");
- WSADATA wsa;
- SOCKADDR_IN addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(19390);
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- char BuffToSend[2048];
- char BuffToShow[2048];
- char Host[512];
- int result = WSAStartup(MAKEWORD(2, 0), &wsa);
- if (result != 1)
- {
- printf("WSAStartup initialization: ");
- CheckErrorByCode(result);
- }
- else
- {
- printf("WSAStartup initialization error! Error code: %d", result);
- CheckErrorByCode(result);
- }
- result = gethostname(Host, sizeof(Host));
- if (result == 1)
- {
- printf("Get hostname function error! Error code: %d", result);
- CheckErrorByCode(result);
- }
- SOCKET Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- bind(Socket, (SOCKADDR*)&addr, sizeof(addr));
- for (int i = 0; i < 2048; i++)
- {
- BuffToSend[i] = NULL;
- BuffToShow[i] = NULL;
- }
- printf("%s: ", Host);
- scanf("%s", &BuffToSend);
- sendto(Socket, BuffToSend, strlen(BuffToSend), 0, (SOCKADDR*)&addr, sizeof(addr));
- int AddrSize = sizeof(addr);
- recvfrom(Socket, BuffToShow, sizeof(BuffToShow), 0, (SOCKADDR*)&addr, &AddrSize);
- printf("\nAnon: %s", BuffToShow);
- closesocket(Socket);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement