void peisk_bluetoothParseHELLO(char *buf,int len) { int version; char str[64]; PeisHostInfoPackage package; if(len != sizeof(int) + 64 + sizeof(package)) { fprintf(stderr,"Warning, received bluetooth HELLO of wrong length (%d)\n",len); return; } memcpy((void*) &version, buf, sizeof(int)); buf += sizeof(int); memcpy(str,buf,64); buf += 64; memcpy(&package,buf,sizeof(package)); if(version != htonl(peisk_protocollVersion)) { fprintf(stderr,"Warning, received bluetooth HELLO of wrong version\n"); return; } str[62]=0; if(strcmp(str,peisk_networkString) != 0) { fprintf(stderr,"Warning, received bluetooth HELLO with wrong networkstring %s\n",str); return; } /* Convert package to be in HOST byte order */ peisk_ntoh_hostInfo(&package.hostInfo); /* Send hostinfo to be processed by the P2P layer */ peisk_handleBroadcastedHostInfo(&package.hostInfo); }
/** Listen to multicast/broadcasted UDP packages announcing peiskernels on the local network */ void peisk_acceptUDPMulticasts() { int size; PeisUDPBroadcastAnnounceMessage message; if(peiskernel.tcp_broadcast_receiver <= 0) return; while(1) { size=recvfrom(peiskernel.tcp_broadcast_receiver,(void*)&message,sizeof(message),MSG_DONTWAIT,NULL,NULL); if(size == -1) return; if(size == sizeof(message)) { /* convert broadcasted message so that all subfields within it is now in HOST order */ message.protocollVersion = ntohl(message.protocollVersion); peisk_ntoh_hostInfo(&message.hostinfo); if(message.hostinfo.id > 65535) { /* Just for debugging - until we start using longer PEIS-id's */ printf("Warning - getting hostinfo with id = %d (%x) on the multicast\n",message.hostinfo.id,message.hostinfo.id); } /* Check if it matches the network connection strings */ message.networkString[63]=0; if(strcmp(message.networkString,peisk_networkString) != 0) return; if(message.protocollVersion > peisk_protocollVersion && message.protocollVersion < 1000) { printf("ERROR - A newer version of the PEIS kernel exists - you should upgrade!\n"); peisk_shutdown(); } if(message.protocollVersion != peisk_protocollVersion) return; message.hostinfo.fullname[PEISK_MAX_HOSTINFO_NAME_LEN-1]=0; /* force name part of hostinfo to be a null terminated string */ /*printf("peisk: received host announcement for '%s'\n",hostinfo.fullname);*/ /* We received a full PeisHostInfo field describing another available host */ if(message.hostinfo.id == -1 || message.hostinfo.id == peisk_id) return; peisk_handleBroadcastedHostInfo(&message.hostinfo); /* Reset counter for deciding if we are allowed to broadcast if this one comes from our host and have a lower ID than us. */ if(message.hostinfo.id < peiskernel.id && strcmp(message.hostinfo.hostname,peiskernel.hostInfo.hostname) == 0) peiskernel.broadcastingCounter = 0; } } }