tivo: clean up some error checking

This commit is contained in:
Justin Maggard 2014-04-18 16:18:00 -07:00
parent 08c21f39d1
commit 27a29f9e92
2 changed files with 20 additions and 16 deletions

View File

@ -109,18 +109,21 @@ getBcastAddress(void)
uint32_t ret = INADDR_BROADCAST;
s = socket(PF_INET, SOCK_STREAM, 0);
if (!s)
return ret;
memset(&ifc, '\0', sizeof(ifc));
ifc.ifc_len = sizeof(ifr);
ifc.ifc_req = ifr;
if(ioctl(s, SIOCGIFCONF, &ifc) < 0) {
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
{
DPRINTF(E_ERROR, L_TIVO, "Error getting interface list [%s]\n", strerror(errno));
close(s);
return ret;
}
count = ifc.ifc_len / sizeof(struct ifreq);
for(i = 0; i < count; i++)
for (i = 0; i < count; i++)
{
memcpy(&addr, &ifr[i].ifr_addr, sizeof(addr));
if(strcmp(inet_ntoa(addr.sin_addr), lan_addr[0].str) == 0)
@ -149,21 +152,22 @@ getBcastAddress(void)
void
sendBeaconMessage(int fd, struct sockaddr_in * client, int len, int broadcast)
{
char * mesg;
int mesg_len;
char msg[512];
int msg_len;
mesg_len = asprintf(&mesg, "TiVoConnect=1\n"
"swversion=1.0\n"
"method=%s\n"
"identity=%s\n"
"machine=%s\n"
"platform=pc/minidlna\n"
"services=TiVoMediaServer:%d/http\n",
broadcast ? "broadcast" : "connected",
uuidvalue, friendly_name, runtime_vars.port);
msg_len = snprintf(msg, sizeof(msg), "TiVoConnect=1\n"
"swversion=1.0\n"
"method=%s\n"
"identity=%s\n"
"machine=%s\n"
"platform=pc/minidlna\n"
"services=TiVoMediaServer:%d/http\n",
broadcast ? "broadcast" : "connected",
uuidvalue, friendly_name, runtime_vars.port);
if (msg_len < 0)
return;
DPRINTF(E_DEBUG, L_TIVO, "Sending TiVo beacon to %s\n", inet_ntoa(client->sin_addr));
sendto(fd, mesg, mesg_len, 0, (struct sockaddr*)client, len);
free(mesg);
sendto(fd, msg, msg_len, 0, (struct sockaddr*)client, len);
}
/*

View File

@ -153,7 +153,7 @@ is_tivo_file(const char *path)
/* read file header */
fd = open(path, O_RDONLY);
if( !fd )
if( fd < 0 )
return 0;
if( read(fd, buf, 5) < 5 )
buf[0] = 'X';