编程语言
首页 > 编程语言> > c – 安全UDP套接字编程

c – 安全UDP套接字编程

作者:互联网

在UDP客户端/服务器上阻止DoS攻击有哪些好的编程实践?目前唯一想到的是忽略具有错误源的数据包,因此(使用WinSock2):

if (oSourceAddr.sa_family == AF_INET) {
    uSourceAddr = inet_addr(oSourceAddr.sa_data);

    if (uSourceAddr == oCorrectDestAddr.sin_addr.S_un.S_addr) {
        queueBuffer.push(std::string(aBuffer));
    }
}

足够快的攻击可能导致这种情况在循环中阻塞 – 特别是如果数据包大小很小.有没有办法可以防止数据包来自某个来源,或者除了正确来源之外的任何来源?我应该注意哪些其他事项?如果解决方案已内置到API中,则代码形式的解释将特别有用.

解决方法:

Is there a way I can prevent packets from arriving from a certain source, or any source besides the correct one?

是.只需将套接字()连接到正确的源.然后UDP将过滤掉其他地址的所有数据报.请参阅man 2 connect,有关SOCK_DGRAM套接字的段落.

标签:c,security,winsock2,udp,denial-of-service
来源: https://codeday.me/bug/20190825/1718724.html