Posts Tagged ‘linux’

The long awaited migration from Qmail to Postfix

I’ve been running qmail based mail servers for years. And you can imagine how many if I am planning this migration from at least 3 years. To be very honest qmail does a very very good job. This is the reason it took so much time to actually do it. In fact qmail has only one problem: it’s stuck in the past. If you want to install something new: say SPF of DKIM you need to patch, recompile. And who would want to do that when it has such a perfect install running for so much time untouched ? Of course if you are ready to make this step then you are probably know you don’t want to do that any time soon so maybe it’s better to install something else. Say postfix? But what about this nice install, and the migration? This is the thinking which took so much time for me and it was only after doing the hardy to lucid upgrade that I decided to be bold enough to do it :) (more…)

Status RSS plugin for pidgin

As a pidgin user I am used at not expecting many fancy things but one of the features I’ve wished for some time is a plugin which updates the status automatically to the last entry in a RSS feed. As an example I’d like to update the status to the last post on my blog. So, even if I don’t like perl too much here is a simple plugin which does just that. It’s inspirationaly called: Status RSS :)

(more…)

Tethered capture with ubuntu and D450

Shooting a photo and the imediately seeing it on a large monitor is a feature I’ve always wished. I don’t say live view on a display but instant copy and display would suffice. And actually, as I found out, it’s quite easy to achieve on Ubuntu Linux (10.04) with a Canon D450. (more…)

Programmatically get the MAC address in C

This is a small example on how you can get the MAC address in C both in Linux and Windows. The example searches in fact the MAC address corresponding to a given IP address and returns it.

/*
 * mac.cpp
 *  Created on: May 25, 2010
 *      Author: len
 */

#ifdef WIN32

#include <stdio.h>
#include <Windows.h>
#include <Iphlpapi.h>
#include <Assert.h>
#pragma comment(lib, "iphlpapi.lib")

/**
 * @return the mac address of the interface with the given ip
 */
char* getMAC(const char *ip){
 PIP_ADAPTER_INFO AdapterInfo;
 DWORD dwBufLen = sizeof(AdapterInfo);
 char *mac_addr = (char*)malloc(17);

 AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
 if (AdapterInfo == NULL) {
 printf("Error allocating memory needed to call GetAdaptersinfo\n");
 return NULL;
 }

 // Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable
 if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
 FREE(AdapterInfo);
 AdapterInfo = (IP_ADAPTER_INFO *) malloc(dwBufLen);
 if (AdapterInfo == NULL) {
 printf("Error allocating memory needed to call GetAdaptersinfo\n");
 return NULL;
 }
 }

 if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) {
 PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
 do {
 sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
 pAdapterInfo->Address[0], pAdapterInfo->Address[1],
 pAdapterInfo->Address[2], pAdapterInfo->Address[3],
 pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
 printf("Address: %s, mac: %s", pAdapterInfo->IpAddressList.IpAddress.String, mac_addr);
 if(strcmp(ip, pAdapterInfo->IpAddressList.IpAddress.String) == 0){
 printf(" matches\n");
 free(AdapterInfo);
 return mac_addr;
 }
 printf("\n");
 pAdapterInfo = pAdapterInfo->Next;        
 }while(pAdapterInfo);                        
 }
 free(AdapterInfo);
 return NULL;
}
#endif

#ifdef linux
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/**
 * @return the mac address of the interface with the given ip
 */
char *getMAC(const char *ip){
 struct ifaddrs *ifaddr, *ifa;
 int family, s;
 char host[NI_MAXHOST];
 struct sockaddr *sdl;
 unsigned char *ptr;
 char *ifa_name;
 char *mac_addr = (char*)calloc(sizeof(char), 18);

 if (getifaddrs(&ifaddr) == -1) {
 perror("getifaddrs");
 return NULL;
 }

 //iterate to find interface name for given server_ip
 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
 if (ifa->ifa_addr != NULL){
 family = ifa->ifa_addr->sa_family;
 if(family == AF_INET){
 s = getnameinfo(ifa->ifa_addr, (family == AF_INET)?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6),
 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
 if (s != 0) {
 printf("getnameinfo() failed: %s\n", gai_strerror(s));
 return NULL;
 }
 printf("address: %s\n", host);
 if(strcmp(host, ip) == 0){
 ifa_name = ifa->ifa_name;
 printf("matching interface name: %s\n", ifa_name);
 }
 }
 }
 }

 //iterate to find corresponding ethernet address
 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
 family = ifa->ifa_addr->sa_family;
 if(family == PF_PACKET && strcmp(ifa_name, ifa->ifa_name) == 0){
 sdl = (struct sockaddr *)(ifa->ifa_addr);
 ptr = (unsigned char *)sdl->sa_data;
 ptr += 10;
 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5));
 printf("found mac address: %s\n", mac_addr);
 break;
 }
 }
 freeifaddrs(ifaddr);
 return mac_addr;
}
#endif

