热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在Ubuntu上使用TCP_REPAIRsocket选项编译代码-CompilingcodewithTCP_REPAIRsocketoptiononUbuntu

Followingthisarticle,IamtryingtogetaCprogramtocompilethatusesTPC_REPAIR.在本文之后,我尝试使用T

Following this article, I am trying to get a C program to compile that uses TPC_REPAIR.

在本文之后,我尝试使用TPC_REPAIR编译一个C程序。

http://oroboro.com/dealing-with-network-port-abuse-in-sockets-in-c/

http://oroboro.com/dealing-with-network-port-abuse-in-sockets-in-c/

TCP_REPAIR is defined in

TCP_REPAIR定义在

/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h

Including this header conflicts with the ones required for other socket APIs.

包含此头与其他套接字api所需的头冲突。

Here's my code

这是我的代码

#include 
#include 
#include 
#include 
#include 
#include "/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h"
int main(int argc, char* argv[])
{
    int cfd;
    struct sockaddr_in addr;
    char ch='r';
    cfd=socket(AF_INET, SOCK_STREAM, 0);
    addr.sin_family=AF_INET;
    addr.sin_addr.s_addr=inet_addr("10.160.102.40");
    addr.sin_port=htons(9988);
    if(connect(cfd, (struct sockaddr *)&addr,
    sizeof(addr))<0) {
        perror("connect error");
        return -1;
    }
    if(write(cfd, &ch, 1)<0) perror("write");
    if(read(cfd, &ch, 1)<0) perror("read");
    printf("\nReply from Server: %c\n",ch);
    //close(cfd);

    int aux = 1;
    if(setsockopt(cfd, SOL_TCP, TCP_REPAIR, &aux, sizeof( aux )) <0 )
    {
        perror( "could not turn on repair mode" );
    }
   return 0;
}

And here's gcc output

这里是gcc输出

In file included from /usr/include/netinet/tcp.h:56:0,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:45:18: error: conflicting types for ‘loff_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:45:26: note: previous declaration of ‘loff_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:61:17: error: conflicting types for ‘dev_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:15:25: note: previous declaration of ‘dev_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:76:19: error: conflicting types for ‘nlink_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:19:17: note: previous declaration of ‘nlink_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:133:0,
                 from /usr/include/netinet/tcp.h:56,
                 from new_client.c:5:
/usr/include/time.h:104:19: error: conflicting types for ‘timer_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:25:26: note: previous declaration of ‘timer_t’ was here
In file included from /usr/include/netinet/tcp.h:56:0,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:198:1: error: conflicting types for ‘int64_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:113:17: note: previous declaration of ‘int64_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:204:1: error: conflicting types for ‘u_int64_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:112:17: note: previous declaration of ‘u_int64_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:220:0,
                 from /usr/include/netinet/tcp.h:56,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/select.h:76:5: error: conflicting types for ‘fd_set’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:14:26: note: previous declaration of ‘fd_set’ was here
In file included from /usr/include/netinet/tcp.h:56:0,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:236:20: error: conflicting types for ‘blkcnt_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:134:23: note: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/uio.h:29:0,
                 from /usr/include/x86_64-linux-gnu/sys/socket.h:28,
                 from /usr/include/netinet/tcp.h:57,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/uio.h:44:8: error: redefinition of ‘struct iovec’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/uio.h:16:8: note: originally defined here
In file included from /usr/include/x86_64-linux-gnu/sys/socket.h:40:0,
                 from /usr/include/netinet/tcp.h:57,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/socket.h:180:8: error: redefinition of ‘struct sockaddr’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/socket.h:19:27: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:193:8: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/socket.h:13:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:204:5: error: expected identifier before numeric constant
/usr/include/x86_64-linux-gnu/bits/socket.h:253:8: error: redefinition of ‘struct msghdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:47:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:280:8: error: redefinition of ‘struct cmsghdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:69:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:310:24: error: conflicting types for ‘__cmsg_nxthdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:111:32: note: previous definition of ‘__cmsg_nxthdr’ was here
/usr/include/x86_64-linux-gnu/bits/socket.h:339:5: error: expected identifier before numeric constant
In file included from /usr/include/x86_64-linux-gnu/sys/socket.h:40:0,
                 from /usr/include/netinet/tcp.h:57,
                 from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/socket.h:417:8: error: redefinition of ‘struct linger’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:34:8: note: originally defined here
