Pages

05 January 2016

Is someone tracking you - test your browser with Panopticlick

Are you serious if someone is tracking you? Do you care that you should not get tracked by someone?

EFF (Electronic Frontier Foundation) has launched a research project called Panopticlick. Recently EFF has also released version 2 of the project. All you have to do is to point you browser to panopticlick. You will see the window like this.


click on "TEST ME" button and it will perform the test required to check the browser. 


at the end of the test it will show the result.

Panopticlick does not stop at displaying result, it also suggest the add on which can be helpful to protect your browser from being tracked.


22 August 2011

How to get GMT offset of given Timezone.


    Calculating GMT offset of any timezone is a little bit tricky. I need to deal with this situation, in one of my project. I have written a small program.
    I have considered /usr/share/zoneinfo as default timezone directory. You need to change if you timezone files are located any where else. Your feedback are valuable for me.


#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

#define ABS(ent) (ent) = ((ent)>0?(ent):0-(ent))
#define TZ_DIR  "/usr/share/zoneinfo"

static void
display_gmt_off(long tz)
{
 int32_t hrs, min;

 hrs = tz/3600;
 min = tz % 3600;
 min = min/60;
 ABS(min);
 ABS(hrs);

 fprintf(stdout, "(GMT");
 if (tz < 0) {
  fprintf(stdout, "+");
 } else if (tz > 0) {
  fprintf(stdout, "-");
 }
 if (hrs > 0 || min > 0) {
  fprintf(stdout, "%d:%d", hrs, min);
 }
 fprintf(stdout, ")\n");
}

static int
invalid_timezone(const char *tz)
{
 char tzpath[1024];
 struct stat st;

 snprintf(tzpath, sizeof(tzpath), "%s/%s", TZ_DIR, tz);
 memset(&st, 0, sizeof(st));
 return stat(tzpath, &st);
}

int
main(int argc, char **argv)
{
 const char *tz;

 if (argc != 2) {
  fprintf(stderr, "Usage %s \n", basename(argv[0]));
  return 1;
 }
 tz = argv[1];

 if (invalid_timezone(tz)) {
  fprintf(stderr, "Invalid timezone %s\n", tz);
  return 1;
 }
 if (setenv("TZ", tz, 1) < 0) {
  fprintf(stderr, "Cannot set TZ(%s)\n", tz);
  return 1;
 }
 tzset();
 display_gmt_off(timezone); /* extern variable in time.h */
 return 0;
}

03 August 2011

C program to get Network interface name and index in linux

 In network programming, we often need to know the interface name(s) or index(es). I am talking about the interface index/name listed with "ifconfig -a" command. Suppose you need to know the index of the interface "eth1", what would you do? Traditional approach is open netlink socket to connect link subsystem. Frame the request to get interface index/name and write to socket and wait for reading. Read the response and extract necessary information.

If you need to know (1) just interface index from given interface name or vice versa (2) list of interface names/indexes, you do not need to write netlink socket code. You can use glibc functions to achieve this. Here I have written three sample programs, please review it. To get or track other information you need to go through netlink way.


/* This program will fetch interface name for given interface index */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;net/if.h&amp;gt;
#include &amp;lt;libgen.h&amp;gt;


int
main(int argc, char **argv)
{
unsigned int port_index;
char if_name[IFNAMSIZ];
if (argc != 2) {
fprintf(stderr, "Usage: %s &amp;lt;interface index&amp;gt;\n", basename(argv[0]));
return 1;
}
port_index = atoi(argv[1]);
if (if_indextoname(port_index, if_name) == NULL) {
fprintf(stderr, "Invalid interface index %d\n", port_index);
return 1;
}
fprintf(stdout, "Index is %d for interface %s\n", port_index, if_name);
return 0;
}


/* This program will fetch interface index of given interface name */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;net/if.h&amp;gt;
#include &amp;lt;libgen.h&amp;gt;


int
main(int argc, char **argv)
{
    unsigned int port_index;
    const char *if_name;
    if (argc != 2) {
        fprintf(stderr, "Usage: %s &amp;lt;interface name&amp;gt;\n", basename(argv[0]));
        return 1;
    }
    if_name = argv[1];
    if ((port_index = if_nametoindex(if_name)) == 0) {
        fprintf(stderr, "No index found for %s interface\n", if_name);
        return 1;
    }
    fprintf(stdout, "Index is %d for interface %s\n", port_index, if_name);
    return 0;
}


/* Ths program will fetch list of indexes of interfaces */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;net/if.h&amp;gt;
#include &amp;lt;libgen.h&amp;gt;


int
main(void)
{
    register int i;
    struct if_nameindex *ids;


    ids = if_nameindex();
    for (i=0; ids[i].if_index != 0; i++) {
        printf("%d = %s\n", ids[i].if_index, ids[i].if_name);
    }
    /* Do not forget to free the memory */
    if_freenameindex(ids);
    return 0;
}



Please put comments if you enjoy the article.