vendredi 6 mars 2015

TCP sendto (C++) fails on Linux but not OSX. Errno: EINVAL 22 Invalid argument

On the client side of my application, the following runs fine on OSX. But when compiled/run on Linux (Ubuntu 12 or Raspbian) sendto() always fails with a EINVAL/22/invalid argument. How do I run it on Linux?



std::vector<uint8_t> rawVect;
// rawVect.push_back()...a bunch of bytes

const uint8_t* sendBytes = &rawVect[0]; // or rawVect.data();
size_t sendSize = rawVect.size();

if(sendSize > 0){

long numBytes = sendto(control_fd, sendBytes, sendSize, 0, res->ai_addr, _res->ai_addrlen);
}


I suspect C++ 11 libraries and std::vectors on Linux. My makefile looks similar to this.



mac:
g++ -std=c++0x myprogram.cpp
# (w/ llvm libc++)

ubuntu:
clang++-3.5 -g -std=c++11 -stdlib=libc++ myprogram.cpp
# couldn't use g++ 4.8 or prior because it didn't support std::vector::insert as I was using it elsewhere. 4.9 not avail for Ubuntu 12.

pi:
g++-4.9 -std=c++0x myprogram.cpp

Aucun commentaire:

Enregistrer un commentaire