on-screen network error messages

This commit is contained in:
zicodxx 2007-02-07 12:50:08 +00:00
parent 0adb299c15
commit 4783d9263d
5 changed files with 26 additions and 21 deletions

View file

@ -22,6 +22,7 @@ extern "C" {
#include "ipclient.h"
static int mysock=-1;
extern int nm_messagebox(char *title, int nchoices, ...);
/* Do hostname resolve on name "buf" and return the address in buffer "qhbuf".
*/
@ -115,7 +116,7 @@ int arch_ip_get_my_addr(u_short myport){
ip_addr addr;
if ((sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0)
FAIL("Creating socket() failure during broadcast detection: %m");
FAIL("Creating socket() failure during broadcast detection:\n%m");
#ifdef SIOCGIFCOUNT
if (ioctl(sock,SIOCGIFCOUNT,&cnt))
@ -127,7 +128,7 @@ int arch_ip_get_my_addr(u_short myport){
chk(ifconf.ifc_req=(struct ifreq *)alloca((ifconf.ifc_len=cnt*sizeof(struct ifreq))));
if (ioctl(sock,SIOCGIFCONF,&ifconf)||ifconf.ifc_len%sizeof(struct ifreq)) {
close(sock);
FAIL("ioctl(SIOCGIFCONF) failure during broadcast detection: %m");
FAIL("ioctl(SIOCGIFCONF) failure during broadcast detection:\n%m");
}
cnt=ifconf.ifc_len/sizeof(struct ifreq);
// chk(broads=malloc(cnt*sizeof(*broads)));
@ -135,14 +136,14 @@ int arch_ip_get_my_addr(u_short myport){
for (i=j=0;i<cnt;i++) {
if (ioctl(sock,SIOCGIFFLAGS,ifconf.ifc_req+i)) {
close(sock);
FAIL("ioctl(udp,\"%s\",SIOCGIFFLAGS) error: %m",ifconf.ifc_req[i].ifr_name);
FAIL("ioctl(udp,\"%s\",SIOCGIFFLAGS) error:\n%m",ifconf.ifc_req[i].ifr_name);
}
if (((ifconf.ifc_req[i].ifr_flags&IF_REQFLAGS)!=IF_REQFLAGS)||
(ifconf.ifc_req[i].ifr_flags&IF_NOTFLAGS))
continue;
if (ioctl(sock,SIOCGIFDSTADDR,ifconf.ifc_req+i)) {
close(sock);
FAIL("ioctl(udp,\"%s\",SIOCGIFDSTADDR) error: %m",ifconf.ifc_req[i].ifr_name);
FAIL("ioctl(udp,\"%s\",SIOCGIFDSTADDR) error:\n%m",ifconf.ifc_req[i].ifr_name);
}
sinp=(struct sockaddr_in *)&ifconf.ifc_req[i].ifr_netmask ;
@ -172,12 +173,12 @@ int arch_ip_open_socket(int port){
int val_one=1;
if ((mysock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
mysock = -1;
FAIL("socket() creation failed on port %d: %m",port);
FAIL("socket() creation failed on port %d:\n%m",port);
}
if (setsockopt(mysock,SOL_SOCKET,SO_BROADCAST,&val_one,sizeof(val_one))) {
if (close(mysock)) msg("close() failed during error recovery: %m");
mysock=-1;
FAIL("setsockopt(SO_BROADCAST) failed: %m");
FAIL("setsockopt(SO_BROADCAST) failed:\n%m");
}
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
@ -186,7 +187,7 @@ int arch_ip_open_socket(int port){
if (bind(mysock,(struct sockaddr *)&sin,sizeof(sin))) {
if (close(mysock)) msg("close() failed during error recovery: %m");
mysock=-1;
FAIL("bind() to UDP port %d failed: %m",port);
FAIL("bind() to UDP port %d failed:\n%m",port);
}
return 0;

View file

@ -73,6 +73,7 @@
#include "args.h"
extern unsigned char ipx_MyAddress[10];
extern int nm_messagebox(char *title, int nchoices, ...);
// #define UDPDEBUG
@ -142,7 +143,7 @@ static void chk(void *p)
exit(EXIT_FAILURE);
}
#define FAIL(m...) do { msg(m); return -1; } while (0)
#define FAIL(m...) do{ nm_messagebox("Error", 1, "Ok", ##m); return -1; } while (0)
/* Find as much as MAX_BRDINTERFACES during local iface autoconfiguration.
* Note that more interfaces can be added during manual configuration
@ -191,7 +192,7 @@ struct sockaddr_in *sinp,*sinmp;
free(broads);
if ((sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0)
FAIL("Creating socket() failure during broadcast detection: %m");
FAIL("Creating socket() failure during broadcast detection:\n%m");
#ifdef SIOCGIFCOUNT
if (ioctl(sock,SIOCGIFCOUNT,&cnt))
@ -203,7 +204,7 @@ struct sockaddr_in *sinp,*sinmp;
chk(ifconf.ifc_req=alloca((ifconf.ifc_len=cnt*sizeof(struct ifreq))));
if (ioctl(sock,SIOCGIFCONF,&ifconf)||ifconf.ifc_len%sizeof(struct ifreq)) {
close(sock);
FAIL("ioctl(SIOCGIFCONF) failure during broadcast detection: %m");
FAIL("ioctl(SIOCGIFCONF) failure during broadcast detection:\n%m");
}
cnt=ifconf.ifc_len/sizeof(struct ifreq);
chk(broads=malloc(cnt*sizeof(*broads)));
@ -211,14 +212,14 @@ struct sockaddr_in *sinp,*sinmp;
for (i=j=0;i<cnt;i++) {
if (ioctl(sock,SIOCGIFFLAGS,ifconf.ifc_req+i)) {
close(sock);
FAIL("ioctl(udp,\"%s\",SIOCGIFFLAGS) error: %m",ifconf.ifc_req[i].ifr_name);
FAIL("ioctl(udp,\"%s\",SIOCGIFFLAGS) error:\n%m",ifconf.ifc_req[i].ifr_name);
}
if (((ifconf.ifc_req[i].ifr_flags&IF_REQFLAGS)!=IF_REQFLAGS)||
(ifconf.ifc_req[i].ifr_flags&IF_NOTFLAGS))
continue;
if (ioctl(sock,(ifconf.ifc_req[i].ifr_flags&IFF_BROADCAST?SIOCGIFBRDADDR:SIOCGIFDSTADDR),ifconf.ifc_req+i)) {
close(sock);
FAIL("ioctl(udp,\"%s\",SIOCGIF{DST/BRD}ADDR) error: %m",ifconf.ifc_req[i].ifr_name);
FAIL("ioctl(udp,\"%s\",SIOCGIF{DST/BRD}ADDR) error:\n%m",ifconf.ifc_req[i].ifr_name);
}
sinp =(struct sockaddr_in *)&ifconf.ifc_req[i].ifr_broadaddr;
@ -411,20 +412,20 @@ struct sockaddr_in sin;
if ((sk->fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
sk->fd = -1;
FAIL("socket() creation failed on port %d: %m",port);
FAIL("socket() creation failed on port %d:\n%m",port);
}
if (setsockopt(sk->fd,SOL_SOCKET,SO_BROADCAST,&val_one,sizeof(val_one))) {
if (close(sk->fd)) msg("close() failed during error recovery: %m");
if (close(sk->fd)) msg("close() failed during error recovery:\n%m");
sk->fd=-1;
FAIL("setsockopt(SO_BROADCAST) failed: %m");
FAIL("setsockopt(SO_BROADCAST) failed:\n%m");
}
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
sin.sin_port=htons(baseport);
if (bind(sk->fd,(struct sockaddr *)&sin,sizeof(sin))) {
if (close(sk->fd)) msg("close() failed during error recovery: %m");
if (close(sk->fd)) msg("close() failed during error recovery:\n%m");
sk->fd=-1;
FAIL("bind() to UDP port %d failed: %m",baseport);
FAIL("bind() to UDP port %d failed:\n%m",baseport);
}
open_sockets++;

View file

@ -20,6 +20,7 @@ extern "C" {
//static int dynamic_socket=0x402;
static int mysock=-1;
extern int nm_messagebox(char *title, int nchoices, ...);
//static unsigned char qhbuf[6];
@ -124,12 +125,12 @@ int arch_ip_open_socket(int port){
if ((mysock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
mysock = -1;
FAIL("socket() creation failed on port %d: %m",port);
FAIL("socket() creation failed on port %d:\n%m",port);
}
if (setsockopt(mysock,SOL_SOCKET,SO_BROADCAST,(char*)&val_one,sizeof(val_one))) {
if (close(mysock)) msg("close() failed during error recovery: %m");
mysock=-1;
FAIL("setsockopt(SO_BROADCAST) failed: %m");
FAIL("setsockopt(SO_BROADCAST) failed:\n%m");
}
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=htonl(INADDR_ANY);
@ -138,7 +139,7 @@ int arch_ip_open_socket(int port){
if (bind(mysock,(struct sockaddr *)&sin,sizeof(sin))) {
if (close(mysock)) msg("close() failed during error recovery: %m");
mysock=-1;
FAIL("bind() to UDP port %d failed: %m",port);
FAIL("bind() to UDP port %d failed:\n%m",port);
}
return 0;

View file

@ -4,6 +4,7 @@ D1X-Rebirth Changelog
--------
main/game.c: expanded help menu and fixed d1x help
iff/iff.c: amd64 fixes, code cleanup
arch/linux/arch_ip.cpp, arch/linux/ipx_udp.c, arch/win32/arch_ip.cpp, main/ipclient.h: on-screen network error messages
20070206
--------

View file

@ -13,6 +13,7 @@ extern "C"{
#include "types.h"
#include "ipx.h"
#include "ipx_drv.h"
#include "newmenu.h"
void ip_sendtoall(char *buf,int len);
int ip_connect_manual(char *textaddr);//make it extern C so that it can be called from .c files.
//void ip_portshift(ubyte*qhbuf,const char *cs);
@ -48,7 +49,7 @@ static inline void msg(const char *fmt,...)
putchar('\n');
}
#define FAIL(m...) do { msg(m); return -1; } while (0)
#define FAIL(m...) do{ nm_messagebox("Error", 1, "Ok", ##m); return -1; } while (0)
static inline void chk(void *p){
if (p) return;