I have a client.c
server.c
on linux. on both I init a socket:
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
in the server I 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) to recvform
:
if (recvfrom(sockfd, buf_get, BUFLEN, 0, (struct sockaddr*)&talker_addr, &slen) == -1)
err("recvfrom()");
And the client.c
sends packets with:
if (sendto(sockfd, buf_sent, BUFLEN, 0, (struct sockaddr*)&serv_addr, slen) == -1)
err("sendto()");
- The problem is that on the first calling to
sendto
fromclient.c
, the servers sees the client's ip as0.0.0.0
, after that on the second, third,... calls theclient.c
get an ip and have a legal ip such as127.0.0.3:3212
. - another weird thing is that if I start a second new client it gets ip from the first time.