Udp Server Giving Segmentation Fault

UDP Server giving Segmentation Fault

These lines:

error("recvfrom");

error("sendto");

don't do what you think they do. You probably meant to say perror.

Additionally, you aren't initializing rmt_length correctly. Try this:

int rmt_length=sizeof(rmt_addr);

Finally, you are echoing more bytes back than the server receives. Try this:

byte_recv=sendto(sock_id,buffer,byte_recv,0,(struct sockaddr*)&rmt_addr,rmt_length);

sendto creating a segmentation fault when sending a packet

The local variable res is overwritten by the call

int length = recvfrom(socketfd, buf, 1000, 0, (struct sockaddr *)&serverAddr, &addr_size);

this is because the address of the pointer serverAddr is passed instead of the value of the pointer:

int length = recvfrom(socketfd, buf, 1000, 0, (struct sockaddr *)serverAddr, &addr_size);

You'll probably see that the program now segfaults for another reason: The buffer handling fails for short files with less than two fragments, because curr->next is uninitialized.

When requesting time from server I get a Segmentation fault (core dumped). How can I resolve this?

memcpy((void *)current_time, ...);

should be

memcpy(¤t_time, ...);


Related Topics



Leave a reply



Submit