How can I get the error number or error string returned by the recv() in socket communication, recv() returns -1 as read size which means some error has occurred. I want to know the specific reason for the error. so how can I get that.
Getting error number returned by recv function
8.8k Views Asked by Asus gates At
2
There are 2 best solutions below
0
Sourav Ghosh
On
You can make use of the errno variable from errno.h header file.
From the man page (emphasis mine)
Return Value
Upon successful completion,
recv()shall return the length of the message in bytes. If no messages are available to be received and the peer has performed an orderly shutdown,recv()shall return 0. Otherwise, -1 shall be returned anderrnoset to indicate the error.
Alternatively, you can also call perror() / strerror() to get a human-readable string related to the error.
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in LINUX
- Is there some way to use printf to print a horizontal list of decrementing hex digits in NASM assembly on Linux
- Why does Hugo generate different taxonomy-related HTML on different OS's?
- Writes in io_uring do not advance the file offset
- Why `set -o pipefail` gives different output even though the pipe is not failing
- what really controls the permissions: UID or eUID?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Docker container unable to make HTTPS requests to external API
- Whow to use callback_query_handler in Python 3.10
- Create kea runtime directory at startup in Yocto image
- Problem on CPU scheduling algorithms in OS
- How to copy files into the singularity sandbox?
- Android kernel error: undefined reference to `get_hw_version_platform'
- Is there a need for BPF Linux namespace?
- Error when trying to execute a binary compiled in a Kali Linux machine on an Ubuntu system
- Issue with launching application after updating ElectronJs to version 28.0.0 on Windows and Linux
Related Questions in RETURN-VALUE
- Bellman equation for MRP?
- how to find sum of input value in javascript
- My Add to cart button not calling out product id
- Storing a returned array in Java
- Does extracting values from a multiple Value return in Haskell invoke the function more than once?
- Return value of forech statement in mybatis
- return from function changes value of array element in c
- Unable to read the return value of a non "view" on-chain function
- Is object copied to the calling function as returned value a lvalue or rvalue?
- If i code a function to create a key-value pair, what will the Object it belongs to be?
- I need to return the value amount from two seperate sheets with the criteria for match of date and text
- How can i solve a problem by using the outcome of a function as a variable in the following?
- cannot load() returned values from string
- Does anyone know why I'm getting a segmentation fault after the returning value of a RPC function?
- Excel return Price based on invoice date
Related Questions in ERRNO
- OSError: [Errno 5] EIO : When using 2 of the same sensors with same address on different I2C channels
- Why does NOT exist std::errno while "errno" does?
- Issue pushing python app to Heroku, "python: can't open file '/app/App.py'
- Is it required to include <errno.h> to use perror?
- What is this example of modifiable lvalue found in error.h ISO C99?
- Multiprocessing and Socket: "OSError: [Errno 98] Address already in use"
- C poll() returns ECHILD
- connect() giving ENOENT - what could be the cause?
- flutter: Could not start Dart VM service HTTP server:
- Reallocating a previously allocated pointer to SIZE_MAX doesn't set ENOMEM, but reallocating NULL works?
- List of possible errno codes for TCP socket connections on Linux for recv/send?
- Is there any problem with my files and folder?
- i am using nodemailer for sending emails and i also used app password as user password .but i am not able to figure out why this error is coming?
- Errno 13 whenever .py file is run with sudo on Linux
- unable to open port with pySerial - serial.Serial
Related Questions in STRERROR
- Why is strerror_s() with ERROR_NOT_ENOUGH_MEMORY error code returning "Exec format error"
- setlocale in C Does Not Effect Error Message Strings Given By strerror
- Using strerror() twice with different values within one printf() triggers a bug on Windows
- TypeError: __str__ returned non-string (type NoneType) in output
- Example of strerror_r
- Element-wise sum of nested lists
- perror and strerror with close(2) involved
- std::string constructor with lvalue throws with clang
- Redefining a predefined errno error message (E2BIG)
- How to export error-handling to a function in C using <errno.h>
- compatibility of strerror_r on different platforms
- GNU strerror_r buffer meaning
- Porting Zed Shaw's debug macros to MSVC
- 'str' object has no attribute
- Expected initializer before 'strerror'
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You need to include errno.h and use the
errnoglobal variable to check the last error code. Also, you can usestrerror()to print a locale aware string explaining the error.Example