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
Number of Subdirectories in a Directory
Bash Script to Compile and Run C++ Program
How to Test Your Own Linux Module
How to Sort The String Array in Linux Bash Shell
Display Hosts Alive with Fping
Shell Bash Script to Print Numbers in Ascending Order
Make Diff to Ignore Symbolic Link
Use Stdin from Within R Studio
Replace Key:Value from One File in Another File in Shellscript
Extract Unique Block of Lines from a File Using Shell Script
How to Find Out The User of Parent Shell Inside a Child Shell
Calling Windows Subsystem for Linux Apps Through Powershell/Cmd
Npm Install -G Grunt-Cli Failed in Linux