Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trySend:
- int sent;
- {
- int skt = socket(AF_INET, SOCK_DGRAM, 0);
- sockaddr_in src_addr;
- memset(&src_addr, 0, sizeof src_addr);
- src_addr.sin_family = AF_INET;
- src_addr.sin_addr.s_addr = htonl(f.fSrcHost.toIPv4Address());
- src_addr.sin_port = 0;
- sockaddr_in dst_addr;
- memset(&dst_addr, 0, sizeof dst_addr);
- dst_addr.sin_family = AF_INET;
- dst_addr.sin_addr.s_addr = htonl(f.fHost.toIPv4Address());
- dst_addr.sin_port = htons(MDK_CMD_UDP_PORT);
- if (bind(skt, (sockaddr *)&src_addr, sizeof src_addr) == -1) DLOG_PF("bind: %1", errno);
- sent = sendto(skt, dg.data(), dg.size(), 0, (sockaddr *)&dst_addr, sizeof dst_addr);
- close(skt);
- ++pktCnt;
- pktSize += dg.size();
- }
- if ((sent != dg.size()))
- DLOG_PF("sendto error %1 %2 %3 [%4 %5]", sent, dg.size(), errno, pktCnt, pktSize);
- if (errno == ENOBUFS)
- {
- DLOG_PF("ENOBUFS sleep");
- sleep(1);
- goto trySend;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement