Homepage Wiki Forum Buy

Ad-hoc

From GNUBLIN

Ad-hoc

It is possible to set up a Ad hoc network on GNUBLIN and connect to it e.g. via a iPhone.


Contents

Preparation

Set up a webserver

How you set up a Webserver is documented at Webserver with CGI-


Connect the WLAN-stick

How you get your WLAN-Stick working you can read here: WLAN.

Configure the udhcpd

To even be able to establish a connection, it is necessary to provide the connecting client a IP address. You can accomplish that with the udhcp daemon.

The udhcp config file (/etc/udhcpd.config) looks as follows


start 192.168.2.2
end 192.168.2.100
opt lease 86400
opt subnet 255.255.255.0
option dns 192.168.2.1
interface wlan0
pidfile /var/run/udhcpd.wlan0.pid

As DNS address you should pick the IP from your GNUBLIN.


Automatically open browser after login

Should the webbrowser automatically open after a WLAN login you should choose the following DNS-Server:


#include <stdio.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>


#define PORT 53
#define BUFLEN 512

int main(){
char recvbuf[BUFLEN];
char sendbuf[BUFLEN];
struct sockaddr_in socket_me, socket_other;
int i, s,slen=sizeof(socket_other);
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
socket_me.sin_family = AF_INET;
socket_me.sin_port = htons(PORT);
socket_me.sin_addr.s_addr = INADDR_ANY;
if(bind(s, (struct sockaddr *) &socket_me, sizeof(socket_me))== -1)
puts("Fehler bei Bind");

while (1){
int rc = recvfrom(s, recvbuf, BUFLEN, 0, (struct sockaddr *) &socket_other, &slen);
if(rc == -1){
puts("recvfrom()");
}
//bauen des Antwortpacket
sendbuf[0]=recvbuf[0];
sendbuf[1]=recvbuf[1];
sendbuf[2]='\x81';
sendbuf[3]='\x80';
sendbuf[4]=recvbuf[4];
sendbuf[5]=recvbuf[5];
sendbuf[6]=recvbuf[4];
sendbuf[7]=recvbuf[5];
sendbuf[8]='\x00';
sendbuf[9]='\x00';
sendbuf[10]='\x00';
sendbuf[11]='\x00';
//transaction Nr
//Flags
//Questions and Answers Counts
int len = strlen(&recvbuf[12]);
memcpy(&sendbuf[12], &recvbuf[12],len+5);
len = 12 + len + 4;
sendbuf[len+1]='\xc0';
sendbuf[len+2]='\x0c';
sendbuf[len+3]='\x00';
sendbuf[len+4]='\x01';
sendbuf[len+5]='\x00';
sendbuf[len+6]='\x01';
sendbuf[len+7]='\x00';
sendbuf[len+8]='\x00';
sendbuf[len+9]='\x00';
sendbuf[len+10]='\x3c';
sendbuf[len+11]='\x00';
sendbuf[len+12]='\x04';

//Ip addresse
sendbuf[len+13]=192;
sendbuf[len+14]=168;
sendbuf[len+15]=2;
sendbuf[len+16]=1;

int sendbuflen = len + 16 + 1; //die länge des packetes
sendto(s, sendbuf, sendbuflen, 0, (struct sockaddr *) &socket_other, slen);
}
return 0;
}

This code will be compiled on the GNUBLIN


Let's go

Frist, we give GNUBLIN a IP address:

ifconfig wlan0 192.168.2.1 up

Second, we displace the WLAN Stick into the Ad-hoch mode and also give him an essid:

iwconfig wlan0 mode ad-hoc essid GNUBLIN


Then we run our self compiled program in the background:

./dns-serv &

Last we just start the udhcp daemon

udhcpd

Now the webbrowser should start, right after the WLAN login.

Hint

Android has some problems to connect to a Access Point. With an iPhone the login works fine.

In other languages