int main(int argc, char *argv[]){
 char *mac = getMAC(argv[1]);
 if(mac != NULL){
 printf("mac: %s\n", mac);
 }
 return 0;
}

This example mixes various informations found on the net. The windows version is based on this example. In order to compile this example under windows you need to disable the precompiled headers (tested in VC express 2008). The linux version just iterates interfaces and matches the name of the PF_PACKET (ethernet) with AF_INET (TCP) in order to find the mac of a given ip.

Holux M-241 GPS

Read track via USB

gpsbabel -t -w  -i m241 -f /dev/ttyUSB0 -o gpx -F test.gpx

(more…)

Ubuntu Lucid Lynx

There was not much I expected from the new ubuntu Lucid Lynx as I was happy enough with the existing version already. But I a good tradition and because I woke up at 8:30 this Saturday I decided to go ahead and install it on my Dell D820.

The install

The install went smoothly, everything was detected, installed the upgrades, the nvidia drivers and some day to day packages: mozilla-thunderbird, pidgin, emacs.

(more…)

Linux encrypted file(system)

Searching for a way to encrypt your files or filesystem on Linux can be an overwhelming choice. At a simple search you find different terms and solutions such as: encfs, dm-crypt, truecrypt, loopback crypt, aespipe, LUKS, etc. The answer is obviously historical. There are a lot of solutions some of them deprecated. I remember a few years ago I solved a similar problem using a tool (can’t remember which) which I was unable to find 2 years later thus remaining with a large file and lost data. Here is a method to encrypt a filesystem or file using LUKS. (more…)

Karmic various tricks

Logout messages

If you are opening a terminal to a different server or do a su in a terminal then on logout you will be required to enter your password in order to confirm the logout action. Since the polkit-gnome-authorization does not work with the new polkit version which ships with ubuntu and the polkit-auth command does not seems to work either I’ve found after some research that the solution resides in editing the /usr/share/polkit-1/actions/org.freedesktop.consolekit.policy file as follows: (more…)

Sony Ericsson C510

Apparently a cup of tea more bad than good in preventing the AH1N1 flu for my old phone which completely died (drowned) as of the procedure. In conclusion I had to choose fast and I did choose the best of the worst which was the single phone with no opening parts, relatively squared buttons and almost free for my operator. Since I see the phone as a basic tool which does not need much else than the ability to make a call this is most reasonable. I will probably break it, scratch it, drop it in dirt or on the stairs so I really don’t need another expensive gadget to take care of. The result was the C510 which I hopped to work in Linux (Ubuntu 9.10 Karmik Koala) as good as it’s predecessor. Here is a short check list: (more…)

Changing dates format in Thunderbird

Since my migration to thunderbird I did not had many things to complain but one of the remaining things was the date format. I am expecting to have something like DD/MM/YY or at least DD MMM YYYY. I did not imagined this could be something else than configuration somewhere. Or not…

After some digging I found out there is no way to configure the date string but the only way to change the date is to change the locale the application is using. The first step was to see the installed locales:

locale -a
C
en_AG
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_NG
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX

then to check each locale date format, for example:

len@black:~$ LC_ALL=en_DK.utf8 locale -k d_fmt t_fmt
d_fmt="%Y-%m-%d"
t_fmt="%T"
len@black:~$ LC_ALL=en_GB.utf8 locale -k d_fmt t_fmt
d_fmt="%d/%m/%y"
t_fmt="%T"

the remaining thing was to convince thunderbird to use this locale. I’ve done this by creating /usr/bin/mythunderbird script:

LC_ALL=en_GB.utf8 $(dirname $0)/thunderbird

now the dates are much better:

Thunderbird dates config

Thunderbird dates config

Related Posts with Thumbnails