Friday, January 25, 2013

[Library] The useful libraries for C

Needless to say, C is powerful. But, if you use Java or Python, you will reconize that C lakes a bunch of Libraries(APIs) or a framework for C programmer to do job quicker. Sometimes you have to look for some C libraries to meet your requirement, and then you can avoid from carving the same wheels again and again. This document will record the useful libraries for C language and I will continue to add the new one on it. For those who are a great C programmer, if you know a good library for C, please also let me know that. Thanks in advance.

OGDF - Open Graph Drawing Framework
http://www.ogdf.net/ogdf.php

Curl Lib
the multiprotocol file transfer library
http://curl.haxx.se/libcurl/

mongoose
The lightweight web server in C
http://code.google.com/p/mongoose/

SimCList – A C library for Lists
http://mij.oltrelinux.com/devel/simclist/

JSON Library
http://www.digip.org/jansson/

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts
http://libevent.org/

libev - a high performance full-featured event loop written in C
It is similar with libevent, but is more efficiently
http://doc.dvgu.ru/devel/ev.html

The Better String Library
http://bstring.sourceforge.net/

Unit Test Frameworks
https://github.com/imb/fctx

Exception Handling for C
http://code.google.com/p/exceptions4c/

SSL Library
https://polarssl.org/ssl-library

libssh2 is a client-side C library implementing the SSH2 protocol
http://www.libssh2.org/

MD5
http://256.com/sources/md5/

CIDR Library ( Need to verify )
http://www.over-yonder.net/~fullermd/projects/libcidr 

NETCONF library in C
https://code.google.com/p/libnetconf/

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
http://www.sqlite.org/

Monday, January 21, 2013

[SDN] The news about Juniper to build its own software-defined networking stack

Software Defined Networking is becoming hotter and hotter topic from last year. Properly networking guys will talk about Software-defined Networking (SDN) everywhere this year. The event that VMware bought Nicira became a catalyst for some related Network Vendors to think about what the strategy and tactic they should have and deal with this wave of SDN. It let me think of this song ( Blondie – The Tide Is High )
  The tide is high but I'm holding on ...
   I'm gonna be your number one ...

   ...

In sum, SDN is important and key to survive this time in the networking world. Here is an example about that Juniper takes an action to provide their SDN approach. I excerpt some paragraph as follows:


Quota from the news:
http://www.theregister.co.uk/2013/01/16/juniper_sdn_strategy/

Juniper's approach to SDN, explained Muglia, will break the monolithic software stack inside of switches and routers – for campuses, branches, and service providers and not just for data centers – into four different planes: management, services, control, and forwarding.

This software will run on a virtualization layer called JunosV App Engine – which sounds a lot like a KVM hypervisor container for an x86 server, but Juniper did not say. This virtualization software will ship later in the first quarter of this year.

Central to that SDN stack is Contrail, a startup that was just getting ready to uncloak last month with its SDN wares when Juniper swept in with $176m in cash and snapped it up. Contrail was founded by a team of networking and software platform experts from Google, Juniper, Cisco, and Aruba Networks, and significantly had former Juniper CTO and chief architect Kireeti Kompella as its CTO. Now Kompella is back at Juniper, and is central to its SDN strategy.

Tuesday, January 8, 2013

[Signal] The examples of using alarm() and sigaction()

In the following URL, it provides a good explanation about signal and signal handling.
https://www.sharcnet.ca/help/index.php/Signal_Handling_and_Checkpointing

Handling signal is a important job when we want to write a great code.
There are several signal functions that we could use often in programming. I will give some examples of how to use alarm() and sigaction() functions as below.
P.S: the URL link is the orginal source code which is from.


The follwing two examples are about how to use alarm() and ualarm().
http://jyhshin.pixnet.net/blog/post/27749178-linux-%E8%A8%88%E6%99%82%E5%99%A8-alarm-signal-%281%29

/* Example of using alarm() */ #include <unistd.h> #include <stdio.h> #include <signal.h> int main(int argc, char *argv[]) { sigset_t block; sigemptyset(&block); sigaddset(&block, SIGALRM); sigprocmask(SIG_BLOCK, &block, NULL); while (1) { alarm(2); printf("%d\n", time(NULL)); sigwaitinfo(&block, NULL); } return 0; }


/* Example of using ualarm() */ #define _XOPEN_SOURCE 500 #include <unistd.h> #include <stdio.h> #include <signal.h> int main(int argc, char *argv[]) { sigset_t block; sigemptyset(&block); sigaddset(&block, SIGALRM); sigprocmask(SIG_BLOCK, &block, NULL); ualarm(500000, 500000); while (1) { printf("%d\n", time(NULL)); sigwaitinfo(&block, NULL); } return 0; }


Actually, sigaction() is widely used in handling signal, for instance, SIGINT (interrupt), SIGCHLD, and so on. Here are the examples to show the usage of sigaction with SIGINT.
http://www.linuxprogrammingblog.com/code-examples/sigaction

/* Example of using sigaction() to setup a signal handler with 3 arguments * including siginfo_t. */ #include <stdio.h> #include <unistd.h> #include <signal.h> #include <string.h> static void hdl (int sig, siginfo_t *siginfo, void *context) { printf ("Sending PID: %ld, UID: %ld\n", (long)siginfo->si_pid, (long)siginfo->si_uid); } int main (int argc, char *argv[]) { struct sigaction act; memset (&act, '\0', sizeof(act)); /* Use the sa_sigaction field because the handles has two additional parameters */ act.sa_sigaction = &hdl; /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */ act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &act, NULL) < 0) { perror ("sigaction error"); return 1; } while (1) sleep (10); return 0; }

http://fanqiang.chinaunix.net/a4/b2/20010508/113528_b.html

/* Example of using sigaction() to setup a signal handler * with setting sa_handler */ #include <stdio.h> #include <unistd.h> #include <signal.h> #include <string.h> #include <errno.h> #define PROMPT "Do you want to terminate the process?" char *prompt=PROMPT; void ctrl_c_oper(int signo) { write(STDERR_FILENO,prompt,strlen(prompt)); } int main() { struct sigaction act; act.sa_handler=ctrl_c_oper; sigemptyset(&act.sa_mask); act.sa_flags=0; if(sigaction(SIGINT,&act,NULL)<0) { fprintf(stderr,"Install Signal Action Error:%s\n\a",strerror(errno)); exit(1); } while(1); }