c语言访问以太坊
㈠ 我以太坊怎么进不了怎么办
是不是网络不好,你重新登陆进去看看,如果还是不行,可以重启手机试试的。
㈡ 在cygwin下想用c语言调用libpcap实现网络抓包。是不是cygwin下不支持libpcap
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <errno.h>
/* 接收缓冲区大小 */
#define RCV_BUF_SIZE 1024 * 5
/* 接收缓冲区 */
static int g_iRecvBufSize = RCV_BUF_SIZE;
static char g_acRecvBuf[RCV_BUF_SIZE] = {0};
/* 物理网卡接口,需要根据具体情况修改 */
static const char *g_szIfName = "eth1";
/* 以太网帧封装的协议类型 */
static const int g_iEthProId[] = { ETHERTYPE_PUP,
ETHERTYPE_SPRITE,
ETHERTYPE_IP,
ETHERTYPE_ARP,
ETHERTYPE_REVARP,
ETHERTYPE_AT,
ETHERTYPE_AARP,
ETHERTYPE_VLAN,
ETHERTYPE_IPX,
ETHERTYPE_IPV6,
ETHERTYPE_LOOPBACK
};
static const char g_szProName[][24] = {
"none", "xerox pup", "sprite", "ip", "arp",
"rarp", "apple-protocol", "apple-arp",
"802.1q", "ipx", "ipv6", "loopback"
};
/* 输出MAC地址 */
static void ethmp_showMac(const int iType, const char acHWAddr[])
{ int i = 0;
if (0 == iType)
{
printf("SMAC=[");
}
else
{
printf("DMAC=[");
}
for(i = 0; i < ETHER_ADDR_LEN - 1; i++)
{
printf("%02x:", *((unsigned char *)&(acHWAddr[i])));
}
printf("%02x] ", *((unsigned char *)&(acHWAddr[i])));
}
/* 物理网卡混杂模式属性操作 */
static int ethmp_setPromisc(const char *pcIfName, int fd, int iFlags)
{ int iRet = -1;
struct ifreq stIfr;
/* 获取接口属性标志位 */
strcpy(stIfr.ifr_name, pcIfName);
iRet = ioctl(fd, SIOCGIFFLAGS, &stIfr);
if (0 > iRet)
{ perror("[Error]Get Interface Flags");
return -1;
}
if (0 == iFlags)
{ /* 取消混杂模式 */
stIfr.ifr_flags &= ~IFF_PROMISC;
}
else
{ /* 设置为混杂模式 */
stIfr.ifr_flags |= IFF_PROMISC;
}
iRet = ioctl(fd, SIOCSIFFLAGS, &stIfr);
if (0 > iRet)
{ perror("[Error]Set Interface Flags");
return -1;
}
return 0;
}
/* 获取L2帧封装的协议类型 */
static char *ethmp_getProName(const int iProNum)
{ int iIndex = 0;
for(iIndex = 0; iIndex < sizeof(g_iEthProId) / sizeof(g_iEthProId[0]); iIndex++)
{ if (iProNum == g_iEthProId[iIndex])
{
break;
}
}
return (char *)(g_szProName[iIndex + 1]);
}
/* Init L2 Socket */
static int ethmp_initSocket()
{ int iRet = -1;
int fd = -1;
struct ifreq stIf;
struct sockaddr_ll stLocal = {0};
/* 创建SOCKET */
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (0 > fd)
{ perror("[Error]Initinate L2 raw socket");
return -1;
}
/* 网卡混杂模式设置 */
ethmp_setPromisc(g_szIfName, fd, 1);
/* 设置SOCKET选项 */
iRet = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &g_iRecvBufSize,sizeof(int));
if (0 > iRet)
{ perror("[Error]Set socket option");
close(fd);
return -1;
}
/* 获取物理网卡接口索引 */
strcpy(stIf.ifr_name, g_szIfName);
iRet = ioctl(fd, SIOCGIFINDEX, &stIf);
if (0 > iRet)
{ perror("[Error]Ioctl operation");
close(fd);
return -1;
}
/* 绑定物理网卡 */
stLocal.sll_family = PF_PACKET;
stLocal.sll_ifindex = stIf.ifr_ifindex;
stLocal.sll_protocol = htons(ETH_P_ALL);
iRet = bind(fd, (struct sockaddr *)&stLocal, sizeof(stLocal));
if (0 > iRet)
{ perror("[Error]Bind the interface");
close(fd);
return -1;
}
return fd;
}
/* 解析Ethernet帧首部 */
static int ethmp_parseEthHead(const struct ether_header *pstEthHead)
{ unsigned short usEthPktType;
if (NULL == pstEthHead)
{ return -1;}
/* 协议类型、源MAC、目的MAC */
usEthPktType = ntohs(pstEthHead->ether_type);
printf(">>>\nEth-Pkt-Type:0x%04x(%s) ", usEthPktType, ethmp_getProName(usEthPktType));
ethmp_showMac(0, pstEthHead->ether_shost);
ethmp_showMac(1, pstEthHead->ether_dhost);
return 0;
}
/* 解析IP数据包头 */
static int ethmp_parseIpHead(const struct ip *pstIpHead)
{ struct protoent *pstIpProto = NULL;
if (NULL == pstIpHead)
{ return -1;}
/* 协议类型、源IP地址、目的IP地址 */
pstIpProto = getprotobynumber(pstIpHead->ip_p);
if(NULL != pstIpProto)
{ printf("\nIP-Pkt-Type:%d(%s) ", pstIpHead->ip_p, pstIpProto->p_name); }
else
{ printf("\nIP-Pkt-Type:%d(%s) ", pstIpHead->ip_p, "None");}
printf("SAddr=[%s] ", inet_ntoa(pstIpHead->ip_src));
printf("DAddr=[%s]\n", inet_ntoa(pstIpHead->ip_dst));
return 0;
}
/* 数据帧解析函数 */
static int ethmp_parseFrame(const char *pcFrameData)
{ int iRet = -1;
struct ether_header *pstEthHead = NULL;
struct ip *pstIpHead = NULL;
/* Ethnet帧头解析 */
pstEthHead = (struct ether_header*)g_acRecvBuf;
iRet = ethmp_parseEthHead(pstEthHead);
if (0 > iRet)
{ return iRet;}
/* IP数据包类型 */
pstIpHead = (struct ip *)(pstEthHead + 1);
iRet = ethmp_parseIpHead(pstIpHead);
return iRet;
}
/* 捕获网卡数据帧 */
static void ethmp_startCapture(const int fd)
{ int iRet = -1;
socklen_t stFromLen = 0;
/* 循环监听 */
while(1)
{ /* 清空接收缓冲区 */
memset(g_acRecvBuf, 0, RCV_BUF_SIZE);
/* 接收数据帧 */
iRet = recvfrom(fd, g_acRecvBuf, g_iRecvBufSize, 0, NULL, &stFromLen);
if (0 > iRet)
{ continue;}
/* 解析数据帧 */
ethmp_parseFrame(g_acRecvBuf);
}
}
/* Main */
int main(int argc, char *argv[])
{ int iRet = -1;
int fd = -1;
/* 初始化SOCKET */
fd = ethmp_initSocket();
if(0 > fd) {
return -1;
}
/* 捕获数据包 */
ethmp_startCapture(fd);
/* 关闭SOCKET */
close(fd);
return 0;
}
编译命令
gcc -o a a.c
./a
实现效果图
...
>>>Eth-Pkt-Type:0x0800(ip) SMAC=[00:1a:92:ef:b6:dd] DMAC=[00:24:7e:dc:99:18] IP-Pkt-Type:6(tcp) SAddr=[192.168.0.111] DAddr=[192.168.0.100]
>>> Eth-Pkt-Type:0x0800(ip) SMAC=[00:24:7e:dc:99:18] DMAC=[00:1a:92:ef:b6:dd] IP-Pkt-Type:6(tcp) SAddr=[192.168.0.100] DAddr=[192.168.0.111]
>>> Eth-Pkt-Type:0x0800(ip) SMAC=[00:24:7e:dc:99:18] DMAC=[00:1a:92:ef:b6:dd] IP-Pkt-Type:1(icmp) SAddr=[192.168.0.100] DAddr=[192.168.0.111]
>>> Eth-Pkt-Type:0x0800(ip) SMAC=[00:1a:92:ef:b6:dd] DMAC=[00:24:7e:dc:99:18] IP-Pkt-Type:1(icmp) SAddr=[192.168.0.111] DAddr=[192.168.0.100]
>>> Eth-Pkt-Type:0x0800(ip) SMAC=[00:1a:92:ef:b6:dd] DMAC=[00:24:7e:dc:99:18] IP-Pkt-Type:6(tcp) SAddr=[192.168.0.111] DAddr=[192.168.0.100]
...
㈢ 求助在linux下用c语言取得双网卡的网关地址
两个网卡当然可以设置两个网关。 两种方法(redhat为例): 1、修改配置文件: 假设两个网卡名分别为eth0,eth1。可以分别修改配置文件/etc/sysconfig/network-scripts/ifcfg-eth0 及/etc/sysconfig/network-scripts/ifcfg-eth1
㈣ 以太坊是什么
以太坊(英语:Ethereum)是一个开源的有智能合约功能的公共区块链平台。通过其专用加密货币以太币(Ether,又称“以太币”)提供去中心化的虚拟机(称为“以太虚拟机”EthereumVirtualMachine)来处理点对点合约。
坊区块链上的代币称为以太币(Ether),代码为ETH,可在许多加密货币的外汇市场上交易,它也是以太坊上用来支付交易手续费和运算服务的媒介。
以太坊的概念首次在2013至2014年间由程序员VitalikButerin,受比特币启发后提出,大意为“下一代加密货币与去中心化应用平台”,在2014年通过ICO众筹得以开始发展。截至2018年2月,以太币是市值第二高的加密货币,仅次于比特币。

