摘要:
转自:http://coolshell.cn/articles/7886.html在《性能调优攻略》里,我说过,要调优性需要找到程序中的Hotspot,也就是被调用最多的地方,这种地方,只要你能优化一点点,你的性能就会有质的提高。在这里我给大家举三个关于代码执行效率的例子(它们都来自于网上)第一个例子PHP中Getter和Setter的效率(来源reddit)这个例子比较简单,你可以跳过。考虑下面的PHP代码:我们可看到,使用Getter/Setter的方式,性能要比直接读写成员变量要差一倍以上。1234567891011121314151617181920212223242526272829 阅读全文
文章分类 - c
Get local ip in C on linux
2012-07-14 00:13 by Rollen Holt, 1602 阅读, 收藏,
摘要:
The local ip is the source ip in IP packets send out from a system. The kernal maintains routing tables which it uses to decide the default gateway , its interface and the local ip configured for that interface. The/proc/net/routefile (not really a file but appears like one) has more information abo 阅读全文
Get ip address from hostname in C using Linux sockets
2012-07-14 00:10 by Rollen Holt, 1385 阅读, 收藏,
摘要:
Here are 2 methods to get the ip address of a hostname :The first method uses the traditional gethostbyname function to retrieve information about a hostname/domain name.Code1#include<stdio.h> //printf2#include<string.h> //memset3#include<stdlib.h> //for exit(0);4#include<sys/so 阅读全文
Whois client code in C with Linux sockets
2012-07-14 00:08 by Rollen Holt, 713 阅读, 收藏,
摘要:
A whois client is a program that will simply fetch the whois information for a domain/ip address from the whois servers. The code over here works according to the algorithm discussed here.Code1/*2* @brief3* Whois client program4*5* @details6* This program shall perform whois for a domain and get you 阅读全文
Raw Sockets programming on Linux with C
2012-07-13 23:52 by Rollen Holt, 338 阅读, 收藏,
摘要:
Raw sockets or packets contain user defined IP headers. Its as simple as that.Here we shall consider sending a raw tcp packets. A tcp packets has 3 parts : IP header + TCP header + dataThe structure of IP Header as given by RFC 791 is :10 1 2 320 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 阅读全文
SYN Flood DOS Attack with C Source Code
2012-07-13 23:46 by Rollen Holt, 3658 阅读, 收藏,
摘要:
TCP/IP 3-way handshake is done to establish a connection between a client and a server. The process is :1. Client –SYN Packet–> Server2. Server –SYN/ACK Packet –> Client3. Client –ACK Packet –> ServerThe above 3 steps are followed to establish a connection between source and destination.SYN 阅读全文
Tcp syn portscan code in C with Linux sockets
2012-07-13 23:38 by Rollen Holt, 2058 阅读, 收藏,
摘要:
Port Scanning searches for open ports on a remote system. The basic logic for a portscanner would be to connect to the port we want to check. If the socket gives a valid connection without any error then the port is open , closed otherwise (or inaccessible, or filtered).This basic technique is calle 阅读全文
C语言程序的存储区域
2012-05-31 23:05 by Rollen Holt, 2338 阅读, 收藏,
摘要:
由C语言代码(文本文件)形成可执行程序(二进制文件),需要经过编译-汇编-连接三个阶段。编译过程把C语言文本文件生成汇编程序,汇编过程把汇编程序形成二进制机器代码,连接过程则将各个源文件生成的二进制机器代码文件组合成一个文件。 C语言编写的程序经过编译-连接后,将形成一个统一文件,它由几个部分组成。在程序运行时又会产生其他几个部分,各个部分代表了不同的存储区域: 1.代码段(Code或Text) 代码段由程序中执行的机器代码组成。在C语言中,程序语句进行编译后,形成机器代码。在执行程序的过程中,CPU的程序计数器指向代码段的每一条机器代码,并由处理器依次运行。 2.只读数据段(RO... 阅读全文
C语言的谜题 原文http://coolshell.cn/articles/945.html
2011-11-20 23:23 by Rollen Holt, 393 阅读, 收藏,
摘要:
这几天,本站推出了几篇关于C语言的很多文章如下所示:语言的歧义[酷壳链接] [CSDN链接]谁说C语言很简单?[酷壳链接] [CSDN链接]6个变态的C语言Hello World程序[酷壳链接] [CSDN链接]如何加密/弄乱C源代码[酷壳链接] [CSDN链接]C语言的谜题[酷壳链接] [CSDN链接]我们可以看到很多C语言相关的一些东西。比如《语言的歧义》主要告诉了大家C语言中你意想不到的错误以及一些歧义上的东西。而《谁说C语言很简单》则通过一些看似你从来不可能写出的代码来告诉大家C语言并不是一件容易事情。《6个变态的hello world》和《如何弄乱C的源代码》则以一种极端的方式告诉大 阅读全文