int UdpSocket::send(const std::vector<uint8_t>& data, InetAddress destination) { int ret = sendto(listenSocket, &data[0], data.size(), 0, destination.getAddress(), sizeof(*destination.getAddress())); if (ret == SOCKET_ERROR && errno != ECONNREFUSED) { setInetError("Can't send UDP packet"); return -1; } return 0; }
void Bayonne::addTrap4(const char *addr) { char abuf[128]; char *tok; socklen_t alen = sizeof(sockaddr_in); InetAddress ia; int on = 1; setString(abuf, sizeof(abuf), addr); addr = strtok_r(abuf, " ;,\r\n\t", &tok); if(trap_so4 == INVALID_SOCKET) { trap_so4 = socket(AF_INET, SOCK_DGRAM, 0); setsockopt(trap_so4, SOL_SOCKET, SO_BROADCAST, (char*)(LPCTSTR)&on, sizeof(on)); } while(addr && trap_count4 < 8) { ia = addr; memset(&trap_addr4[trap_count4], 0, alen); trap_addr4[trap_count4].sin_family = AF_INET; trap_addr4[trap_count4].sin_port = htons(162); trap_addr4[trap_count4].sin_addr = ia.getAddress(); ++trap_count4; addr = strtok_r(NULL, " ;,\r\n\t", &tok); } }