(4)c语言访问以太坊扩展阅读:
以太坊平台本身没有特点,没有价值性。和编程语言相似,它由企业家和开发者决定其用途。不过很明显,某些应用类型较之其他更能从以太坊的功能中获益。以太坊尤其适合那些在点与点之间自动进行直接交互或者跨网络促进小组协调活动的应用。
例如,协调点对点市场的应用,或是复杂财务合同的自动化。比特币使个体能够不借助金融机构、银行或政府等其他中介来进行货币交换。以太坊的影响可能更为深远。
理论上,任何复杂的金融活动或交易都能在以太坊上用编码自动且可靠地进行。除金融类应用外,任何对信任、安全和持久性要求较高的应用场景——比如资产注册、投票、管理和物联网——都会大规模地受到以太坊平台影响。
㈤ APUE/Linux下通过C程序列出本机网卡eth0的IP。popen、fgets、gread、、、
fgets是每次读一行, fread是每次读size个,用什么自己决定。
㈥ linux嵌入式系统下编程修改ip mac地址,c语言程序,具体操作类似 ifconfig eth down ifconfig eth0 Up
#include <stdlib.h>int system(const char *string);例:在~/myprogram/目录下有shell脚本test.sh,内容为#!bin/bash#test.shecho $HOME在该目录下新建一个c文件systemtest.c,内容为:#include<stdlib.h>main(){
system("~/myprogram/test.sh");}执行结果如下:xiakeyou@ubuntu:~/myprogram$ gcc systemtest.c -o
systemtestxiakeyou@ubuntu:~/myprogram$ ./systemtest/home/d/e/xiakeyouxiakeyou@ubuntu:~/myprogram$2)popen(char *command,char *type)执行过程:popen()会调用fork()产生子进程,然后从子进程中调用/bin/sh
-c来执行参数command的指令。参数
type可使用“r”代表读取,“w”代表写入。依照此type值,popen()会建立管道连到子进程的标准输出设备或标准输入设备,然后返回一个文件
指针。随后进程便可利用此文件指针来读取子进程的输出设备或是写入到子进程的标准输入设备中。此外,所有使用文件指针(FILE*)操作的函数也都可以使
用,除了fclose()以外。返回值:若成功则返回文件指针,否则返回NULL,错误原因存于errno中。
注意:在编写具SUID/SGID权限的程序时请尽量避免使用popen(),popen()会继承环境变量,通过环境变量可能会造成系统安全的问题。例:C程序popentest.c内容如下:#include<stdio.h>main(){FILE * fp;charbuffer[80];fp=popen(“~/myprogram/test.sh”,”r”);fgets(buffer,sizeof(buffer),fp);printf(“%s”,buffer);pclose(fp);}执行结果如下:xiakeyou@ubuntu:~/myprogram$ vim popentest.cxiakeyou@ubuntu:~/myprogram$ gcc popentest.c -o popentestxiakeyou@ubuntu:~/myprogram$ ./popentest/home/d/e/xiakeyouxiakeyou@ubuntu:~/myprogram$
只是偶能力可能有点有限,没有太看懂。直接用system()倒是脚本可是执行,只是返回值却是一塌糊涂,试了多次也没有找到什么规律。不免又看了一下上面的那篇博文,得到一些启发,可以这样来实现:先将脚本的返回值利用 echo > XXXXX 输出到一个本地文件中当需要这个返回值是,可是通过C语言的文件操作函数来直接从文件中读取后来一想,这应该就是上文中POPEN的实现方法!C程序调用shell脚本共有三种法子 :system()、popen()、exec系列函数 system()
不用你自己去产生进程,它已经封装了,直接加入自己的命令exec 需要你自己 fork 进程,然后exec 自己的命令popen() 也可以实现执行你的命令,比system 开销小1)system(shell命令或shell脚本路径);system()会调用fork()产生 子历程,由子历程来调用/bin/sh-c string来履行
参数string字符串所代表的命令,此命令履行 完后随即返回原调用的历程。在调用system()期间SIGCHLD
信号会被暂时搁置,SIGINT和SIGQUIT 信号则会被漠视 。
返回值:如果system()在调用/bin/sh时失败则返回127,其他失败原因返回-1。若参数string为空指针(NULL),则返回非零值。
如果 system()调用成功 则最后会返回履行
shell命令后的返回值,但是此返回值也有可能为system()调用/bin/sh失败所返回的127,因 此最好能再反省 errno
来确认履行 成功 。system命令以其简略 高效的作用得到很很广泛 的利用 ,下面是一个例子例:在~/test/目录下有shell脚本test.sh,内容为#!bin/bash#test.shecho hello在同层目录下新建一个c文件system_test.c,内容为:#include<stdlib.h>int main(){system("~/test/test.sh");}履行 效果 如下:[root@localhost test]$gcc system_test.c -o system_test[root@localhost test]$./system_testhello[root@localhost test]$2)popen(char *command,char *type)popen()会调用fork()产生 子历程,然后从子历程中调用/bin/sh -c来履行
参数command的指令。参数type可应用 “r”代表读取,“w”代表写入。遵循此type值,popen()会建立
管道连到子历程的标准 输出设备 或标准 输入设备 ,然后返回一个文件指针。随后历程便可利用 此文件指针来读取子历程的输出设备
或是写入到子历程的标准 输入设备 中。此外,所有应用 文 件指针(FILE*)操作的函数也都可以应用
,除了fclose()以外。返回值:若成功 则返回文件指针,否则返回NULL,差错
原因存于errno中。注意:在编写具SUID/SGID权限的程序时请尽量避免应用popen(),popen()会继承环境变量,通过环境变量可能会造成系统安全的问题。例:C程序popentest.c内容如下:#include<stdio.h>main{FILE * fp;charbuffer[80];fp=popen(“~/myprogram/test.sh”,”r”);fgets(buffer,sizeof(buffer),fp);printf(“%s”,buffer);pclose(fp);}履行 效果 如下:[root@localhost test]$ vim popentest.c[root@localhost test]$ gcc popentest.c -o popentest[root@localhost test]$ ./popentest/root/test[root@localhost test]$
㈦ c语言如何实现文件处理,将log文件中的每一行中的某一特定部分保存到结构体中
#include<stdio.h>
struct
{
charstr[10];
}a[3];
intmain()
{
FILE*fp=fopen("log","r");
inti,t;
if(fp==NULL)return1;
for(i=0;i<3;i++)
{
fscanf(fp,"id.%dstring:%s ",&t,a[i].str);//读到结构体存储
printf("id.%dstring:%s ",i+1,a[i].str);//输出
}
fclose(fp);
return0;
}
㈧ 以太坊是干啥
区块链宠物游戏
以太小丑是由IAC广告宣传平台推出的一款区块链宠物养成游戏,结合养宠物的娱乐方式轻松赚钱,同时结合区块链技术,确保玩家利益。 体验抚养,打工,收益,转卖的游戏乐趣,画面精美,体验丰富,收益快乐!做真正的游戏让玩家得到更畅爽的体验,用游戏这一广为人知的产品形态,把人类带入全智时代!
以太小丑是数字收藏品,非标准的数字货币(以太币等),基于区块链,永不可更改,可以通过第三方平台的验证清楚的查询到相关数据信息!以太小丑(CryptoClow)是基于以太坊区块链开发的数字化的,有收藏价值的区块链游戏。使用以太币领养小丑,同时可以转卖,也可以用他们去繁育出各种造型奇特的新一代小丑,还可以培育他们去打工赚钱,让小丑这个数字收藏品有了更多的持续性和可玩性。#以太坊小丑#
㈨ linux 里通过想写一个c语言的文件 ,通过执行文件可以修改ifcfg-eth0中的IPADDR的值
//获取本机IP地址函数
view plain to clipboardprint?
01.QString GetLocalIp()
02.{
03.
04. int sock_get_ip;
05. char ipaddr[50];
06.
07. struct sockaddr_in *sin;
08. struct ifreq ifr_ip;
09.
10. if ((sock_get_ip=socket(AF_INET, SOCK_STREAM, 0)) == -1)
11. {
12. printf("socket create failse...GetLocalIp!\n");
13. return "";
14. }
15.
16. memset(&ifr_ip, 0, sizeof(ifr_ip));
17. strncpy(ifr_ip.ifr_name, "eth0", sizeof(ifr_ip.ifr_name) - 1);
18.
19. if( ioctl( sock_get_ip, SIOCGIFADDR, &ifr_ip) < 0 )
20. {
21. return "";
22. }
23. sin = (struct sockaddr_in *)&ifr_ip.ifr_addr;
24. strcpy(ipaddr,inet_ntoa(sin->sin_addr));
25.
26. printf("local ip:%s \n",ipaddr);
27. close( sock_get_ip );
28.
29. return QString( ipaddr );
30.}
QString GetLocalIp()
{
int sock_get_ip;
char ipaddr[50];
struct sockaddr_in *sin;
struct ifreq ifr_ip;
if ((sock_get_ip=socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("socket create failse...GetLocalIp!\n");
return "";
}
memset(&ifr_ip, 0, sizeof(ifr_ip));
strncpy(ifr_ip.ifr_name, "eth0", sizeof(ifr_ip.ifr_name) - 1);
if( ioctl( sock_get_ip, SIOCGIFADDR, &ifr_ip) < 0 )
{
return "";
}
sin = (struct sockaddr_in *)&ifr_ip.ifr_addr;
strcpy(ipaddr,inet_ntoa(sin->sin_addr));
printf("local ip:%s \n",ipaddr);
close( sock_get_ip );
return QString( ipaddr );
}
//修改本机IP地址的函数
int SetLocalIp( const char *ipaddr )
{
int sock_set_ip;
struct sockaddr_in sin_set_ip;
struct ifreq ifr_set_ip;
bzero( &ifr_set_ip,sizeof(ifr_set_ip));
if( ipaddr == NULL )
return -1;
if(sock_set_ip = socket( AF_INET, SOCK_STREAM, 0 ) == -1);
{
perror("socket create failse...SetLocalIp!\n");
return -1;
}
memset( &sin_set_ip, 0, sizeof(sin_set_ip));
strncpy(ifr_set_ip.ifr_name, "eth0", sizeof(ifr_set_ip.ifr_name)-1);
sin_set_ip.sin_family = AF_INET;
sin_set_ip.sin_addr.s_addr = inet_addr(ipaddr);
memcpy( &ifr_set_ip.ifr_addr, &sin_set_ip, sizeof(sin_set_ip));
if( ioctl( sock_set_ip, SIOCSIFADDR, &ifr_set_ip) < 0 )
{
perror( "Not setup interface\n");
return -1;
}
//设置激活标志
ifr_set_ip.ifr_flags |= IFF_UP |IFF_RUNNING;
//get the status of the device
if( ioctl( sock_set_ip, SIOCSIFFLAGS, &ifr_set_ip ) < 0 )
{
perror("SIOCSIFFLAGS");
return -1;
}
close( sock_set_ip );
return 0;
}
