blob: d98be54eb78630d6c5ceece34a11b24584086a3f [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include "ReceiveSocket.h"
2#include <string.h>
3#include <math.h>
4#include <errno.h>
5#include <stdint.h>
6#include <stddef.h>
7
8#include "aos/common/network/SocketLibraries.h"
Brian Silverman598800f2013-05-09 17:08:42 -07009#include "aos/common/logging/logging.h"
brians343bc112013-02-10 01:53:46 +000010
11namespace aos {
12
13static const char *localhost = "0.0.0.0";
14
15int ReceiveSocket::Connect(NetworkPort port) {
16 Reset();
17 const int ret = Socket::Connect(port, localhost);
18 if (ret != 0) {
19 return ret;
20 }
21
Brian Silvermana9cbe302013-03-12 18:41:44 -070022 if (bind(socket_, &addr_.addr,
brians343bc112013-02-10 01:53:46 +000023 sizeof(addr_)) == -1) {
24 LOG(ERROR, "failed to bind to address '%s' because of %d: %s\n", localhost,
25 errno, strerror(errno));
26 return last_ret_ = -1;
Brian Silvermana9cbe302013-03-12 18:41:44 -070027 }
brians343bc112013-02-10 01:53:46 +000028 return last_ret_ = 0;
29}
30
31} // namespace aos
32