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()"); - the problem on first calling
sendtoclient.c, servers sees client's ip0.0.0.0, after on second, third,... callsclient.cip , have legal ip such127.0.0.3:3212. - 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
Post a Comment