http://news.slashdot.org/story/11/07/30/2046206/Whats-Needed-For-Freedom-In-the-Cloud
This was Intended to be a BSD only blog, but now it's about all Unix Like Free Operating Systems, Linux, FreeBSD etc.
Sunday, July 31, 2011
Friday, July 29, 2011
user-space-ip.c
Currently it arp's and ping's and can send and receive UDP, which is fine for RTP based video and audio.
I wanted to setup some user space TCP/IP stack like Apline or LWIP and make a web server,
The MAC address is hard coded.
The network card in put promiscuous mode so DO NOT RUN THIS ON A HEAVILY LOADED SERVER.
It uses raw sockets so it must run as root.
It's only been tested on Linux.
#include
#include
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/in.h>
#include <linux/ip.h>
// #include
#include <linux/icmp.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
// Evil Globals
/*our MAC address*/
unsigned char src_mac[6] = { 0x00, 0x0c, 0xf1, 0x75, 0xf8, 0xaa }; // Bogus
unsigned char src_ip[4] = { 192, 168, 0, 88 }; // Bogus
/*other host MAC address*/
unsigned char bcast_mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; //Broadcast
unsigned char dest_mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; //Broadcast
unsigned char dest_ip[4] = { 255, 255, 255, 255 }; // Bogus
unsigned char arp_query_ip[4] = { 192, 168, 0, 16 }; // Bogus
u_int16_t
csum_partial (void *buffer, unsigned int len, u_int16_t prevsum)
{
u_int32_t sum = 0;
u_int16_t *ptr = buffer;
while (len > 1)
{
sum += *ptr++;
len -= 2;
}
if (len)
sokol@server:~$
sokol@server:~$
sokol@server:~$
sokol@server:~$ cat user-space-ip.c
#include
#include
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/in.h>
#include <linux/ip.h>
// #include
#include <linux/icmp.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
// Evil Globals
/*our MAC address*/
unsigned char src_mac[6] = { 0x00, 0x0c, 0xf1, 0x75, 0xf8, 0xaa }; // Bogus
unsigned char src_ip[4] = { 192, 168, 0, 88 }; // Bogus
/*other host MAC address*/
unsigned char bcast_mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; //Broadcast
unsigned char dest_mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; //Broadcast
unsigned char dest_ip[4] = { 255, 255, 255, 255 }; // Bogus
unsigned char arp_query_ip[4] = { 192, 168, 0, 16 }; // Bogus
u_int16_t
csum_partial (void *buffer, unsigned int len, u_int16_t prevsum)
{
u_int32_t sum = 0;
u_int16_t *ptr = buffer;
while (len > 1)
{
sum += *ptr++;
len -= 2;
}
if (len)
{
union
{
u_int8_t byte;
u_int16_t wyde;
} odd;
odd.wyde = 0;
odd.byte = *((u_int8_t *) ptr);
sum += odd.wyde;
}
sum = (sum >> 16) + (sum & 0xFFFF);
sum += prevsum;
return (sum + (sum >> 16));
}
void
sendpack (int sock)
{
struct sockaddr_ll socket_address; /*target address */
void *buffer = (void *) malloc (ETH_FRAME_LEN); /*buffer for ethernet frame */
unsigned char *etherhead = buffer; /*pointer to ethenet header */
struct ethhdr *eh = (struct ethhdr *) etherhead; /*another pointer to ethernet header */
unsigned char *data = buffer + 14; /*userdata in ethernet frame */
int send_result = 0;
/*prepare sockaddr_ll*/
/*RAW communication*/
socket_address.sll_family = PF_PACKET;
/*we don't use a protocoll above ethernet layer ->just use anything here*/
socket_address.sll_protocol = htons (ETH_P_ALL);
/*index of the network device see full code later how to retrieve it*/
socket_address.sll_ifindex = if_nametoindex ("eth0");
printf ("if index for eth0 = %d\n", if_nametoindex ("eth0"));
/*ARP hardware identifier is ethernet*/
socket_address.sll_hatype = ARPHRD_ETHER; // for recv only
/*target is another host*/
socket_address.sll_pkttype = PACKET_BROADCAST; // for recv only
/*address length*/
socket_address.sll_halen = ETH_ALEN;
/*MAC - begin*/
socket_address.sll_addr[0] = 0x00;
socket_address.sll_addr[1] = 0x00;
socket_address.sll_addr[2] = 0x00;
socket_address.sll_addr[3] = 0x00;
socket_address.sll_addr[4] = 0x00;
socket_address.sll_addr[5] = 0x00;
/*MAC - end*/
socket_address.sll_addr[6] = 0x00; /*not used */
socket_address.sll_addr[7] = 0x00; /*not used */
memcpy ((void *) socket_address.sll_addr, (void *) dest_mac, ETH_ALEN);
/*set the frame header*/
memcpy ((void *) buffer, (void *) dest_mac, ETH_ALEN);
memcpy ((void *) (buffer + ETH_ALEN), (void *) src_mac, ETHALEN);
eh->h_proto = htons (ETH_P_ARP);
data[0] = 0;
data[1] = 1; // Hardware Type Ethernet
data[2] = 8;
data[3] = 0; // Protocol IP
data[4] = 6;
data[5] = 4; // Hardware size 6, protocol size 4
data[6] = 0;
data[7] = 1; // Opcode Request
memcpy ((void *) &data[8], (void *) src_mac, ETH_ALEN);
memcpy ((void *) &data[14], (void *) src_ip, 4);
memset ((void *) &data[18], 0, ETH_ALEN);
memcpy ((void *) &data[24], (void *) arp_query_ip, 4);
/*send the packet*/
send_result = sendto (sock, buffer, 61, 0,
(struct sockaddr *) &socket_address,
sizeof (socket_address));
if (send_result == -1)
{
printf ("error sending packet %d\n", errno);
if (errno == ENOTSOCK)
printf ("ENOTSOCK\n");
if (errno == EAGAIN)
printf ("EAGAIN\n");
if (errno == ENOBUFS)
printf ("ENOBUFS\n");
if (errno == EINVAL)
printf ("EINVAL\n");
if (errno == EPIPE)
printf ("EPIPE\n");
if (errno == EMSGSIZE)
printf ("EMSGSIZE\n");
if (errno == EBADF)
printf ("EBADF\n");
if (errno == EFAULT)
printf ("EFAULT\n");
}
}
void
recvpack (int sock)
{
char buffer[2048];
unsigned char *iphead, *ethhead;
char proto[10];
int n;
struct iphdr *ip;
struct icmphdr *icmp; //= (void *)((u_int32_t *)ip + ip.ihl );
struct tcphdr *tcp;
struct udphdr *udp;
n = recvfrom (sock, buffer, 2048, 0, NULL, NULL);
printf ("%d bytes read\n", n);
/* Check to see if the packet contains at least
* complete Ethernet (14), IP (20) and TCP/UDP
* (8) headers.
*/
if (n < 20)
{ // was 42
perror ("recvfrom():");
printf ("Incomplete packet (errno is %d)\n", errno);
close (sock);
exit (0);
}
ethhead = buffer;
if (!memcmp(ethhead, (void *) src_mac, 6) || !memcmp(ethhead, (void *) bcast_mac, 6) ) // IS it for our MAC?
{
printf ("Destination MAC address: "
"%02x:%02x:%02x:%02x:%02x:%02x\n",
ethhead[0], ethhead[1], ethhead[2],
ethhead[3], ethhead[4], ethhead[5]);
printf ("Source MAC address: "
"%02x:%02x:%02x:%02x:%02x:%02x\n",
ethhead[6], ethhead[7], ethhead[8],
ethhead[9], ethhead[10], ethhead[11]);
if (ethhead[12] == 0x08 && ethhead[13] == 0x00)
{
iphead = buffer + 14; /* Skip Ethernet header */
if (*iphead == 0x45) { /* Double check for IPv4 and no options present */
ip = (void *)iphead;
printf ("Source host %d.%d.%d.%d\n",
iphead[12], iphead[13], iphead[14], iphead[15]);
printf ("Dest host %d.%d.%d.%d\n",
iphead[16], iphead[17], iphead[18], iphead[19]);
printf ("Source,Dest ports %d,%d\n",
(iphead[20] << 8) + iphead[21],
(iphead[22] << 8) + iphead[23]);
sprintf (proto, "%d", iphead[9]);
if (iphead[9] == IPPROTO_ICMP) {
strcpy (proto, "ICMP");
icmp = (void *)iphead + 20;
if (icmp->type == ICMP_ECHO) {
fprintf(stderr, "PONG!\n");
u_int32_t tmp;
char tbuf[10];
/* Turn it around */
memcpy ( tbuf, (void *) (buffer + ETH_ALEN), ETH_ALEN);
memcpy ((void *) buffer, (void *) tbuf, ETH_ALEN);
memcpy ((void *) (buffer + ETH_ALEN), (void *) src_mac, ETH_ALEN);
//memcpy ((void *) tmp, (void *)&ip->saddr , 4);
tmp = ip->saddr;
ip->saddr = ip->daddr;
ip->daddr = tmp;
icmp->type = ICMP_ECHOREPLY;
icmp->checksum = 0;
icmp->checksum = ~csum_partial(icmp, ntohs(ip->tot_len) - ip->ihl*4, 0);
{
unsigned int i;
for (i = 44; i < ntohs(ip->tot_len); i++){
printf("%u:0x%02X ", i, ((unsigned char *)ip)[i]);
}
printf("\n");
int send_result;
struct sockaddr_ll socket_address; /*target address */
/*RAW communication*/
socket_address.sll_family = PF_PACKET;
/*we don't use a protocoll above ethernet layer ->just use anything here*/
socket_address.sll_protocol = htons (ETH_P_ALL);
/*index of the network device see full code later how to retrieve it*/
socket_address.sll_ifindex = if_nametoindex ("eth0");
printf ("if index for eth0 = %d\n", if_nametoindex ("eth0"));
/*ARP hardware identifier is ethernet*/
socket_address.sll_hatype = ARPHRD_ETHER; // for recv only
/*target is another host*/
socket_address.sll_pkttype = PACKET_BROADCAST; // for recv only
/*address length*/
socket_address.sll_halen = ETH_ALEN;
/*MAC - begin*/
socket_address.sll_addr[0] = 0x00;
socket_address.sll_addr[1] = 0x00;
socket_address.sll_addr[2] = 0x00;
socket_address.sll_addr[3] = 0x00;
socket_address.sll_addr[4] = 0x00;
socket_address.sll_addr[5] = 0x00;
/*MAC - end*/
socket_address.sll_addr[6] = 0x00; /*not used */
socket_address.sll_addr[7] = 0x00; /*not used */
memcpy ((void *) socket_address.sll_addr, (void *)tbuf , ETH_ALEN);
sleep(2);
send_result = sendto (sock, buffer, n, 0,
(struct sockaddr *) &socket_address,
sizeof (socket_address));
if (send_result == -1)
{
printf ("error sending packet %d\n", errno);
}
//write(fd, &u, len);
}
}
}
if (iphead[9] == IPPROTO_IGMP)
strcpy (proto, "IGMP");
if (iphead[9] == IPPROTO_TCP)
strcpy (proto, "TCP");
if (iphead[9] == IPPROTO_UDP)
strcpy (proto, "UDP");
printf ("Layer-4 protocol %s\n", proto);
printf ("TTL %d\n", iphead[8]);
}
}
else
if (ethhead[12] == 0x08 && ethhead[13] == 0x06)
{
printf ("proto = ARP");
}
else
printf ("proto = %02x:%02x\n", ethhead[12], ethhead[13]);
}
}
int
main (int argc, char **argv)
{
int sock;
struct ifreq ethreq;
if ((sock = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
{
perror ("socket");
exit (1);
}
/* Set the network card in promiscuous mode */
strncpy (ethreq.ifr_name, "eth0", IFNAMSIZ);
if (ioctl (sock, SIOCGIFFLAGS, ðreq) == -1)
{
perror ("ioctl");
close (sock);
exit (1);
}
ethreq.ifr_flags |= IFF_PROMISC;
if (ioctl (sock, SIOCSIFFLAGS, ðreq) == -1)
{
perror ("ioctl");
close (sock);
exit (1);
}
sendpack (sock); // ARP Request
while (1)
{
printf ("----------\n");
recvpack (sock);
}
}
Thursday, July 28, 2011
Maze - a new tool for debugging multiprocess and multithreaded programs
Maze - a new tool for debugging multiprocess and multithreaded programs
Hello everybody,
If you develop parallel programs on Linux, Maze may be the right tool for you. If you tend to be an early adopter of new technologies, this may be an interesting project for you as well!
Maze is a Linux-based deterministic environment for your program. It helps you to find and reliably reproduce concurrency bugs. It is easy to use and well-documented. It works out-of-the-box, you do not need to instrument or modify your program.
Please check it out at http://kloobok.com
Thank you!
Roni.
Using sed and awk to highlight console output.
This is really useful for scanning output from make or reading logs.
$ cat TestInput
sdfasd
This is a test abcd test abcd
asdfsd test sdfasdfas
sdfasdffetestasdfasdfas
sdfs
daf
sdf
$ cat highlight
awk '/test/ {print "\033[30;47m" $0 "\033[37;40m"}' TestInput
$ ./highlight
This is a test abcd test abcd
asdfsd test sdfasdfas
sdfasdffetestasdfasdfas
$
I can change the colors.
$ cat highlight
awk '/test/ {print "\033[32;41m" $0 "\033[37;40m"}' TestInput
$ ./highlight
This is a test abcd test abcd
asdfsd test sdfasdfas
sdfasdffetestasdfasdfas
$
Here is a list of color codes.
Terminal Color changing come in the form of esc , ASCII Decimal 27, hex 1B octal 33
esc[background ; foreground m
It's important there be no spaces.
"\033[32;41m"so \033 sends escape, 32;41 is background and foreground and "m" is the command.
I can do the same trick with SED also.
[jsokol]$ cat highlight2 sed 's/test/\d27[32;41m\0\d27[37;40m/g' TestInput [jsokol]$ ./highlight2
sdfasd This is a test abce test aaxx asdfsd test sdfasdfas
sdfasdffetestasdfasdfas
sdfs daf sdf
[jsokol]$
Fwd: Riverbed Intros Cloud Storage Acceleration Business Unit / SANsymphony-V Offers Auto Tiering For Multi-Vendor Storage
From: CRN Storage <CRN_Storage_Weekly1@newsletter.crn.com>
Date: Thu, Jul 28, 2011 at 10:59 AM
Subject: Riverbed Intros Cloud Storage Acceleration Business Unit / SANsymphony-V Offers Auto Tiering For Multi-Vendor Storage
To: sokol@videotechnology.com
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unity Technologies' Flash Day
Flash Day
Unity Technologies' Flash Day is designed to introduce Flash users to the Unity development platform. Flash Day will take place on Tuesday, September 27, the day before Unite 11 kicks off at The Stanford Court Renaissance Hotel in San Francisco. The event is free, but seats are limited, so sign up today.When and Where?
September 27, 2011The Stanford Court Renaissance (Map)
Stanford Ballroom
905 California Street
San Francisco, CA 94108
Unity is a cross platform development tool that lets you write code once and have it run across many platforms.
Mac OS, PC, Android, iPhone, Wii, Xbox., Playstation.
UNITY_STANDALONE_OSX | Platform define for compiling/executing code specifically for Mac OS (This includes Universal, PPC and Intel architectures). |
UNITY_DASHBOARD_WIDGET | Platform define when creating code for Mac OS dashboard widgets. |
UNITY_STANDALONE_WIN | Use this when you want to compile/execute code for Windows stand alone applications. |
UNITY_WEBPLAYER | Platform define for web player content (this includes Windows and Mac Web player executables). |
UNITY_WII | Platform define for compiling/executing code for the Wii console. |
UNITY_IPHONE | Platform define for compiling/executing code for the iPhone platform. |
UNITY_ANDROID | Platform define for the Android platform. |
UNITY_PS3 | Platform define for running Play Station 3 code. |
UNITY_XBOX360 | Platform define for executing XBbox 360 code. |
Fwd: maui super-computer...
From: Bill C
Date: Thu, Jul 28, 2011 at 12:27 PM
Subject: maui super-computer...
To: John Sokol <john.sokol@gmail.com>
ha ha... they made it out of lots of desktops.....
ADK: Android Open Accessory Development Kit
Android Open Accessory Development Kit
The Android 3.1 platform (also backported to Android 2.3.4)
https://docs.google.com/present/view?id=dd7dnm9r_223hffbnvgc&pli=1
www.YLabz.com
Ash@YLabz.com
Wednesday, July 27, 2011
GNU Radio
GNU Radio
GNU Radio is a free software development toolkit that provides the signal processing runtime and processing blocks to implement software radios using readily-available, low-cost external RF hardware and commodity processors. It is widely used in hobbyist, academic and commercial environments to support wireless communications research as well as to implement real-world radio systems.GNU Radio applications are primarily written using the Python programming language, while the supplied, performance-critical signal processing path is implemented in C++ using processor floating point extensions where available. Thus, the developer is able to implement real-time, high-throughput radio systems in a simple-to-use, rapid-application-development environment.
While not primarily a simulation tool, GNU Radio does support development of signal processing algorithms using pre-recorded or generated data, avoiding the need for actual RF hardware.
GNU Radio is licensed under the GNU General Public License (GPL) version 3. All of the code is copyright of the Free Software Foundation.
See more at:
http://gnuradio.org/redmine/projects/gnuradio/wiki
Here is a project that uses it.
Unlocking Wireless PC Locks
OpenVPN notes.
FATAL: Could not load /lib/modules/2.6.18-028stab070.10/modules.dep: No such file or directory
$ uname -a
Linux 2.6.18-028stab070.10 #1 SMP Thu Oct 21 13:44:25 MSD 2010 x86_64 GNU/Linux
$ cat /etc/debian_version
lenny/sid
Not sure if I can make it run without getting those modules in place, alternately I make have to set up a physical host on a DSL line some place and open a port on the firewall. What a hassle.
I had to chat with the Sysadmin of Tektonic.net ISP and he flipped some switch and suddenly
/dev/net/tun started working. Even weirder is lsmod showed no modules loaded.
I want to take a look at Virtual Box and see if that also does some weirdness with Linux modules too.
Install and setup OpenVPN on Debian 4.0 Etch
Quick simple tutorial/howto on OpenVPN with Debian
http://openvpn.net/bridge.html
http://openvpn.net/INSTALL-win32.html
Monday, July 25, 2011
Boot To Gecko – Mozilla's Web-Based OS
"Mozilla has launched a new project called 'Boot to Gecko.' The aim of this project is to develop a complete operating system for the open web. Unlike Google's version of a web-based OS — the Chrome OS — Mozilla's version is not aimed at netbooks. With Boot to Gecko, Mozilla is aiming for smartphones – and Android forms a part of their plan."
Fwd: Tech Focus: Hardware languages for softies
I'd bet most software people realize that we are almost a the point of pure code to hardware design.
From: "Embedded.com Newsletter" <Embedded@newsletters.eetimes.com>
Date: Jul 25, 2011 9:08 AM
Subject: Tech Focus: Hardware languages for softies
To: <sokol@videotechnology.com>
|