社区
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。
真不知道为什么。错误提示不懂。
恳请指个方向。
...全文
171
4
打赏
收藏
不同版本GCC编译的问题!
一程序,在Ubuntu 10.04下用GCC编译有warning(涉及到类型转换的, 没问题),运行时就提示如下: *** stack smashing detected ***: ./a.out terminated 还是那同样的程序,放到redhat 9.0上用GCC编译,运行OK。 真不知道为什么。错误提示不懂。 恳请指个方向。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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
打赏
举报
回复
上代码
linux
不同
gcc
编译
的库和运行时库的
版本
兼容
问题
gcc
4.9.3
编译
的库能被
gcc
4.8链接...是的,
编译
器
编译
了库之后和
编译
器是没有关系了,如果使用了新
版本
的
gcc
编译
出来的库,可能和系统自带运行库产生
版本
不兼容的现象。查看libc/libc++库的
版本
`strings "/lib/...
高
版本
gcc
编译
linux,高
版本
gcc
编译
出的程序在低
版本
glibc机器上运行
比如我们用
gcc
9.3.0
编译
程序,但需要发布的机器
gcc
版本
是4.8.5,怎么办?你可能想到如下方法静态
编译
容器发布打包依赖的so,使用本地so运行程序1.静态
编译
将libc和libstdc++静态
编译
,
编译
时带上如下参数。g++ -...
【
gcc
】高
版本
gcc
编译
出的程序在低
版本
glibc机器上运行
比如我们用
gcc
9.3.0
编译
程序,但需要发布的机器
gcc
版本
是4.8.5,怎么办? 你可能想到如下方法 静态
编译
容器发布 打包依赖的so,使用本地so运行程序 1.静态
编译
(多数场景不行) 其中静态
编译
是行不通的,...
不同
版本
gcc
编译
编译
相同kernel source code 的
问题
前一段时间,针对公司的设备(使用486sx的cpu,不带浮点运算单元,
编译
kernel的时候需要模拟FPU)在Fedora11上进行
编译
了一个486的kernel 在设备上运行,基本测试都OK,不过最近客户反应有
问题
,
问题
是计算...
多个
gcc
/glibc
版本
的共存及指定
gcc
版本
的
编译
文章目录需求背景知识什么是glibc,libc,glib...glibc的关系确定程序需要的```glibc/libstdc++```的
版本
解决步骤
编译
安装多个
gcc
/glibc
版本
共存指定
gcc
/g++,glibc的
版本
进行
编译
程序运行机器上的依赖总结 这篇文章
C语言
70,026
社区成员
243,245
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章