mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-12 02:44:00 +00:00
Merge pull request #7143 from lioncash/net
proAdhoc: Make some functions return boolean values.
This commit is contained in:
commit
6546a5ac03
@ -1,5 +1,6 @@
|
||||
// TODO: Add license
|
||||
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "util/text/parsers.h"
|
||||
#include "proAdhoc.h"
|
||||
@ -750,31 +751,25 @@ 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) {
|
||||
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) {
|
||||
// Copy Data
|
||||
@ -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) {
|
||||
@ -805,17 +800,14 @@ int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
||||
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) {
|
||||
// Copy Data
|
||||
@ -824,8 +816,7 @@ int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
||||
// 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++) {
|
||||
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