mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-02-17 06:31:14 +00:00
Updated coding style.
This commit is contained in:
parent
94b790728e
commit
01ba04139f
@ -43,12 +43,12 @@
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
static int openBpf(char *ifname);
|
||||
static int retreiveAuthInfo(void);
|
||||
static int mainLoop(int sd);
|
||||
static int open_bpf(char *ifname);
|
||||
static int retreive_auth_info(void);
|
||||
static int main_loop(int sd);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *ifName;
|
||||
char *if_name;
|
||||
int ret;
|
||||
int sd;
|
||||
|
||||
@ -56,23 +56,23 @@ int main(int argc, char **argv) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
ifName = argv[1];
|
||||
if_name = argv[1];
|
||||
|
||||
ret = retreiveAuthInfo();
|
||||
ret = retreive_auth_info();
|
||||
if (ret != 0) {
|
||||
return 254;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
sd = openBpf(ifName);
|
||||
sd = open_bpf(if_name);
|
||||
if (sd < 0) {
|
||||
return 253;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
ret = mainLoop(sd);
|
||||
ret = main_loop(sd);
|
||||
|
||||
close(sd);
|
||||
|
||||
@ -83,18 +83,18 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mainLoop(int sd) {
|
||||
static int main_loop(int sd) {
|
||||
fd_set readSet;
|
||||
char *outgoing, *incoming;
|
||||
unsigned short *outLen;
|
||||
unsigned short *inLen;
|
||||
int inIndex, outIndex;
|
||||
unsigned short *out_len;
|
||||
unsigned short *in_len;
|
||||
int in_index, out_index;
|
||||
u_int blen = 0;
|
||||
int ret;
|
||||
int fret = 0;
|
||||
struct bpf_hdr *hdr;
|
||||
int pktLen;
|
||||
int frameLen;
|
||||
int pkt_len;
|
||||
int frame_len;
|
||||
int pad;
|
||||
|
||||
if (ioctl(sd, BIOCGBLEN, &blen) < 0) {
|
||||
@ -112,10 +112,10 @@ static int mainLoop(int sd) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
inIndex = 0;
|
||||
outIndex = 0;
|
||||
in_index = 0;
|
||||
out_index = 0;
|
||||
|
||||
outLen = (unsigned short *)outgoing;
|
||||
out_len = (unsigned short *)outgoing;
|
||||
|
||||
while (1) {
|
||||
int i;
|
||||
@ -130,10 +130,10 @@ static int mainLoop(int sd) {
|
||||
}
|
||||
|
||||
if (FD_ISSET(0, &readSet)) {
|
||||
if(outIndex < 2) {
|
||||
ret = read(0, outgoing + outIndex, 2-outIndex);
|
||||
if (out_index < 2) {
|
||||
ret = read(0, outgoing + out_index, 2-out_index);
|
||||
} else {
|
||||
ret = read(0, outgoing + outIndex, *outLen - outIndex + 2);
|
||||
ret = read(0, outgoing + out_index, *out_len - out_index + 2);
|
||||
}
|
||||
|
||||
if (ret < 1) {
|
||||
@ -141,22 +141,22 @@ static int mainLoop(int sd) {
|
||||
break;
|
||||
}
|
||||
|
||||
outIndex += ret;
|
||||
if(outIndex > 1) {
|
||||
out_index += ret;
|
||||
if (out_index > 1) {
|
||||
fflush(stdout);
|
||||
|
||||
if((*outLen + 2) > blen) {
|
||||
if ((*out_len + 2) > blen) {
|
||||
fret = -6;
|
||||
break;
|
||||
}
|
||||
|
||||
if(outIndex == (*outLen + 2)) {
|
||||
ret = write(sd, outLen + 1, *outLen);
|
||||
if(ret != *outLen) {
|
||||
if (out_index == (*out_len + 2)) {
|
||||
ret = write(sd, out_len + 1, *out_len);
|
||||
if (ret != *out_len) {
|
||||
fret = -7;
|
||||
break;
|
||||
}
|
||||
outIndex = 0;
|
||||
out_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,28 +172,28 @@ static int mainLoop(int sd) {
|
||||
}
|
||||
|
||||
hdr = (struct bpf_hdr *)incoming;
|
||||
inLen = (unsigned short *)(incoming + 16);
|
||||
in_len = (unsigned short *)(incoming + 16);
|
||||
|
||||
do {
|
||||
pktLen = hdr->bh_caplen;
|
||||
frameLen = pktLen + 18;
|
||||
pkt_len = hdr->bh_caplen;
|
||||
frame_len = pkt_len + 18;
|
||||
|
||||
if((pktLen < 0) || (frameLen > ret) || (frameLen < 0)) {
|
||||
if ((pkt_len < 0) || (frame_len > ret) || (frame_len < 0)) {
|
||||
fret = -9;
|
||||
break;
|
||||
}
|
||||
*inLen = pktLen;
|
||||
*in_len = pkt_len;
|
||||
|
||||
write(0, inLen, pktLen + 2);
|
||||
if((frameLen & 0x03) == 0) {
|
||||
write(0, in_len, pkt_len + 2);
|
||||
if ((frame_len & 0x03) == 0) {
|
||||
pad = 0;
|
||||
} else {
|
||||
pad = 4 - (frameLen & 0x03);
|
||||
pad = 4 - (frame_len & 0x03);
|
||||
}
|
||||
|
||||
ret -= (frameLen + pad);
|
||||
hdr = (struct bpf_hdr *)((unsigned char *)hdr + frameLen + pad);
|
||||
inLen = (unsigned short *)((unsigned char *)hdr + 16);
|
||||
ret -= (frame_len + pad);
|
||||
hdr = (struct bpf_hdr *)((unsigned char *)hdr + frame_len + pad);
|
||||
in_len = (unsigned short *)((unsigned char *)hdr + 16);
|
||||
} while (ret > 0);
|
||||
|
||||
if (fret != 0) {
|
||||
@ -208,7 +208,7 @@ static int mainLoop(int sd) {
|
||||
return fret;
|
||||
}
|
||||
|
||||
static int retreiveAuthInfo(void) {
|
||||
static int retreive_auth_info(void) {
|
||||
AuthorizationRef aRef;
|
||||
OSStatus status;
|
||||
AuthorizationRights myRights;
|
||||
@ -253,7 +253,7 @@ static int retreiveAuthInfo(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int openBpf(char *ifname) {
|
||||
static int open_bpf(char *ifname) {
|
||||
u_int blen = 0;
|
||||
struct ifreq ifreq;
|
||||
u_int arg;
|
||||
|
@ -40,14 +40,18 @@
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
FILE * runTool(const char *ifName);
|
||||
FILE * run_tool(const char *ifName);
|
||||
|
||||
FILE * runTool(const char *ifName) {
|
||||
OSStatus authStatus;
|
||||
FILE * run_tool(const char *ifName) {
|
||||
OSStatus auth_status;
|
||||
FILE *fp;
|
||||
char *args[] = {"etherslavetool", NULL, NULL};
|
||||
int ret;
|
||||
const char *path;
|
||||
AuthorizationFlags auth_flags;
|
||||
AuthorizationRef auth_ref;
|
||||
AuthorizationItem auth_items[1];
|
||||
AuthorizationRights auth_rights;
|
||||
|
||||
path = [[[NSBundle mainBundle]
|
||||
pathForResource:@"etherslavetool" ofType: nil] UTF8String];
|
||||
@ -56,42 +60,37 @@ FILE * runTool(const char *ifName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AuthorizationFlags authFlags;
|
||||
AuthorizationRef authRef;
|
||||
AuthorizationItem authItems[1];
|
||||
AuthorizationRights authRights;
|
||||
|
||||
args[1] = (char *)ifName;
|
||||
|
||||
authFlags = kAuthorizationFlagExtendRights |
|
||||
auth_flags = kAuthorizationFlagExtendRights |
|
||||
kAuthorizationFlagInteractionAllowed |
|
||||
kAuthorizationFlagPreAuthorize;
|
||||
|
||||
authItems[0].name = "system.privilege.admin";
|
||||
authItems[0].valueLength = 0;
|
||||
authItems[0].value = NULL;
|
||||
authItems[0].flags = 0;
|
||||
auth_items[0].name = "system.privilege.admin";
|
||||
auth_items[0].valueLength = 0;
|
||||
auth_items[0].value = NULL;
|
||||
auth_items[0].flags = 0;
|
||||
|
||||
authRights.count = sizeof (authItems) / sizeof (authItems[0]);
|
||||
authRights.items = authItems;
|
||||
auth_rights.count = sizeof (auth_items) / sizeof (auth_items[0]);
|
||||
auth_rights.items = auth_items;
|
||||
|
||||
authStatus = AuthorizationCreate(&authRights,
|
||||
auth_status = AuthorizationCreate(&auth_rights,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
authFlags,
|
||||
&authRef);
|
||||
auth_flags,
|
||||
&auth_ref);
|
||||
|
||||
if(authStatus != errAuthorizationSuccess) {
|
||||
if (auth_status != errAuthorizationSuccess) {
|
||||
fprintf(stderr, "%s: AuthorizationCreate() failed.\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
authStatus = AuthorizationExecuteWithPrivileges(authRef,
|
||||
auth_status = AuthorizationExecuteWithPrivileges(auth_ref,
|
||||
path,
|
||||
kAuthorizationFlagDefaults,
|
||||
args + 1,
|
||||
&fp);
|
||||
|
||||
if(authStatus != errAuthorizationSuccess) {
|
||||
if (auth_status != errAuthorizationSuccess) {
|
||||
fprintf(stderr, "%s: AuthorizationExecWithPrivileges() failed.\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ enum {
|
||||
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
extern "C" {
|
||||
extern FILE * runTool(const char *ifName);
|
||||
extern FILE * run_tool(const char *if_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -155,9 +155,9 @@ static void slirp_add_redirs();
|
||||
static int slirp_add_redir(const char *redir_str);
|
||||
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
static int getmacaddress(const char* dev, unsigned char *addr);
|
||||
static bool openEtherSlave(const char *ifName);
|
||||
static int readpacket(void);
|
||||
static int get_mac_address(const char* dev, unsigned char *addr);
|
||||
static bool open_ether_slave(const char *if_name);
|
||||
static int read_packet(void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -260,7 +260,7 @@ bool ether_init(void)
|
||||
// Do nothing if no Ethernet device specified
|
||||
const char *name = PrefsFindString("ether");
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
const char *slaveDev = PrefsFindString("etherslavedev");
|
||||
const char *slave_dev = PrefsFindString("etherslavedev");
|
||||
#endif
|
||||
if (name == NULL)
|
||||
return false;
|
||||
@ -333,11 +333,11 @@ bool ether_init(void)
|
||||
break;
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
case NET_IF_ETHERSLAVE:
|
||||
if(slaveDev == NULL) {
|
||||
if (slave_dev == NULL) {
|
||||
WarningAlert("etherslavedev not defined in preferences.");
|
||||
return false;
|
||||
}
|
||||
return openEtherSlave(slaveDev);
|
||||
return open_ether_slave(slave_dev);
|
||||
#endif
|
||||
}
|
||||
if (net_if_type != NET_IF_SLIRP) {
|
||||
@ -792,10 +792,10 @@ static int16 ether_do_write(uint32 arg)
|
||||
#endif
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
if (net_if_type == NET_IF_ETHERSLAVE) {
|
||||
unsigned short pktlen;
|
||||
unsigned short pkt_len;
|
||||
|
||||
pktlen = len;
|
||||
if(write(fd, &pktlen, 2) < 2) {
|
||||
pkt_len = len;
|
||||
if (write(fd, &pkt_len, 2) < 2) {
|
||||
return excessCollsns;
|
||||
}
|
||||
|
||||
@ -940,7 +940,7 @@ static void *receive_func(void *arg)
|
||||
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
if (net_if_type == NET_IF_ETHERSLAVE) {
|
||||
if(readpacket() < 1) {
|
||||
if (read_packet() < 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -987,12 +987,12 @@ void ether_do_interrupt(void)
|
||||
#endif
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
if (net_if_type == NET_IF_ETHERSLAVE) {
|
||||
unsigned short *pktlen;
|
||||
unsigned short *pkt_len;
|
||||
uint32 p = packet;
|
||||
|
||||
pktlen = (unsigned short *)packet_buffer;
|
||||
length = *pktlen;
|
||||
memcpy(Mac2HostAddr(packet), pktlen + 1, length);
|
||||
pkt_len = (unsigned short *)packet_buffer;
|
||||
length = *pkt_len;
|
||||
memcpy(Mac2HostAddr(packet), pkt_len + 1, length);
|
||||
ether_dispatch_packet(p, length);
|
||||
break;
|
||||
} else
|
||||
@ -1124,7 +1124,7 @@ static int slirp_add_redir(const char *redir_str)
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MACOSX_ETHERSLAVE
|
||||
static int getmacaddress(const char* dev, unsigned char *addr)
|
||||
static int get_mac_address(const char* dev, unsigned char *addr)
|
||||
{
|
||||
struct ifaddrs *ifaddrs, *next;
|
||||
int ret = -1;
|
||||
@ -1156,23 +1156,21 @@ static int getmacaddress(const char* dev, unsigned char *addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool openEtherSlave(const char *ifName)
|
||||
static bool open_ether_slave(const char *if_name)
|
||||
{
|
||||
FILE *fp;
|
||||
char str[64];
|
||||
|
||||
str[sizeof(str)-1] = '\0';
|
||||
|
||||
if(getmacaddress(ifName, ether_addr) != 0) {
|
||||
snprintf(str, sizeof(str)-1, "Unable to find interface %s.",
|
||||
ifName);
|
||||
if (get_mac_address(if_name, ether_addr) != 0) {
|
||||
snprintf(str, sizeof(str), "Unable to find interface %s.",
|
||||
if_name);
|
||||
WarningAlert(str);
|
||||
return false;
|
||||
}
|
||||
|
||||
fp = runTool(ifName);
|
||||
fp = run_tool(if_name);
|
||||
if (fp == NULL) {
|
||||
snprintf(str, sizeof(str)-1, "Unable to run ether slave helper tool.");
|
||||
snprintf(str, sizeof(str), "Unable to run ether slave helper tool.");
|
||||
WarningAlert(str);
|
||||
return false;
|
||||
}
|
||||
@ -1189,20 +1187,20 @@ static bool openEtherSlave(const char *ifName)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int readpacket()
|
||||
static int read_packet()
|
||||
{
|
||||
int index;
|
||||
unsigned short *pktLen;
|
||||
unsigned short *pkt_len;
|
||||
int ret = -1;
|
||||
|
||||
pktLen = (unsigned short *)packet_buffer;
|
||||
pkt_len = (unsigned short *)packet_buffer;
|
||||
|
||||
index = 0;
|
||||
while (1) {
|
||||
if (index < 2) {
|
||||
ret = read(fd, packet_buffer + index, 2 - index);
|
||||
} else {
|
||||
ret = read(fd, packet_buffer + index, *pktLen - index + 2);
|
||||
ret = read(fd, packet_buffer + index, *pkt_len - index + 2);
|
||||
}
|
||||
|
||||
if (ret < 1) {
|
||||
@ -1213,13 +1211,13 @@ static int readpacket()
|
||||
index += ret;
|
||||
|
||||
if (index > 1) {
|
||||
if(*pktLen > (sizeof(packet_buffer) + 2)) {
|
||||
fprintf(stderr, "%s: pktLen (%d) too large.\n", __func__, *pktLen);
|
||||
if (*pkt_len > (sizeof(packet_buffer) + 2)) {
|
||||
fprintf(stderr, "%s: pkt_len (%d) too large.\n", __func__, *pkt_len);
|
||||
break;
|
||||
}
|
||||
|
||||
if(index == (*pktLen + 2)) {
|
||||
ret = *pktLen;
|
||||
if (index == (*pkt_len + 2)) {
|
||||
ret = *pkt_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user