BOOL cg_bittorrent_client_createpeerid(CgBittorrentClient *cbc, CgByte *peerId) { CgNetworkInterfaceList *netIfList; CgNetworkInterface *netIf; char hostName[CG_HTTP_SEVERNAME_MAXLEN]; CgByte hostNameHash[CG_SHA1_HASH_SIZE]; CgSHA1Context sha; int err; memset(peerId, 0, CG_BITTORRENT_CLIENT_PEERID_SIZE); /* Client ID/Vertion */ peerId[0] = '-'; memcpy(peerId + 1, CG_BITTORRENT_CLIENT_ID, 2); memcpy(peerId + 3, CG_BITTORRENT_CLIENT_VER, 4); /* Host Name */ cg_http_getservername(hostName, CG_HTTP_SEVERNAME_MAXLEN); err = cg_sha1_reset(&sha); if (!err) { err = cg_sha1_input(&sha, hostName, cg_strlen(hostName)); if (!err) err = cg_sha1_result(&sha, hostNameHash); } if (err) return FALSE; memcpy(peerId + 7, hostNameHash, 7); /* Mac Address */ netIfList = cg_net_interfacelist_new(); if (!netIfList) return FALSE; cg_net_gethostinterfaces(netIfList); netIf =cg_net_interfacelist_gets(netIfList); if (!netIf) { cg_net_interfacelist_delete(netIfList); return FALSE; } cg_net_interface_getmacaddress(netIf, (peerId + 14)); cg_net_interfacelist_delete(netIfList); return FALSE; }
char *cg_upnp_getservername(char *buf, int bufSize) { int nameLen; cg_log_debug_l4("Entering...\n"); cg_http_getservername(buf, bufSize); nameLen = cg_strlen(buf); bufSize -= nameLen; if (bufSize <= 0) return buf; #if defined(HAVE_SNPRINTF) snprintf((buf+nameLen), bufSize, " %s/%s UPnP/%s DLNADOC/%s", CG_CLINK_NAME, CG_CLINK_VER, CG_UPNP_VER, CG_DLNA_VER); #else sprintf((buf+nameLen), " %s/%s UPnP/%s DLNADOC/%s", CG_CLINK_NAME, CG_CLINK_VER, CG_UPNP_VER, CG_DLNA_VER); #endif cg_log_debug_l4("Leaving...\n"); return buf; }