社区
C语言
帖子详情
不同版本GCC编译的问题!
crossfire_sli
2010-07-26 04:03:35
一程序,在Ubuntu 10.04下用GCC编译有warning(涉及到类型转换的, 没问题),运行时就提示如下:
*** stack smashing detected ***: ./a.out terminated
还是那同样的程序,放到redhat 9.0上用GCC编译,运行OK。
真不知道为什么。错误提示不懂。
恳请指个方向。
...全文
216
4
打赏
收藏
不同版本GCC编译的问题!
一程序,在Ubuntu 10.04下用GCC编译有warning(涉及到类型转换的, 没问题),运行时就提示如下: *** stack smashing detected ***: ./a.out terminated 还是那同样的程序,放到redhat 9.0上用GCC编译,运行OK。 真不知道为什么。错误提示不懂。 恳请指个方向。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
skyworth98
2010-07-26
打赏
举报
回复
parp.ar_hrd = htons(ARPHRD_ETHER); //这个需要转网络字节序,为何ip,mac不转
ipone是RISC芯片,mac之前用的是power芯片,两者都是bigendian cpu,而tcp/ip协议栈最早是实现在big endian系统上的,所以不需要转换。
而x86系列的是little endian芯片,所以在x86系列上的都需要转换,新的基于intel芯片的mac也需要转换。
crossfire_sli
2010-07-26
打赏
举报
回复
#include <stdio.h> //perror
#include <sys/types.h> //socket
#include <sys/socket.h> //socket
#include <string.h> //memcpy
#include <unistd.h> //usleep
#include <stdlib.h>
#include <net/if_arp.h> //struct arphdr parp&struct ether_header
#include <net/ethernet.h> //同上
#define ARP_LEN 30
void mac_str(char * mac, char * buf)
{
sscanf(mac, "%x:%x:%x:%x:%x:%x", buf, buf+1, buf+2, buf+3, buf+4, buf+5);
}
void ip_str(char * ip, char * buf)
{
sscanf(ip, "%d.%d.%d.%d", buf+0, buf+1, buf+2, buf+3);
}
void encapsulate_frame( char * dest_mac, char * source_mac, unsigned int type, char * buf)
{
mac_str( dest_mac, buf );
mac_str( source_mac, buf+6 );
*(short *)( buf+12) = htons(type); //the first * is missing...
}
void encapsulate_arp( unsigned short ar_op, char * source_mac, char * source_ip, char * dest_mac, char * dest_ip, char * buf)
{
struct arphdr parp;
parp.ar_hrd = htons(ARPHRD_ETHER); //这个需要转网络字节序,为何ip,mac不转
parp.ar_pro = htons(ETHERTYPE_IP);
parp.ar_hln = 6;
parp.ar_pln = 4;
parp.ar_op = htons(ar_op);
memcpy(buf, &parp, sizeof(struct arphdr));
char addr_buf[20];
mac_str(source_mac, addr_buf);
ip_str(source_ip, addr_buf+6);
mac_str(dest_mac, addr_buf+10);
ip_str(dest_ip, addr_buf+16);
memcpy(buf+sizeof(struct arphdr), addr_buf, 20);
}
int open_packet_socket(void)
{
int sock;
if( (sock = socket(AF_INET, SOCK_PACKET, htons(ETH_P_RARP))) < 0 ) //AF_INET,采用TCP/IP|SOCK_PACKET原始套接口,自己封装|
{
perror("The RAW socket was not created.");
exit(-1);
}; //missing ;
return sock;
}
int main()
{
char * source_ip = "210.41.192.1";
char * source_mac = "00:25:64:7A:B6:2E";
char * dest_ip = "210.41.196.93";
char * dest_mac = "00:0A:E6:E2:EF:E2";
char * buf = malloc( sizeof(struct ether_header)+ARP_LEN ); //以太网头的长度+arp头的长度
encapsulate_frame( dest_mac, source_mac, ETHERTYPE_ARP, buf );
encapsulate_arp( ARPOP_REPLY, source_mac, source_ip, dest_mac, dest_ip, buf+sizeof(struct ether_header) );
int sock_fd = open_packet_socket();
struct sockaddr to; //创建一个结构,表示发送给谁
bzero( &to, sizeof(struct sockaddr) );
to.sa_family = AF_INET;
strcpy( to.sa_data, "eth0" ); //通过eth0发送出去
while(1)
{
sendto( sock_fd, buf, sizeof(struct ether_header)+ARP_LEN, 0, &to, sizeof(struct sockaddr));
//0,采用默认方式发送|&to通过eth0网卡发送|
usleep( 100 );
}
}
skyworth98
2010-07-26
打赏
举报
回复
根据错误提示,貌似你有什么地方有栈缓冲区溢出,建议检查局部变量的使用
[Quote=引用楼主 crossfire_sli 的回复:]
一程序,在Ubuntu 10.04下用GCC编译有warning(涉及到类型转换的, 没问题),运行时就提示如下:
*** stack smashing detected ***: ./a.out terminated
还是那同样的程序,放到redhat 9.0上用GCC编译,运行OK。
真不知道为什么。错误提示不懂。
恳请指个方向。
[/Quote]
ilwmin
2010-07-26
打赏
举报
回复
上代码
【
gcc
】高
版本
gcc
编译
出的程序在低
版本
glibc机器上运行
本文探讨了在
不同
GCC
版本
环境下
编译
和运行程序时遇到的
问题
,包括静态
编译
的局限性、容器发布的适用场景、安装部署devtoolset以解决
版本
冲突,以及打包依赖的SO文件的两种方法。重点介绍了通过设置rpath和dynamic-linker在
编译
时解决依赖,以及使用patchelf工具在无法重新
编译
时修改二进制文件的rpath和interpreter。
GCC
不同
版本
的
编译
方法
本文介绍了
GCC
不同
版本
的
编译
方法。
GCC
3.2以下
版本
编译
涉及内核头文件设置、二进制工具设置等步骤,
gcc
需
编译
两次。
GCC
3.2以上
版本
编译
包括二进制工具设置、Glibc头文件安装、
GCC
两次交叉
编译
等,两次
编译
均由主系统的
gcc
和binutils完成。
riscv各种
版本
gcc
工具链
编译
与安装
本文详细介绍了RISC-V架构下
GCC
交叉
编译
器的
编译
过程及配置选项,包括裸机和Linux环境下的多种
版本
,如riscv32-unknown-elf-
gcc
、riscv64-unknown-elf-
gcc
等,并涵盖了multilib支持及嵌入式专用
版本
riscv-none-embed-
gcc
。
WSL2 Ubuntu安装
GCC
不同
版本
本文介绍在WSL2的Ubuntu 24.04中安装和卸载
不同
版本
GCC
的方法。安装旧版
GCC
7.1需手动操作,可通过源码
编译
或第三方PPA,但后者可能不兼容;安装
GCC
11及以上
版本
可直接通过官方仓库。卸载时需手动删除文件和目录,并清理环境变量等。
所有
Gcc
版本
对C和C++的支持情况(超详细
版本
)
文章介绍了如何查看
GCC
编译
器的
版本
,并详细列出了
不同
版本
GCC
对C和C++标准的默认支持情况,特别强调了C++11及以上的标准,如C++14和C++17。同时,提到了在不支持新标准的环境下如何通过指定
编译
标志来使用特定的C++
版本
功能,例如使用`lock_guard`和`mutex`解决并发
问题
。
C语言
70,039
社区成员
243,245
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章