c - Why the first client sees to have source ip of 0.0.0.0? -


i have client.c server.c on linux. on both init socket:

sockfd = socket(af_inet, sock_dgram, ipproto_udp) 

in server add:

listen_addr.sin_family = af_inet; listen_addr.sin_port = htons(port); listen_adrr.sin_addr.s_addr = htonl(inaddr_any); 

the server.c calls (blocking way) recvform:

if (recvfrom(sockfd, buf_get, buflen, 0, (struct sockaddr*)&talker_addr, &slen) == -1)             err("recvfrom()"); 

and client.c sends packets with:

if (sendto(sockfd, buf_sent, buflen, 0, (struct sockaddr*)&serv_addr, slen) == -1)         err("sendto()"); 
  1. the problem on first calling sendto client.c, servers sees client's ip 0.0.0.0, after on second, third,... calls client.c ip , have legal ip such 127.0.0.3:3212.
  2. another weird thing if start second new client gets ip first time.

make sure setting slen size of talker_addr struct before call recvfrom. set value (which may explain why works in subsequent calls) in recvfrom if there bad initial value, may garbage first call.

slen = sizeof(struct sockaddr_in); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -