12-01-2011
send() and recv() send raw bytes without any consideration for their content whatsoever. If you give it a length of 100, it will use precisely 100 bytes of that buffer given sufficient data.
Remember though: A raw byte stream might not stop at a polite boundary, isn't guaranteed to give you an entire message, and won't politely null-terminate everything for you the way things like fgets() and sprintf() do. send() and recv() are raw system calls without the niceties. You get exactly what was sent, no more, no less.
This User Gave Thanks to Corona688 For This Post:
10 More Discussions You Might Find Interesting
1. Programming
I am opening a server socket on one of our machines and connection to it on the other machine. After making the connection if ether one of the systems does a recv() and ther is no data to receive then the buffer is filled with spaces and returns. I have no way of knowing if it is valid or not. ... (1 Reply)
Discussion started by: hazard0007
1 Replies
2. Forum Support Area for Unregistered Users & Account Problems
I have forgotten my password and twice have entered my email address in your 'Forgotten Password' screen, but have received no email about how to proceed. Do you know what's wrong - please advise. Thanks. Jan (jvander) (0 Replies)
Discussion started by: jvandernopasswd
0 Replies
3. Programming
In attachment, is the code to test IP by ARP proxy. I always use it to test a IP already existing in my cluster.
Usage:
arp_func eth0 192.168.1.1
Enviroment:
IA64, RedHat AS3.0, 2.4.21-15.EL, gcc-3.2.3-34,
"gcc -o arp_func arp_func.c"
When the code below added before... (0 Replies)
Discussion started by: lameryang
0 Replies
4. IP Networking
hi !
In my program I have a structure as shown below:
struct data
{
int a;
char *b;
long c;
}str;
i have assigned the following values to it:
strcpy(str.b,"John");
str.a=10;
str.c=123435;
The client is tryin to send struct data to the server using
send(sock,(char *... (2 Replies)
Discussion started by: mridula
2 Replies
5. Programming
Hi,
Am very new to socket programming.
When we use UDP sockets to communicate between two processess,
will both the client/server socket be able to send/recv ?
meaning can sendto()/ recvfrom() be used on both server and client?
It could be useful even if anybody provide some link on socket... (1 Reply)
Discussion started by: rvan
1 Replies
6. Programming
So I'm making a program that gets the IP Address of an inputed website, then sends the IP Address to an inputed host. This program has no real meaning, but just a learning experiment. So I sucessfully made the program, then I wanted to try out recv(), and it produces some weird output; here is the... (2 Replies)
Discussion started by: Octal
2 Replies
7. Programming
I have a question regarding the recv syscall.
Suppose I have a client/server and the following exchange of message took place:
Client --> Server using multiple send syscalls one after another immediately:
send "Packet1"
send "Packet2"
send "Packet3"
Server receives in the... (2 Replies)
Discussion started by: heljy
2 Replies
8. Programming
Hi all,
I am facing a problem in recv() system call i.e.. in my project i have to implement timer for sending (data) and resending purpose when there is no acknowledgement.
is there any way that recv() sys call has its own timer i.e., for ex: recv() has to wait for 10 secs.
if any... (0 Replies)
Discussion started by: Rohil
0 Replies
9. Programming
Hi all,
I am facing a problem in recv() system call i.e.. in my project i have to implement timer for sending (data) and resending purpose when there is no acknowledgement.
is there any way that recv() sys call has its own timer i.e., for ex: recv() has to wait for 10 secs.
if any one knows... (2 Replies)
Discussion started by: Rohil
2 Replies
10. Programming
I'm working with recv and I am having a heck of a lot of trouble ignoring excess data that I did not ask for. I was hoping someone could shine some light on the subject for me because I'm not getting anywhere fast.
---------- Post updated at 02:46 AM ---------- Previous update was at 12:31 AM... (2 Replies)
Discussion started by: Errigour
2 Replies
LEARN ABOUT OPENDARWIN
sockatmark
SOCKATMARK(3) Linux Programmer's Manual SOCKATMARK(3)
NAME
sockatmark - determine whether socket is at out-of-band mark
SYNOPSIS
#include <sys/socket.h>
int sockatmark(int sockfd);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
sockatmark(): _POSIX_C_SOURCE >= 200112L
DESCRIPTION
sockatmark() returns a value indicating whether or not the socket referred to by the file descriptor sockfd is at the out-of-band mark. If
the socket is at the mark, then 1 is returned; if the socket is not at the mark, 0 is returned. This function does not remove the out-of-
band mark.
RETURN VALUE
A successful call to sockatmark() returns 1 if the socket is at the out-of-band mark, or 0 if it is not. On error, -1 is returned and
errno is set to indicate the error.
ERRORS
EBADF sockfd is not a valid file descriptor.
EINVAL sockfd is not a file descriptor to which sockatmark() can be applied.
VERSIONS
sockatmark() was added to glibc in version 2.2.4.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+-------------+---------------+---------+
|Interface | Attribute | Value |
+-------------+---------------+---------+
|sockatmark() | Thread safety | MT-Safe |
+-------------+---------------+---------+
CONFORMING TO
POSIX.1-2001, POSIX.1-2008.
NOTES
If sockatmark() returns 1, then the out-of-band data can be read using the MSG_OOB flag of recv(2).
Out-of-band data is supported only on some stream socket protocols.
sockatmark() can safely be called from a handler for the SIGURG signal.
sockatmark() is implemented using the SIOCATMARK ioctl(2) operation.
BUGS
Prior to glibc 2.4, sockatmark() did not work.
EXAMPLE
The following code can be used after receipt of a SIGURG signal to read (and discard) all data up to the mark, and then read the byte of
data at the mark:
char buf[BUF_LEN];
char oobdata;
int atmark, s;
for (;;) {
atmark = sockatmark(sockfd);
if (atmark == -1) {
perror("sockatmark");
break;
}
if (atmark)
break;
s = read(sockfd, buf, BUF_LEN);
if (s == -1)
perror("read");
if (s <= 0)
break;
}
if (atmark == 1) {
if (recv(sockfd, &oobdata, 1, MSG_OOB) == -1) {
perror("recv");
...
}
}
SEE ALSO
fcntl(2), recv(2), send(2), tcp(7)
COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2017-09-15 SOCKATMARK(3)