Commit 6e16caa0 authored by garciay's avatar garciay
Browse files

Bug fixed in udp_layer

parent 0159e1b8
......@@ -599,7 +599,7 @@ void geonetworking_layer::fill_beacon(const OCTETSTRING& p_ll_address, const INT
4,
LtBase(LtBase::e__50ms)
),
5
1
);
_beacon->gnPacket().packet() = GnNonSecuredPacket(
CommonHeader(
......
......@@ -32,8 +32,8 @@ udp_layer::udp_layer(const std::string & p_type, const std::string & param) : la
// Initialize the socket
_saddr.sin_family = AF_INET;
_saddr.sin_addr.s_addr = htonl(INADDR_ANY);
_saddr.sin_port = htons(std::atoi(_params["src_port"].c_str()));
_saddr.sin_addr.s_addr = INADDR_ANY;
_saddr.sin_port = ::htons(std::atoi(_params["src_port"].c_str()));
// Create socket
_fd = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (_fd == -1) {
......@@ -52,8 +52,8 @@ udp_layer::udp_layer(const std::string & p_type, const std::string & param) : la
Handler_Add_Fd_Read(_fd);
_daddr.sin_family = AF_INET;
_daddr.sin_addr.s_addr = htonl(get_host_id(_params["dsp_ip"]));
_daddr.sin_port = htons(std::atoi(_params["dst_port"].c_str()));
_daddr.sin_addr.s_addr = ::htonl(get_host_id(_params["dst_ip"]));
_daddr.sin_port = ::htons(std::atoi(_params["dst_port"].c_str()));
}
......@@ -76,7 +76,7 @@ void udp_layer::send_data(OCTETSTRING& data, params& params) {
loggers::get_instance().log_msg(">>> udp_layer::send_data: ", data);
int result = ::sendto(_fd, (const char*)static_cast<const unsigned char*>(data), data.lengthof(), 0, (struct sockaddr*)&_daddr, sizeof(_daddr));
loggers::get_instance().log("udp_layer::send_data: #bytes sent: %d", result);
loggers::get_instance().log("udp_layer::send_data: #bytes sent: %d to %s:%d", result, ::inet_ntoa(_daddr.sin_addr), ntohs(_daddr.sin_port));
}
void udp_layer::receive_data(OCTETSTRING& data, params& params) {
......@@ -111,15 +111,17 @@ unsigned long udp_layer::get_host_id(const std::string& p_host_name) {
loggers::get_instance().log(">>> udp_layer::get_host_id");
if (p_host_name.empty()) {
loggers::get_instance().warning("udp_layer::get_host_id: Wrong parameter");
return INADDR_ANY;
}
unsigned long ip_addr = 0;
if(p_host_name.compare("255.255.255.255") == 0) {
loggers::get_instance().warning("udp_layer::get_host_id: Host ip is 255.255.255.255");
ip_addr = 0xffffffff;
} else {
in_addr_t addr = ::inet_addr(p_host_name.c_str());
if (addr != (in_addr_t) - 1) { // host name in XX:XX:XX:XX form
if (addr != (in_addr_t)-1) { // host name in XX:XX:XX:XX form
ip_addr = addr;
} else { // host name in domain.com form
struct hostent* hptr;
......@@ -133,7 +135,7 @@ unsigned long udp_layer::get_host_id(const std::string& p_host_name) {
loggers::get_instance().log("udp_layer::get_host_id: Host name: %s, Host address: %u", p_host_name.c_str(), ip_addr);
return ip_addr;
return ::htonl(ip_addr);
}
udp_layer_factory udp_layer_factory::_f;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment