For some reason today I began browsing for physics engine for Iphone. JIC I get an idea to develop a game kinds...
Chipmunk and cocos2d interested me.
Did a bit of googling and cocos2d really simple. I found this great youtube channel with some useful cocos2d tutorial. I'll play around with cocos2d for a while and then probably look in to chimpmunk.
Friday, October 22, 2010
Sunday, August 15, 2010
Friday, August 6, 2010
Validating Shell Script Arguments...
Following are the few links that helped me to validating shell script arguments.
http://aplawrence.com/Unix/getopts.html
http://wiki.bash-hackers.org/scripting/posparams
http://www.faqs.org/docs/air/tsshell.html
http://aplawrence.com/Unix/getopts.html
http://wiki.bash-hackers.org/scripting/posparams
http://www.faqs.org/docs/air/tsshell.html
Tuesday, August 3, 2010
CMake on OSX
Here I create my first CMakeList for OSX to create a library
It was bit of a struggle to get to this point because the cmake documentation is very bad I felt..
http://www.cmake.org/Wiki/CMake_Cross_Compiling
http://www.cmake.org/cmake/help/cmake2.6docs.html
Following couple of link came to my rescue.
http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/cross-compile-for-the-iphone/how-to-cross-compile-for-the-iphone-using-cmake
http://stackoverflow.com/questions/794137/how-to-set-up-cmake-to-build-a-library-for-the-iphone
cmake_minimum_required(VERSION 2.6)
project (cmakeTest)
set(PROJECT_ROOT $ENV{PROJECT_ROOT})
set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX10.5.sdk)
set(CMAKE_OSX_ARCHITECTURES "i386")
SET(CMAKE_AR ar)
add_definitions( -Wall )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ./CMAKE_build)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ./CMAKE_build/bin)
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ./CMAKE_build/bin)
include_directories(${PLUGIN_ROOT}/cmakeTest/API)
add_definitions(-DMACOSX)
add_library(cmakeTest STATIC
${PROJECT_ROOT}/cmakeTest/src/File1.cpp
${PROJECT_ROOT}/cmakeTest/src/File2.cpp
${PROJECT_ROOT}/cmakeTest/src/File3.cpp
${PROJECT_ROOT}/cmakeTest/src/File4.cpp
${PROJECT_ROOT}/cmakeTest/src/File5.cpp)
It was bit of a struggle to get to this point because the cmake documentation is very bad I felt..
http://www.cmake.org/Wiki/CMake_Cross_Compiling
http://www.cmake.org/cmake/help/cmake2.6docs.html
Following couple of link came to my rescue.
http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/cross-compile-for-the-iphone/how-to-cross-compile-for-the-iphone-using-cmake
http://stackoverflow.com/questions/794137/how-to-set-up-cmake-to-build-a-library-for-the-iphone
Tuesday, July 20, 2010
Perl : Tutorials
Following link points to a neat perl tutorial..
http://www.comp.leeds.ac.uk/Perl/
Some more links of String matching/replacements using perl:
http://www.htmlite.com/perl025c.php
http://www.troubleshooters.com/codecorn/littperl/perlreg.htm
Some more links of String matching/replacements using perl:
http://www.htmlite.com/perl025c.php
http://www.troubleshooters.com/codecorn/littperl/perlreg.htm
Wednesday, July 7, 2010
Animating NSViews and NSWindows
Following is a neat article on how to animate, NSWindows and NSViews using core-animation.
http://www.informit.com/articles/article.aspx?p=1431312&seqNum=3
http://www.informit.com/articles/article.aspx?p=1431312&seqNum=3
Monday, May 17, 2010
No Safari Plugins on iPad
Do not bother developing Safari plugin on iPhone or iPad. Detect the user agent and re-direct to the plugin disabled page.
Apple Tech Note
Apple Tech Note
Tuesday, March 30, 2010
Berkely Packet Filters
I had to implement a feature to list down all the free IP addresses available on a given subnet. Theoretically ICMP orARP protocols could be used to do this, I chose ARP as it exactly fits my bill.
How to implement was not really clear ? I piped in data from arp command to my application, so that application development does not stop because of this. However this is not at all a good way, this forks a new process which is a bloody costly in my application context. One more thing is that arp command looks up the arp tables and does not send an arp packet to check the existence of an IP. Anyways that was make shift arrangement till I implement it the right way.
The main problem was that the ARP works at the data link layer and not on the transport layer. To implement I'll need to send link layer raw packets. Using any transport layer protocols will not serve the purpose. I banged my head for couple of days. Then I found my savior Berkley Packet Filters (bpf).
Any Unix like Operating systems will have some bpf devices. My Mac has 4 bpf devices. Using bpf we can send raw ethernet packets, with out the need of any transport layer protocol. However to receive the response from these raw ethernet packets, a packet sniffer needs to be implemented. Mac OSX ships libpcap (lib packet capture), I used this to create a packet sniffer.
Packet sniffer was capturing all kind of packets, just realized the amount of communication goes on, in the background. libcap allows applications to add filters I had to apply an filter to capture only ARP packets.
ARP implementation solved 2 of my problems.
- finding a list of free IP addresses on a given subnet
- finding Mac-address of the gateway on that subnet.
How to implement was not really clear ? I piped in data from arp command to my application, so that application development does not stop because of this. However this is not at all a good way, this forks a new process which is a bloody costly in my application context. One more thing is that arp command looks up the arp tables and does not send an arp packet to check the existence of an IP. Anyways that was make shift arrangement till I implement it the right way.
The main problem was that the ARP works at the data link layer and not on the transport layer. To implement I'll need to send link layer raw packets. Using any transport layer protocols will not serve the purpose. I banged my head for couple of days. Then I found my savior Berkley Packet Filters (bpf).
Any Unix like Operating systems will have some bpf devices. My Mac has 4 bpf devices. Using bpf we can send raw ethernet packets, with out the need of any transport layer protocol. However to receive the response from these raw ethernet packets, a packet sniffer needs to be implemented. Mac OSX ships libpcap (lib packet capture), I used this to create a packet sniffer.
Packet sniffer was capturing all kind of packets, just realized the amount of communication goes on, in the background. libcap allows applications to add filters I had to apply an filter to capture only ARP packets.
ARP implementation solved 2 of my problems.
- finding a list of free IP addresses on a given subnet
- finding Mac-address of the gateway on that subnet.
Monday, March 8, 2010
libz inflate and deflate samples
Following link points to sample code to inflate (zip) and deflate (unzip) using libz library.
BRL-CAD/src/other/libz/examples/zpipe.c
BRL-CAD/src/other/libz/examples/zpipe.c
Thursday, February 18, 2010
tracing routing table...
found a piece of code to parse through routing tables...
http://www.mail-archive.com/freebsd-net@freebsd.org/msg09484.html
http://www.mail-archive.com/freebsd-net@freebsd.org/msg09484.html
Friday, February 12, 2010
Network Adapter Dilemma
I was for a long time, stuck with a problem of enumerating the available network adapters on my Mac and identifying the active adapter or say finding the default adapter.
I had an alternate way of doing this by piping the output of the
After a bit of struggling to find right
The job is now half done. I need to find active adapters,for this I need to get the IP address and Subnet mask assigned to the network adapter. Only active network adapters will have a valid IP and subnet mask assigned.
Thats a uncomplicated job
I had an alternate way of doing this by piping the output of the
"netstat -r -n | grep default" into my application actually. However better way to do this is through code, considering the performance benchmarks the application had to meet. After a bit of struggling to find right
mib values for sysctl using the following code I was able to enumerate the network adapters.
int
findNetworkAdapters
{
int mib[6];
size_t bufferSize = 0;
uint8_t *buffer = NULL, *nextChunk = NULL;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
mib[5] = 0;
if (sysctl(mib, 6, NULL, &bufferSize, NULL, 0) != 0)
return -1;
buffer = new uint8_t[bufferSize];
if (buffer != NULL)
{
if (sysctl(mib, 6, buffer, &bufferSize, NULL, 0) == 0)
{
struct if_msghdr *interface = (struct if_msghdr*)buffer;
for ( nextChunk = buffer;
nextChunk != buffer + bufferSize; nextChunk = nextChunk + interface->ifm_msglen)
{
interface = (struct if_msghdr*)nextChunk;
if (interface->ifm_type == RTM_IFINFO)
{
struct sockaddr_dl *link = (struct sockaddr_dl*)(interface + 1);
if (link->sdl_type == IFT_ETHER)
{
std::string name = (link->sdl_data);
printf("Interface : %s\n", name.c_str());
struct ether_addr hwaddr;
memcpy ((void*)&hwaddr, LLADDR(link), ETHER_ADDR_LEN);
printf("HW address : %x:%x:%x:%x:%x:%x\n", hwaddr.octet[0], hwaddr.octet[1], hwaddr.octet[2], hwaddr.octet[3], hwaddr.octet[4], hwaddr.octet[5]);
findIPAddress(name.c_str());
findSubnetMask(name.c_str());
printf ("\n");
}
}
}
}
free buffer;
}
return 1;
}
The job is now half done. I need to find active adapters,for this I need to get the IP address and Subnet mask assigned to the network adapter. Only active network adapters will have a valid IP and subnet mask assigned.
Thats a uncomplicated job
ioctl the socket and wallah !! I got the IP and subnet mask. Based on IP and subnet mask I could easily identify the active network adapters.
int
findIPAddress(const char* iName)
{
struct ifreq req;
struct sockaddr_in *sin;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
memset((void*)&req, 0, sizeof(struct ifreq));
strcpy(req.ifr_name, iName);
if (ioctl(fd, SIOCGIFADDR, (char *)&req) == -1)
{
printf("Error : %s\n", strerror(errno));
close(fd);
return -1;
}
sin = (struct sockaddr_in*)(&(req.ifr_addr));
printf("IP : %s\n", inet_ntoa(sin->sin_addr));
close(fd);
return 1;
}
int
findSubnetMask(const char* iName)
{
struct ifreq req;
struct sockaddr_in *sin;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
memset((void*)&req, 0, sizeof(struct ifreq));
strcpy(req.ifr_name, iName);
if (ioctl(fd, SIOCGIFNETMASK, (char *)&req) == -1)
{
printf("Error : %s\n", strerror(errno));
close(fd);
return -1;
}
sin = (struct sockaddr_in*)(&(req.ifr_addr));
printf("Subnet Mask : %s\n", inet_ntoa(sin->sin_addr));
close(fd);
return 1;
}
Wednesday, January 13, 2010
Head-Start in Python
Wanna learn Python ? Following link points to a great way of learning Python.
http://inventwithpython.com/chapters/
Learning Python using games... a good way I feel...
http://inventwithpython.com/chapters/
Learning Python using games... a good way I feel...
Subscribe to:
Posts (Atom)