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 NetInterface &iface) 00022 { 00023 _sockaddr.addr.addr_type = IEEE802154_ADDR_SHORT; 00024 //_sockaddr.addr.pan_id = 0x780; 00025 _sockaddr.addr.pan_id = panid; 00026 00027 // convert given address 00028 iface.getAddress(&_sockaddr.addr); 00029 //printf("Address to bind %04x\n", _sockaddr.addr.short_addr); 00030 00031 if ( ::bind(_socket, (struct sockaddr *) &_sockaddr, sizeof(_sockaddr)) < 0 ) 00032 { 00033 throw SocketException("UnicastSocketLowpan: cannot bind socket"); 00034 } 00035 } 00036 /* 00037 void UnicastSocketLowpan::bind(int panid, std::string address) 00038 { 00039 _sockaddr.addr.addr_type = IEEE802154_ADDR_SHORT; 00040 _sockaddr.addr.pan_id = 0x780; 00041 //_sockaddr.addr.pan_id = panid; 00042 00043 printf("Wrong function\n"); 00044 00045 // convert given address 00046 if (address.length() > 0) 00047 00048 { 00049 if (inet_pton(PF_IEEE802154, address.c_str(), &_sockaddr.addr) <= 0) 00050 { 00051 throw SocketException("UnicastSocketLowpan: can not parse address " + address); 00052 } 00053 } 00054 00055 _sockaddr.addr.short_addr = 0x8001; //FIXME HACK!! 00056 00057 if ( ::bind(_socket, (struct sockaddr *) &_sockaddr, sizeof(_sockaddr)) < 0 ) 00058 { 00059 throw SocketException("UnicastSocketLowpan: cannot bind socket"); 00060 } 00061 } 00062 */ 00063 }
1.7.1