Code :
SOCKADDR_IN addr_local; SOCKADDR_IN addr_dest; SOCKET sock; /* We now accept packet on given UDP port, send query */ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock == -1) return; memset(&addr_local, 0, sizeof addr_local); addr_local.sin_port = htons(port); addr_local.sin_family = AF_INET; if (bind(sock, (PSOCKADDR) &addr_local, sizeof addr_local) == 0) { TEXT packet[512]; int len, slen = sizeof addr_dest; while ((len = recvfrom(sock, packet, sizeof packet, 0, (SOCKADDR *) &addr_dest, &slen))) { /* Tu viens de recevoir un packet de <len> octet dans <packet> */ } closesocket(sock); }
|