mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
proAdhoc: Make some functions return boolean values.
Also shortens validNetworkName a little.
This commit is contained in:
parent
1809e98b7b
commit
1d9ace08ae
@ -1,5 +1,6 @@
|
||||
// TODO: Add license
|
||||
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "util/text/parsers.h"
|
||||
#include "proAdhoc.h"
|
||||
@ -750,33 +751,27 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){
|
||||
}
|
||||
}
|
||||
|
||||
int isBroadcastMAC(const SceNetEtherAddr * addr) {
|
||||
// Broadcast MAC
|
||||
if(memcmp(addr->data, "\xFF\xFF\xFF\xFF\xFF\xFF", ETHER_ADDR_LEN) == 0) return 1;
|
||||
// Normal MAC
|
||||
return 0;
|
||||
bool isBroadcastMAC(const SceNetEtherAddr * addr) {
|
||||
return memcmp(addr->data, "\xFF\xFF\xFF\xFF\xFF\xFF", ETHER_ADDR_LEN) == 0;
|
||||
}
|
||||
|
||||
int resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
||||
bool resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
||||
sockaddr_in addr;
|
||||
getLocalIp(&addr);
|
||||
uint32 localIp = addr.sin_addr.s_addr;
|
||||
|
||||
if(ip == localIp){
|
||||
if (ip == localIp) {
|
||||
getLocalMac(mac);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Multithreading Lock
|
||||
peerlock.lock();
|
||||
|
||||
// Peer Reference
|
||||
SceNetAdhocctlPeerInfo * peer = friends;
|
||||
|
||||
// Iterate Peers
|
||||
for(; peer != NULL; peer = peer->next) {
|
||||
for (SceNetAdhocctlPeerInfo* peer = friends; peer != NULL; peer = peer->next) {
|
||||
// Found Matching Peer
|
||||
if(peer->ip_addr == ip) {
|
||||
if (peer->ip_addr == ip) {
|
||||
// Copy Data
|
||||
*mac = peer->mac_addr;
|
||||
|
||||
@ -784,7 +779,7 @@ int resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
||||
peerlock.unlock();
|
||||
|
||||
// Return Success
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -792,7 +787,7 @@ int resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
||||
peerlock.unlock();
|
||||
|
||||
// Peer not found
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
||||
@ -800,32 +795,28 @@ int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
||||
SceNetEtherAddr localMac;
|
||||
getLocalMac(&localMac);
|
||||
// Local MAC Requested
|
||||
if(memcmp(&localMac, mac, sizeof(SceNetEtherAddr)) == 0) {
|
||||
if (memcmp(&localMac, mac, sizeof(SceNetEtherAddr)) == 0) {
|
||||
// Get Local IP Address
|
||||
sockaddr_in sockAddr;
|
||||
getLocalIp(&sockAddr);
|
||||
*ip = sockAddr.sin_addr.s_addr;
|
||||
return 0; // return succes
|
||||
return true;
|
||||
}
|
||||
|
||||
// Multithreading Lock
|
||||
peerlock.lock();
|
||||
|
||||
// Peer Reference
|
||||
SceNetAdhocctlPeerInfo * peer = friends;
|
||||
|
||||
// Iterate Peers
|
||||
for(; peer != NULL; peer = peer->next) {
|
||||
for (SceNetAdhocctlPeerInfo * peer = friends; peer != NULL; peer = peer->next) {
|
||||
// Found Matching Peer
|
||||
if(memcmp(&peer->mac_addr, mac, sizeof(SceNetEtherAddr)) == 0) {
|
||||
if (memcmp(&peer->mac_addr, mac, sizeof(SceNetEtherAddr)) == 0) {
|
||||
// Copy Data
|
||||
*ip = peer->ip_addr;
|
||||
|
||||
// Multithreading Unlock
|
||||
peerlock.unlock();
|
||||
|
||||
// Return Success
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -833,35 +824,24 @@ int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
||||
peerlock.unlock();
|
||||
|
||||
// Peer not found
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
int validNetworkName(const SceNetAdhocctlGroupName * group_name) {
|
||||
// Result
|
||||
int valid = 1;
|
||||
|
||||
bool validNetworkName(const SceNetAdhocctlGroupName * group_name) {
|
||||
// Name given
|
||||
if(group_name != NULL) {
|
||||
// Iterate Name Characters
|
||||
int i = 0; for(; i < ADHOCCTL_GROUPNAME_LEN && valid; i++) {
|
||||
if (group_name != NULL) {
|
||||
for (int i = 0; i < ADHOCCTL_GROUPNAME_LEN; i++) {
|
||||
// End of Name
|
||||
if(group_name->data[i] == 0) break;
|
||||
if (group_name->data[i] == 0)
|
||||
break;
|
||||
|
||||
// Not a digit
|
||||
if(group_name->data[i] < '0' || group_name->data[i] > '9') {
|
||||
// Not 'A' to 'Z'
|
||||
if(group_name->data[i] < 'A' || group_name->data[i] > 'Z') {
|
||||
// Not 'a' to 'z'
|
||||
if(group_name->data[i] < 'a' || group_name->data[i] > 'z') {
|
||||
// Invalid Name
|
||||
valid = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Invalid name
|
||||
if (!::isalnum(group_name->data[i]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Return Result
|
||||
return valid;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
u64 join32(u32 num1, u32 num2){
|
||||
|
@ -627,29 +627,29 @@ int initNetwork(SceNetAdhocctlAdhocId *adhocid);
|
||||
/**
|
||||
* Broadcast MAC Check
|
||||
* @param addr To-be-checked MAC Address
|
||||
* @return 1 if Broadcast MAC or... 0
|
||||
* @return true if Broadcast MAC, false otherwise.
|
||||
*/
|
||||
int isBroadcastMAC(const SceNetEtherAddr * addr);
|
||||
bool isBroadcastMAC(const SceNetEtherAddr * addr);
|
||||
|
||||
/**
|
||||
* Resolve IP to MAC
|
||||
* @param ip Peer IP Address
|
||||
* @param mac OUT: Peer MAC
|
||||
* @return 0 on success or... ADHOC_NO_ENTRY
|
||||
* @return true on success, false otherwise.
|
||||
*/
|
||||
int resolveIP(uint32_t ip, SceNetEtherAddr * mac);
|
||||
bool resolveIP(uint32_t ip, SceNetEtherAddr * mac);
|
||||
|
||||
/**
|
||||
* Resolve MAC to IP
|
||||
* @param mac Peer MAC Address
|
||||
* @param ip OUT: Peer IP
|
||||
* @return 0 on success or... ADHOC_NO_ENTRY
|
||||
* @return true on success, false otherwise.
|
||||
*/
|
||||
int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip);
|
||||
|
||||
/**
|
||||
* Check whether Network Name contains only valid symbols
|
||||
* @param group_name To-be-checked Network Name
|
||||
* @return 1 if valid or... 0
|
||||
* @return true if valid, false otherwise.
|
||||
*/
|
||||
int validNetworkName(const SceNetAdhocctlGroupName * groupname);
|
||||
bool validNetworkName(const SceNetAdhocctlGroupName * groupname);
|
||||
|
@ -476,7 +476,7 @@ int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int len, i
|
||||
target.sin_port = htons(dport);
|
||||
|
||||
// Get Peer IP
|
||||
if (resolveMAC((SceNetEtherAddr *)daddr, (uint32_t *)&target.sin_addr.s_addr) == 0) {
|
||||
if (resolveMAC((SceNetEtherAddr *)daddr, (uint32_t *)&target.sin_addr.s_addr)) {
|
||||
// Acquire Network Lock
|
||||
//_acquireNetworkLock();
|
||||
|
||||
@ -673,7 +673,7 @@ int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void *dataLen
|
||||
SceNetEtherAddr mac;
|
||||
|
||||
// Find Peer MAC
|
||||
if (resolveIP(sin.sin_addr.s_addr, &mac) == 0) {
|
||||
if (resolveIP(sin.sin_addr.s_addr, &mac)) {
|
||||
// Provide Sender Information
|
||||
*saddr = mac;
|
||||
*sport = ntohs(sin.sin_port);
|
||||
@ -1569,7 +1569,7 @@ int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int timeou
|
||||
SceNetEtherAddr mac;
|
||||
|
||||
// Find Peer MAC
|
||||
if (resolveIP(peeraddr.sin_addr.s_addr, &mac) == 0) {
|
||||
if (resolveIP(peeraddr.sin_addr.s_addr, &mac)) {
|
||||
// Allocate Memory
|
||||
SceNetAdhocPtpStat * internal = (SceNetAdhocPtpStat *)malloc(sizeof(SceNetAdhocPtpStat));
|
||||
|
||||
@ -1678,7 +1678,7 @@ int sceNetAdhocPtpConnect(int id, int timeout, int flag) {
|
||||
sin.sin_port = htons(socket->pport);
|
||||
|
||||
// Grab Peer IP
|
||||
if (resolveMAC(&socket->paddr, (uint32_t *)&sin.sin_addr.s_addr) == 0) {
|
||||
if (resolveMAC(&socket->paddr, (uint32_t *)&sin.sin_addr.s_addr)) {
|
||||
// Grab Nonblocking Flag
|
||||
uint32_t nbio = getBlockingFlag(socket->id);
|
||||
// Switch to Nonblocking Behaviour
|
||||
|
Loading…
Reference in New Issue
Block a user