I have FPGA device which is waiting for UDP packet "FFFF" on port 1000, then answers also with UDP "FFFF". This code works fine, I see incoming "FFFF" packets on my JTAG, but only when Wireshark is launched. If Wireshark is off all I see on JTAG is arp packets, to which I respond, and then - nothing. My C project is on Codeblocks, i had writed "-lwsock32" on other linker options of linker settings.
What am I doing wrong, I want my code work without Wireshark...I guess Wirshark launches some server and everything starts working
MAC of my device is 34:34:45:79:34:54, IP is 192.168.150.111 (can be found in code) IP of my PC is in same network - 192.168.150.5
#include <stdio.h>
#include <stdbool.h>
#include <windows.h>
#include <conio.h>
int main(int argc, char* argv[])
{
SOCKET sckt;
struct sockaddr_in sckt_addr;
DWORD timeout;
WSADATA WSAData;
int rc = WSAStartup (0x202, &WSAData);
if(rc != 0)
{
printf("Ошибка инициализация версии Windows Sockets");
return -1;
}
sckt = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sckt == INVALID_SOCKET)
{
printf("Ошибка инициализация версии Windows Sockets");
return -1;
}
sckt_addr.sin_family = AF_INET;
sckt_addr.sin_addr.s_addr = INADDR_ANY;
sckt_addr.sin_port = htons(1000);
if(bind (sckt , (LPSOCKADDR) &sckt_addr, sizeof(sckt_addr)) == SOCKET_ERROR)
{
printf("Error while initializing Windows Sockets");
closesocket (sckt);
return -1;
}
sckt_addr.sin_addr.s_addr = inet_addr("192.168.150.111");
char o_data[2];
o_data[0] = o_data[1] = 0xFF;
const int i_data_len = 7;
char i_data [7];
int sckt_addr_size = 32;
while(true)
{
rc = sendto (sckt, o_data, 2, 0, (SOCKADDR *)&sckt_addr, sizeof(sckt_addr));
if (rc != 2)
{
printf ("Socket error");
return 1;
}
rc = recvfrom (sckt, i_data, i_data_len, 0, (SOCKADDR *) &sckt_addr, &sckt_addr_size);
if (WSAGetLastError() == WSAETIMEDOUT)
{
printf ("No response from FPGA");
continue;
}
else
{
if (((unsigned char)i_data[0] << 8) + (unsigned char)i_data[1] == 0xFFFF)
printf("\n\nDevice answered FFFF\n");
else
{
printf("\n\nReceived wrong response. ");
return 2;
}
}
}
closesocket (sckt);
WSACleanup ();
return 0;
}
The moment I run wireshark I see that my FPGA answers with ARP-packet and UDP packets going fine:

sizeof(sockaddr_in)is 16 not 32, so you are lying torecvfrom()about the size of yoursckt_addr. Not that it really matters, but you should do the right thing and useint sckt_addr_size = sizeof(sckt_addr);. More importantly, your error handling ofrecvfrom()is wrong and should be checkingrcfor failure before then checkingWSAGetLastError().