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;
}
