IBR-DTNSuite 0.6

ibrcommon/ibrcommon/net/UnicastSocketLowpan.cpp

Go to the documentation of this file.
00001 /*
00002  * UnicastSocket.cpp
00003  *
00004  *  Created on: 28.06.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #include "ibrcommon/net/UnicastSocketLowpan.h"
00009 
00010 namespace ibrcommon
00011 {
00012         UnicastSocketLowpan::UnicastSocketLowpan()
00013          : lowpansocket(IPPROTO_UDP) //FIXME
00014         {
00015         }
00016 
00017         UnicastSocketLowpan::~UnicastSocketLowpan()
00018         {
00019         }
00020 
00021         void UnicastSocketLowpan::bind(int panid, const vinterface &iface)
00022         {
00023 
00024                 _sockaddr.addr.addr_type = IEEE802154_ADDR_SHORT;
00025                 //_sockaddr.addr.pan_id = 0x780;
00026                 _sockaddr.addr.pan_id = panid;
00027 
00028                 // convert given address
00029                 getAddress(&_sockaddr.addr, iface);
00030                 //printf("Address to bind %04x\n", _sockaddr.addr.short_addr);
00031 
00032                 if ( ::bind(_socket, (struct sockaddr *) &_sockaddr, sizeof(_sockaddr)) < 0 )
00033                 {
00034                         throw SocketException("UnicastSocketLowpan: cannot bind socket");
00035                 }
00036         }
00037 /*
00038         void UnicastSocketLowpan::bind(int panid, const vaddress &address)
00039         {
00040                 _sockaddr.addr.addr_type = IEEE802154_ADDR_SHORT;
00041                 _sockaddr.addr.pan_id = 0x780;
00042                 //_sockaddr.addr.pan_id = panid;
00043 
00044                 printf("Wrong function\n");
00045 
00046                 // convert given address
00047                 if (address.length() > 0)
00048 
00049                 {
00050                         if (inet_pton(PF_IEEE802154, address.c_str(), &_sockaddr.addr) <= 0)
00051                         {
00052                                 throw SocketException("UnicastSocketLowpan: can not parse address " + address);
00053                         }
00054                 }
00055 
00056                 _sockaddr.addr.short_addr = 0x8001; //FIXME HACK!!
00057 
00058                 if ( ::bind(_socket, (struct sockaddr *) &_sockaddr, sizeof(_sockaddr)) < 0 )
00059                 {
00060                         throw SocketException("UnicastSocketLowpan: cannot bind socket");
00061                 }
00062         }
00063 */
00064 }