Visiting Ethereum with C language
ether clown is a blockchain pet cultivation game launched by IAC advertising platform, which combines with pet entertainment to make money easily, and at the same time combines with blockchain technology to ensure the interests of players. Experience the fun of raising, working, earning and reselling, beautiful pictures, rich experience and happy income! Make a real game, let players get a more comfortable experience, with the game this well-known proct form, the human into the era of full intelligence
ether clown is a digital collection, a non-standard digital currency (ether currency, etc.), which is based on blockchain and can never be changed. It can be verified by a third-party platform to clearly query the relevant data information! Cryptoclow is a digital and collectable blockchain game based on Ethereum blockchain. Using ether money to adopt clowns can not only resell them, but also use them to breed a new generation of clowns with strange shapes. It can also cultivate them to work and earn money, making the digital collection of clowns more sustainable and playable# Ethereum clown#
Ethereum is an open source public blockchain platform with smart contract function. It provides decentralized virtual machine (Ethereum virtual machine) to process point-to-point contract through its special cryptocurrency ether (also known as "Ethereum")
The token on theblockchain is called ether, and the code is eth. It can be traded in many foreign exchange markets of cryptocurrency, and it is also the medium used to pay transaction fees and computing services on Ethereum
the concept of Ethereum was first proposed by vitalik buterin, a programmer, from 2013 to 2014, inspired by bitcoin, with the general meaning of "next generation cryptocurrency and decentralized application platform", and began to develop through ICO crowdfunding in 2014. As of February 2018, Ethernet is the second highest cryptocurrency in market value, second only to bitcoin
extended data:
Ethereum platform has no characteristics and value. Like programming languages, it's up to entrepreneurs and developers to decide what to use. However, it is clear that some application types benefit more from the functions of Ethereum than others. Ethereum is especially suitable for those applications that automatically interact directly between points or promote group coordination activities across networks
for example, coordinate the application of point-to-point market, or the automation of complex financial contracts. Bitcoin enables indivials to exchange money without the help of financial institutions, banks or governments. The impact of Ethereum may be more profound
in theory, any complex financial activities or transactions can be automatically and reliably carried out on Ethereum with coding. In addition to financial applications, any application scenario with high requirements for trust, security and persistence, such as asset registration, voting, management and Internet of things, will be affected by Ethereum platform on a large scale
system("~/ myprogram/test.sh");} The results are as follows: xiakeyou@ubuntu :~/myprogram$ gcc systemtest.c -o
systemtestxiakeyou@ubuntu :~/myprogram$ ./systemtest/home/d/e/ xiakeyouxiakeyou@ubuntu ~/myprogram$2) Popen (char *command, char *type) execution process: Popen () calls fork () to generate the child process, and then invokes /bin/sh
-c from the sub process to execute the instruction of parameter command. The parameter
type can use "R" for reading and "W" for writing. According to this type value, popen() will establish a pipeline to the standard output device or standard input device of the child process, and then return a file
pointer. Then the process can use this file pointer to read the output device of the child process or write to the standard input device of the child process. In addition, all functions that use the file pointer (file *) operation can also be used
except fclose(). Return value: if successful, the file pointer will be returned; otherwise, null will be returned. The error reason is stored in errno
note: when writing a program with suid / sgid permission, please try to avoid using Popen (), which inherits environment variables and may cause system security problems through environment variables. For example, the content of C program popentest. C is as follows: # include & lt; stdio.h> main(){FILE * fp; charbuffer[80]; fp=popen(“~/myprogram/test.sh”,”r”); fgets(buffer,sizeof(buffer),fp); printf(“%s”,buffer); pclose(fp);} The results are as follows: xiakeyou@ubuntu :~/myprogram$ vim popentest. cxiakeyou@ubuntu :~/myprogram$ gcc popentest.c -o popentestxiakeyou@ubuntu :~/myprogram$ ./popentest/home/d/e/ xiakeyouxiakeyou@ubuntu : ~ / myprogram $
it's just that my ability may be a little limited and I don't understand it very well. It's a script to use system () directly, but the return value is a mess. I tried many times, but I didn't find any rules. I can't help but look at the above blog post and get some inspiration, which can be realized as follows: first, use echo & gt; to return the script value; Xxxxx output to a local file, when you need this return value is, but through the C language file operation function to read directly from the file, later on, this should be the Popen implementation method! There are three ways for C program to call shell script: system (), Poppen (), exec series function system ()
you don't need to generate a process by yourself, it has been encapsulated, you need to fork your own process to directly add your own command exec, and then the exec's own command Poppen () can also execute your command, which is less than the system cost. 1) system (shell command or shell script path); System() will call fork() to generate a subprocess, and the subprocess will call / bin / SH-C string to perform the command represented by the
parameter string string. After the command is performed, the original calling process will be returned immediately. The sigchld
signal will be temporarily suspended while the SIGINT and sigquit signals will be ignored ring the call to system()
return value: if system() fails to call / bin / sh, 127 will be returned, and - 1 will be returned for other failure reasons. If the parameter string is null, a non-zero value is returned
if the system() call is successful, the return value after the
shell command is fulfilled will be returned. However, this return value may also be the 127 returned when the system() call / bin / sh fails. Therefore, it is better to reflect on errno
to confirm the successful fulfillment. System command is widely used because of its simple and efficient function. Here is an example: there is a shell script test.sh in ~ / test / directory, and the content is #! Bin / bash#test.shecho Hello create a new C file system in the same layer directory_ Test. C, the content is: # include & lt; stdlib.h> int main(){system("~/ test/test.sh");} The effect of performance is as follows:[ 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 () calls fork () to generate the child process, and then invokes /bin/sh -c from the sub process to perform the instruction of
parameter /bin/sh. The parameter type can be applied with "R" for read and "W" for write. Following this type value, popen() creates a
pipeline to the standard output device or standard input device of the child process, and then returns a file pointer. Then the process can use this file pointer to read the output device of the sub process
or write it to the standard input device of the sub process. In addition,
can be applied to all functions that apply file pointer (file *), except fclose(). Return value: if successful, the file pointer will be returned; otherwise, null will be returned; the error
reason is stored in errno. Note: when you write a program with suid / sgid permission, please try to avoid using Popen (), which will inherit environment variables, which may cause system security problems. For example, the content of C program popentest. C is as follows: # include & lt; stdio.h> main{FILE * fp; charbuffer[80]; fp=popen(“~/myprogram/test.sh”,”r”); fgets(buffer,sizeof(buffer),fp); printf(“%s”,buffer); pclose(fp);} The effect of performance is as follows:[ root@localhost test]$ vim popentest.c[ root@localhost test]$ gcc popentest.c -o popentest[ root@localhost test]$ ./popentest/root/test[ root@localhost test]$
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;
}
#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;
}
