Don’t know how to install package on Mac?

In linux like ubuntu, we can simply type
sudo apt-get install [package-name]
to installs packages.

But in Mac OS X… there is no apt-get 🙁

Most of time I do download the source code and compile by myself because I am a geek 🙂
However, sometimes I have no time to debug the errors generated by the compiler and the problem of software dependency…

So guess what? Macports! If you are worried to install packages, macports is your friend. It does the same thing as apt-get and more powerful.

For example, I want to install mscgen, just type
sudo port install mscgen
and…that’s it. Macports will check the dependency and install all related packages including mscgen for you.

Here is the official site: http://www.macports.org/

Re-writing all the codes!!!

We have decided that the Newsfeeder we are developing is a service selling to the customers, not a single product. Actually, we are not selling the whole system to a normal user.

Hence, we can install many existing modules/parts on the server side to improve the developing speed. For example: We can use boost::thread instead of simple pthread, etc. Assuming there is no bugs in those wrappers and libraries provided by the official sites (e.g. mysql), we could have no tests on those modules.

So I decide to re-write all the code in the back-end of the Newsfeeder.
Re-manage the whole directory, and add documentation stuffs using Doxygen (I will try to integrate it with X-code).

Unix domain socket

Refer to http://en.wikipedia.org/wiki/Unix_domain_socket (For personal research)

A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing within the same host operating system. While similar in functionality to named pipes, Unix domain sockets may be created as byte streams or as datagram sequences, while pipes are byte streams only. Processes using Unix domain sockets do not need to share a common ancestry. The programmer’s application interface (API) for Unix domain sockets is similar to that of an Internet socket, but does not use an underlying network protocol for communication. The Unix domain socket facility is a standard component of POSIX operating systems.

Unix domain sockets use the file system as address name space. They are referenced by processes as inodes in the file system. This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel.

In addition to sending data, processes may send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

Extra: unix domain sockets guide

Limit the number of connections(限制连接数)

I hate people using P2P downloaders to eat up the whole network access.
As I have the root access of the router (easy to hack), I add some rules to limit it.

iptables -I FORWARD -p tcp --syn -m connlimit --connlimit-above 30 -j DROP
iptables -I FORWARD -p! tcp -m connlimit --connlimit-above 30 -j DROP

First line is to limit tcp connections to 30 per ip.
Second line is to limit non-tcp connections to 30 per ip.

Here is Chinese version:
限制连接数以防止P2P下载器例如迅雷、电驴、BT及P2P播放器例如PPS、PPLive、风行等。
以下为在路由器上执行的代码(通过telnet连接)

iptables -I FORWARD -p tcp --syn -m connlimit --connlimit-above 30 -j DROP
iptables -I FORWARD -p! tcp -m connlimit --connlimit-above 30 -j DROP

第一行为限制tcp连接数到30个每ip。
第二行为限制非tcp连接数到30个每ip。

A bash script to monitor and log a CLI application

I am doing Java this session and have done my assignment 4 for socket practices.

The assignment contains 2 parts: Client and server.

I can’t modify the assignment to have proper log details (e.g. add time to logs) because it will lose marks 🙁

So, I did a bash script named “run”.

#!/bin/bash
# Author name: Need-Being
# Modification date: 14/10/2011
trap "" SIGHUP
cd Server
java JavaQuizServer 2>&1 | while read LINE
do
        echo "`date '+[20%y/%m/%d-%T]'`[java] $LINE" >> ../JavaQuiz.log
done

“java JavaQuizServer” is the line to execute the program. I add the time before whatever it output and send it to “JavaQuiz.log”
‘trap “” SIGHUP’ is used for ignore signal SIGUP that it can be alive after closing it parent process i.e. ssh.
Continue reading A bash script to monitor and log a CLI application

Someone is attacking me…

Someone is attacking me via ssh from 4 hours ago.
I just post here to warning you.

Oct  4 22:31:07 localhost sshd[11172]: Failed password for root from 59.151.19.47 port 36029 ssh2   
Oct  4 22:31:09 localhost sshd[11174]: Failed password for invalid user lydia from 219.254.35.83 por
t 56406 ssh2                                                                                        
Oct  4 22:31:09 localhost sshd[11176]: pam_unix(sshd:auth): authentication failure; logname= uid=0 e
uid=0 tty=ssh ruser= rhost=59.151.19.47  user=root                                                  
Oct  4 22:31:11 localhost sshd[11178]: Invalid user magda from 219.254.35.83                        
Oct  4 22:31:11 localhost sshd[11178]: pam_unix(sshd:auth): check pass; user unknown                
Oct  4 22:31:11 localhost sshd[11178]: pam_unix(sshd:auth): authentication failure; logname= uid=0 e
uid=0 tty=ssh ruser= rhost=219.254.35.83                                                            
Oct  4 22:31:12 localhost sshd[11176]: Failed password for root from 59.151.19.47 port 36142 ssh2   
Oct  4 22:31:13 localhost sshd[11178]: Failed password for invalid user magda from 219.254.35.83 por
t 56624 ssh2                

Above are the logs.
If you keep attacking, you are liable for this.

59.151.19.47 From China
219.254.35.83 From Korea

To defend this DoS attack, related software has been set up 🙂
Good Job, Need-Being!

Some functionalities in STL is missing using CC

If you trying to compile source code, having some STL used, with CC in SunOS. You may fail.

For example:
If you use std::list::sort() in, you will get following error like this one:

Error: Could not find a match for std::list::sort(bool(int,int))

This happens because CC is using the old libCstd .

Continue reading Some functionalities in STL is missing using CC