Hello everybody
I try to use the sendmsg() function to send several packets through a
AF_PACKET SOCK_RAW socket using one system call.
Once the packets are loaded into memory, I try to send the first ones,
but unfortunately sendmsg() fails, returns -1 and perror() gives me the
message: Message to long
The struct msghdr is filled with a struct sockaddr_ll address, no flag,
and the array of struct iovec.
I use Linux 2.6.11.4-21.7-default (SuSE Linux 9.3 Professional).
The program I develop is limited by the overhead due to repeated calls
to sendto() when sending packets to the network. If I could use
sendmsg(), there would be much less overhead and the performances I'd
get would be much better.
Using writev() doesn't help much, as it doesn't send every packet alone
with its own FCS (it concatenates them all and sends them with only 1
FCS/CRC, thus it makes 1 big packet of my smaller packets, and this is
not wanted).
Is there some other function or API I can use to get better performance
for sending packets at very high bitrates, even very small packets?
(sendto is only bitrate-reliable until 150 Mbit/s, which is too small
for my use, and I guess sendmsg() would help there).
What's wrong with this code?
Thanks
Yannick
http://www.loth.be/yannick/stressnet/index.html
(if this is not the right list, which list would be ok?)
-----------------
-Here's the code-
-----------------
namespace stressnet{
struct packetListElement
{
struct iovec * data;
struct packetListElement * next;
};
}
struct msghdr msgHeader;
struct iovec *iovArray=new struct iovec[2];
struct stressnet:

acketListElement *ple;
ple=df->getPListRootElement();
for(int i=0;i<2;++i)
{
memcpy(iovArray+i,ple->data,sizeof(struct iovec));
std::cout<<ple->data->iov_len<<std::endl;
ple=ple->next;
}
msgHeader.msg_iovlen=2;
msgHeader.msg_name=(void *)pSocket->getLocalSockAddr();
/* this is a pointer to a struct sockaddr_ll socket address
* which is correctly initialized as it does work with sendto()
*/
msgHeader.msg_namelen=sizeof(struct sockaddr_ll);
msgHeader.msg_control=NULL;
/* no ancillary data
*/
msgHeader.msg_controllen=0;
int result;
if ((result=sendmsg (pSocket->getSocketDescriptor(), &msgHeader, 0))<0)
{
perror("sendmsg() failed");
}
std::cout<<result<<std::endl;
-------------------
-Here's the output-
-------------------
Raw socket successfully created!
Socket family: 17
Ethernet protocol: 3
Interface index: 2
Socket bound!
60
60
sendmsg() failed: Message too long
-1