In file included from new_client.c:6:0:
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:24:8: error: redefinition of ‘struct tcphdr’
/usr/include/netinet/tcp.h:92:8: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:135:6: error: nested redefinition of ‘enum tcp_ca_state’
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:135:6: error: redeclaration of ‘enum tcp_ca_state’
/usr/include/netinet/tcp.h:179:6: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:136:2: error: redeclaration of enumerator ‘TCP_CA_Open’
/usr/include/netinet/tcp.h:181:3: note: previous definition of ‘TCP_CA_Open’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:138:2: error: redeclaration of enumerator ‘TCP_CA_Disorder’
/usr/include/netinet/tcp.h:182:3: note: previous definition of ‘TCP_CA_Disorder’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:140:2: error: redeclaration of enumerator ‘TCP_CA_CWR’
/usr/include/netinet/tcp.h:183:3: note: previous definition of ‘TCP_CA_CWR’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:142:2: error: redeclaration of enumerator ‘TCP_CA_Recovery’
/usr/include/netinet/tcp.h:184:3: note: previous definition of ‘TCP_CA_Recovery’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:144:2: error: redeclaration of enumerator ‘TCP_CA_Loss’
/usr/include/netinet/tcp.h:185:3: note: previous definition of ‘TCP_CA_Loss’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:148:8: error: redefinition of ‘struct tcp_info’
/usr/include/netinet/tcp.h:188:8: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:193:8: error: redefinition of ‘struct tcp_md5sig’
/usr/include/netinet/tcp.h:235:8: note: originally defined here

1 个解决方案

#1


4  

This is really not useful

这真的没有用

#include "/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h"

Because either the kernel supports it or it does not. You can check for it like this:

因为内核要么支持它,要么不支持。你可以这样检查:

find /usr/include -type f -exec grep TCP_REPAIR {} /dev/null \;
/usr/include/linux/tcp.h:#define TCP_REPAIR     19  /* TCP sock is under repair right now */
/usr/include/linux/tcp.h:#define TCP_REPAIR_QUEUE   20
/usr/include/linux/tcp.h:#define TCP_REPAIR_OPTIONS 22

if it's there, great, otherwise you'll have to use the workaround.

如果它在那里,很好,否则你将不得不使用变通方法。

Here's an Ubuntu that has it

这是一个Ubuntu

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.10
Release:        12.10
Codename:       quantal

It looks like SOL_TCP is only defined in /usr/include/netinet/tcp.h

看起来SOL_TCP只在/usr/include/netinet/tcp.h中定义

find /usr/include -type f -exec grep SOL_TCP {} /dev/null \;
/usr/include/netinet/tcp.h:# define SOL_TCP     6   /* TCP level */

To overcome the unfortunate absence of SOL_TCP in /usr/include/linux/tcp.h. You can try to simply copy it from netinet/tcp.h, it's just a number after all.

为了克服/usr/include/linux/tcp.h中SOL_TCP的不幸缺失您可以尝试从netinet/tcp复制它。h,它毕竟只是一个数字。

#ifndef SOL_TCP
#define SOL_TCP 6
#endif

However, the man page of setsockopt offers an even better approach:

不过,setsockopt的man页面提供了一种更好的方法:

To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; see getprotoent(3).

要在任何其他级别操作选项,提供控制选项的适当协议的协议编号。例如,为了表示一个选项将由TCP协议解释,应该将级别设置为TCP的协议号;看到getprotoent(3)。


推荐阅读
  • 本文介绍了为什么要使用多进程处理TCP服务端,多进程的好处包括可靠性高和处理大量数据时速度快。然而,多进程不能共享进程空间,因此有一些变量不能共享。文章还提供了使用多进程实现TCP服务端的代码,并对代码进行了详细注释。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • c语言\n不换行,c语言printf不换行
    本文目录一览:1、C语言不换行输入2、c语言的 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 开发笔记:实验7的文件读写操作
    本文介绍了使用C++的ofstream和ifstream类进行文件读写操作的方法,包括创建文件、写入文件和读取文件的过程。同时还介绍了如何判断文件是否成功打开和关闭文件的方法。通过本文的学习,读者可以了解如何在C++中进行文件读写操作。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
  • 如何在跨函数中使用内存?
    本文介绍了在跨函数中使用内存的方法,包括使用指针变量、动态分配内存和静态分配内存的区别。通过示例代码说明了如何正确地在不同函数中使用内存,并提醒程序员在使用动态分配内存时要手动释放内存,以防止内存泄漏。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • Commit1ced2a7433ea8937a1b260ea65d708f32ca7c95eintroduceda+Clonetraitboundtom ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 本文介绍了最长上升子序列问题的一个变种解法,通过记录拐点的位置,将问题拆分为左右两个LIS问题。详细讲解了算法的实现过程,并给出了相应的代码。 ... [详细]
author-avatar
当初
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有