Tool: IP Packet Sniffer

May 30, 2009 | Filed Under Tools | No Comments

Today I’ve implemented a simple IP Packet Sniffer.

IP Packet Sniffer

IP Sniffer TCP Data Viewipsniffer-2Sometimes is useful to know what’re the IP packages that transit on your network, for Analyze network problems, Monitor network usage, Debug client/server communications or Debug network protocol implementations.

The tool is very simple, but I think that can be useful to learn something more about IP and TCP packets and Protocols implementation.

Maybe you can extend this Tool to support other Transport Layer Protocol.

Note: You need to run it as Root.

You can find the Source Code Here: IP Packet Sniffer Source Code.

Qt4 Jump Away Animation

May 16, 2009 | Filed Under Qt4 | No Comments

When I’ve started working on Mac OS X with Core Animation, I was impressed by an Example (I don’t remember the link, if someone knows it, post it in the comments! thanks)… Very few lines of code for a great effect.

After a year, or probably more.. this example was came back to my mind, so I’ve decided to clone using Qt. And below you can see a short Demonstration Video. Your desktop jump away.. full screen is fantastic :)

The Source Code is Available Here: Qt4 Jump Away Animation Source Code.

PyQt4: PyCon3 Photos on Flickr

May 16, 2009 | Filed Under Events, Qt4 | No Comments

PyCon3 was finished, Only one week is passed and I already miss it. Guido van Rossum, Alex Martelli, Ariya Hidayat, Raymond Hettinger, David Boddie, Fredrik Lundh… C/C++ and Python Developer not .NET “coders” (I hate even more my boring .NET job).

Following the PyCon week, here a simple example of PyQt4 that allows you to see up to 500 photos tagged PyCon3 on Flickr.

PyQt4 PyCon3 Flickr

As always the source code is available here: PyQt4 PyCon3 Flickr Source Code.

[TIP] Non Blocking C Read

May 11, 2009 | Filed Under Tips | No Comments

This is Just a simple code that maybe all the Linux C Developer knows, but if someone is still learning, This is a function that wrap the standard read function adding the non blocking feature. It’s Really useful in relation with Sockets.

int nonblock_read (int fd, char *buffer, size_t bufsize, int timeout) {
  if (timeout > 0) {
    struct timeval tv;
    fd_set rfds;

    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);

    tv.tv_sec = 0;
    tv.tv_usec = timeout * 1000;

    if (select(1, &rfds, NULL, NULL, &tv) <= 0)
      return(-ETIME);
  }

  return(read(fd, buffer, bufsize));
}

PyCon3 Italia, 8-9-10 May 2009

May 8, 2009 | Filed Under Events | No Comments


pycontre-logo

I will spend the next few days in FlorenceĀ for PyCon. Probably on Monday, I’ll publish some photos and why not, code examples from PyCon.

See you there!

Qt4 Touch and Rotate

May 7, 2009 | Filed Under Qt4 | No Comments

Alan has asked my How I’ve implemented the Touch and Rotate feature of the Moko. The answer is very simple, It’s all Magic! There’re very few lines of code to do it, because all the magic is made by atan2.

Atan2 is a variation of the arctangent function. For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.

Qt Touch and Rotate

The Source Code is available here: Qt4 Touch and Rotate Source Code.

OT: PyCon3 (Italia) starts Tomorrow!

Qt4 JSON Stream Reader

May 2, 2009 | Filed Under Qt4 | No Comments

JSON, short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects).

One way to use JSON with Qt4 is using the QScriptEngine (engine.Evaluate(jsonSource)), But I like Reinventing the wheel, so I’ve written a simple JSON Stream Reader that works “almost” like the QXmlStreamReader.

You’ve a readNext() method that read the next token and returns its type, and two properties name() and values() that Returns the name of the Property, Object or Array and the Value of the Property in a QVariant that can be Bool, Int, Double or String.

Below there’s an Example of How to use the JSON Stream Reader. Maybe you can use it to create an automatic Object Mapper like the Xml Object Mapper that I’ve posted a couple of weeks ago.

QFile file("test.json");
if (!file.open(QIODevice::ReadOnly)) {
   qDebug() << file.errorString();
   return(1);
}

THJsonStreamReader reader(&file);
while (!reader.atEnd()) {
   switch (reader.readNext()) {
      case THJsonStreamReader::PropertyNumerical:
         qDebug() << " - Property Numerical" << reader.name() << reader.value();
         break;
      case THJsonStreamReader::PropertyString:
         qDebug() << " - Property String" << reader.name() << reader.value();
         break;
      case THJsonStreamReader::PropertyFalse:
         qDebug() << " - Property False" << reader.name() << reader.value();
         break;
      case THJsonStreamReader::PropertyTrue:
         qDebug() << " - Property True" << reader.name() << reader.value();
         break;
      case THJsonStreamReader::PropertyNull:
         qDebug() << " - Property Null" << reader.name();
         break;
      case THJsonStreamReader::Object:
         qDebug() << "Object" << reader.name();
         break;
      case THJsonStreamReader::ObjectEnd:
         qDebug() << "Object End";
         break;
      case THJsonStreamReader::Array:
         qDebug() << "Array" << reader.name();
         break;
      case THJsonStreamReader::ArrayEnd:
         qDebug() << "Array End";
         break;
   }
}

file.close();

The Source Code is Available Here: Qt4 JSON Stream Reader Source Code.

Qt4 Google Authentication

May 1, 2009 | Filed Under Qt4 | 1 Comment

Today, I’m looking at Google services, Contacts, Maps, Search… to use all this service in your app you need to get The Authentication Token (see the Google Auth For Installed Apps page). So, I’ve implemented a simple class to do this.

QEventLoop q;
THGoogleAuth gAuth("MYNAME@gmail.com");
QObject::connect(&gAuth, SIGNAL(authenticated()), &q, SLOT(quit()));
gAuth.login(THGoogleAuth::Contacts, "MYPASSWORD");
q.exec();

if (gAuth.error() == THGoogleAuth::NoError) {
    qDebug() << "SID" << gAuth.sid();
    qDebug() << "LSID" << gAuth.lsid();
    qDebug() << "AUTH" << gAuth.auth();
} else {
    qDebug() << gAuth.errorString();
}

The Source Code is Available Here: Qt4 Google Auth Source Code.

Next Page »