Get MAC address using C

不過 , 這邊有指定 eth0 , 若 server 有很多 interface 的話就要注意一下了. #include <stdio.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> int main( int argc, char *argv[] ) { int s; struct ifreq buffer; s = socket(PF_INET, SOCK_DGRAM, 0); memset(&buffer, 0x00, sizeof(buffer)); strcpy(buffer.ifr_name, "eth0"); ioctl(s, SIOCGIFHWADDR, &buffer); close(s); for( s = 0; s < 6; s++ … Read more


"C 語言" … ㄏㄏ.. 這麼古老且重要的語言,從 1972年開始到現在至少超過30年! 學會 pointer 後 C 就算是懂 90% 了 REF: FROM URL : TABLE OF CONTENTS Preface Introduction Chapter 1: What is a Pointer? Chapter 2: Pointer Types and Arrays. Chapter 3: Pointers and Strings Chapter 4: More on Strings Chapter 5: Pointers and Structures Chapter 6: More on … Read more

The Expat XML Parser – XML 分析/拆解工具 – C – 這個讚! 用 C 寫 spider 會用到

Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document (like start tags). An introductory article on using Expat is available on Function reference :

新的轉碼方法 , libiconv , BIG5 轉 UTF8

這段 code , 很好用, 就貼在這兒了, 下次可以直接剪下跟貼上 重點有兩個: 1. From encoding 是 CP950 2. libiconv 不要用 libc 的, 因為缺一個 function : iconvctl int fnConvert(const char *from, const char *to, char* save, int savelen, char *src, int srclen) { iconv_t cd; char *inbuf = src; char *outbuf = save; size_t outbufsize = savelen; int status = 0; … Read more

get my ip address useing c / sample code

C CODE /* FILENAME : my_local_ip.c */ #include #include #include #include #include #include #include #include int main(int argc, char **argv) { int s; struct sockaddr_in sin; int slen; int port; if( argc<3 ) { printf(“Usage: %s \n”, argv[0]); printf(“\n\tsample %s 80\n”,argv[0]); return -1; } port = atoi(argv[2]); s = socket(PF_INET, SOCK_STREAM, 0); memset(&sin, 0, … Read more

解決 error while loading shared libraries 的方法

執行程式時, 若遇到 ./update_item: error while loading shared libraries: cannot open shared object file: No such file or directory 像這樣的錯誤訊息 , 表示程式中所需的 so 檔(share library) 沒找到 , 要修改 /etc/ 加上這個目錄 , 改完要下 ldconfig –v 讓路徑生效 可以用 ldd 看該程式所使用到的 shared library 有那些, 及 lib 路徑 —– 以下是 gentoo 的標準解法 , 其他版本的 linux 則不太相同!! cat /etc/   … Read more