<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Do you know the right way?<BR>
<BR>
PPC_LINUX "just worked", and I can check Solaris and Darwin.<BR>
<BR>
I don't want to edit /etc/hosts -- I use DHCP.<BR>
Though DHCP has been bothering me -- only for some of my machines do names resolve, so I end using IP addresses, which change sometimes, and I loop over them running ssh to all of them and "see what I get", not ideal.<BR>
<BR>
- Jay<BR><BR><BR>> To: jay.krell@cornell.edu<BR>> Date: Sun, 11 Jan 2009 08:02:18 -0800<BR>> From: mika@async.caltech.edu<BR>> CC: m3devel@elegosoft.com<BR>> Subject: Re: [M3devel] Juno (X) networking problem on AMD64_FREEBSD<BR>> <BR>> This is a screwy thing in Modula-3. A bug I would call it.<BR>> <BR>> I've noticed a lot of networking M3 programs don't work right unless<BR>> the return value of Unix's "hostname" maps to a real IP address via<BR>> gethostbyname. I accomplish it in practice by adding my hostname<BR>> to /etc/hosts.<BR>> <BR>> This is obviously not the right way to fix it... <BR>> <BR>> Mika<BR>> <BR>> Jay writes:<BR>> >--_9e67232c-a064-417d-879e-227a77e310f9_<BR>> >Content-Type: text/plain; charset="iso-8859-1"<BR>> >Content-Transfer-Encoding: quoted-printable<BR>> ><BR>> ><BR>> >Hi. Unix network programming question..<BR>> >AMD64_FREEBSD:<BR>> >$DISPLAY is set to point back to Cygwin host.It works for PPC_LINUX.<BR>> >[jay@fbsdamd64a /cm3/bin]$ ./Juno<BR>> >****** runtime error:*** Exception "IPError.FatalError" not in RAISES li=<BR>> >st*** file "../src/common/IPError.m3"=2C line 27***<BR>> >Abort trap: 6 (core dumped)[jay@fbsdamd64a /cm3/bin]$<BR>> >IP.m3:<BR>> >=20<BR>> >PROCEDURE GetHostAddr(): Address =3D VAR hname: ARRAY [0..255] OF CHAR=3B =<BR>> > BEGIN LOCK mu DO IF Unix.gethostname(ADR(hname[0])=2C BYTESIZE(hna=<BR>> >me)) # 0 THEN IPError.Die ()=3B END=3B VAR h :=3D Unetdb.g=<BR>> >ethostbyname(ADR(hname[0]))=3B BEGIN IF h =3D NIL THEN IPError.Die()=<BR>> >=3B END=3B RETURN GetAddress(h)=3B END=3B END=3B END GetHos=<BR>> >tAddr=3B<BR>> >PROCEDURE GetAddress (ent: Unetdb.struct_hostent_star): Address =3D VAR ua=<BR>> >: Uin.struct_in_addr=3B BEGIN <* ASSERT ent.h_length <=3D BYTESIZE(Addr=<BR>> >ess) *> ua :=3D LOOPHOLE(ent.h_addr_list=2C UNTRACED =<BR>> >REF UNTRACED REF Uin.struct_in_addr)^^=3B RETURN LOOPHOLE(ua.s_addr=2C A=<BR>> >ddress)=3B END GetAddress=3B<BR>> >=20<BR>> >gethostbyname is failing.<BR>> >=20<BR>> >Analogous C code also fails:<BR>> >=20<BR>> >[jay@fbsdamd64a /cm3/bin]$ cat ~/5.c#include <assert.h>#include <netdb.h>#i=<BR>> >nclude <stdio.h>#include <errno.h>typedef struct hostent hostent_t=3B<BR>> >=20<BR>> >int main(){ char hostname[200]=3B hostent_t* h=3B int i=3B<BR>> > i =3D gethostname(hostname=2C 200)=3B assert(i =3D=3D 0)=3B printf("hostna=<BR>> >me: %s\n"=2C hostname)=3B h =3D gethostbyname(hostname)=3B herror("foo")=3B=<BR>> > printf("%p %d %d\n"=2C h=2C errno=2C h_errno)=3B assert(h)=3B return 0=3B}<BR>> >=20<BR>> >herror says "unknown host".<BR>> >Stack is:<BR>> > at ../src/runtime/ex_frame/RTExFrame.m3:58#13 0x0000000801a7f2b3 in RTH=<BR>> >ooks__Raise (M3_AJWxb1_ex=3DError accessing memory address 0x8000ffffd278: =<BR>> >Bad address.) at ../src/runtime/common/RTHooks.m3:79#14 0x000000080169c8=<BR>> >d3 in IPError__Die () at ../src/common/IPError.m3:27#15 0x0000000801698a3e =<BR>> >in IP__GetHostAddr (M3_BCxjPn__result=3DError accessing memory address 0x80=<BR>> >00ffffd338: Bad address.) at ../src/POSIX/IP.m3:82#16 0x00000008012133d0=<BR>> > in XSharedMem__SameHost (M3_AQuuui_trsl=3DError accessing memory address 0=<BR>> >x8000ffffd4d8: Bad address.) at ../src/xvbt/XSharedMem.m3:96#17 0x000000=<BR>> >0801212ab7 in XSharedMem__InitXClient (M3_AQuuui_v=3DError accessing memory=<BR>> > address 0x8000ffffd648: Bad address.) at ../src/xvbt/XSharedMem.m3:29#1=<BR>> >8 0x0000000801211819 in XExtensions__InitXClient (M3_AQuuui_xclient=3DError=<BR>> > accessing memory address 0x8000ffffd7f8: Bad address.) at ../src/xvbt/X=<BR>> >Extensions.m3:14#19 0x00000008012467a4 in XClientF__Connect (M3_Bd56fi_inst=<BR>> >=3D0x1879b=2C M3_AQuuui_trsl=3D0x6) at ../src/xvbt/XClientF.m3:583---Typ=<BR>> >e <return> to continue=2C or q <return> to quit---(More stack frames follow=<BR>> >...)(gdb)<BR>> >(* return TRUE if server and client are on same host *)PROCEDURE SameHost (=<BR>> >trsl: XClient.T): BOOLEAN =3D VAR display :=3D DisplayH=<BR>> >ost(trsl)=3B displayAddr: IP.Address=3B BEGIN IF display =3D NIL THE=<BR>> >N RETURN TRUE=3B END=3B<BR>> > TRY IF NOT IP.GetHostByName(display=2C displayAddr) THEN RETURN FA=<BR>> >LSE=3B END=3B RETURN displayAddr =3D IP.GetHostAddr()=3B EXCEPT =<BR>> >| IP.Error =3D> RETURN FALSE=3B END=3B END SameHost=3B<BR>> >=20<BR>> >Thoughts?<BR>> >=20<BR>> >Perhaps my network isn't setup well=2C like I should add the local machine =<BR>> >to /etc/hosts.I think this can be made to fail gracefully though.It seems l=<BR>> >ike it has nothing to do with AMD64_FREEBSD=2C but could have to do with Fr=<BR>> >eeBSD.<BR>> >=20<BR>> >Seems like SocketPosix has nearly the exact same code but appearsmore forgi=<BR>> >ving.. IOError instead of Fatal?<BR>> >=20<BR>> >SocketPosix.m3:<BR>> >=20<BR>> >PROCEDURE GetHostAddr (): Address RAISES {OSError.E} =3D VAR host : AR=<BR>> >RAY [0..255] OF CHAR=3B info : Unetdb.struct_hostent_star=3B ua : U=<BR>> >in.struct_in_addr=3B BEGIN IF Unix.gethostname (ADR (host[0])=2C BYTESI=<BR>> >ZE (host)) # 0 THEN IOError (Unexpected)=3B END=3B<BR>> > info :=3D Unetdb.gethostbyname (ADR (host[0]))=3B IF info =3D NIL TH=<BR>> >EN IOError (Unexpected)=3B END=3B <* ASSERT info.h_length <=3D BYTESIZE =<BR>> >(Address) *><BR>> > ua :=3D LOOPHOLE(info.h_addr_list=2C UNTRACED REF UNT=<BR>> >RACED REF Uin.struct_in_addr)^^=3B RETURN LOOPHOLE (ua.s_addr=2C Address=<BR>> >)=3B END GetHostAddr=3B<BR>> >=20<BR>> >=20<BR>> >It is again disappointing to see such code duplication.<BR>> >=20<BR>> >=20<BR>> >I guess SameHost can duplicate the logic to predict the error state and ret=<BR>> >urn false upon error?<BR>> >Duplicating the logic for a third time. :(<BR>> >=20<BR>> > - Jay=<BR>> ><BR>> >--_9e67232c-a064-417d-879e-227a77e310f9_<BR>> >Content-Type: text/html; charset="iso-8859-1"<BR>> >Content-Transfer-Encoding: quoted-printable<BR>> ><BR>> ><html><BR>> ><head><BR>> ><style><BR>> >.hmmessage P<BR>> >{<BR>> >margin:0px=3B<BR>> >padding:0px<BR>> >}<BR>> >body.hmmessage<BR>> >{<BR>> >font-size: 10pt=3B<BR>> >font-family:Verdana<BR>> >}<BR>> ></style><BR>> ></head><BR>> ><body class=3D'hmmessage'><BR>> >Hi. Unix network programming question..<BR><BR>> ><BR>AMD64_FREEBSD:<BR><BR>> ><BR>$DISPLAY is set to point back to Cygwin host.<BR>It works for PPC_LINUX=<BR>> >.<BR><BR>> ><BR>[jay@fbsdamd64a /cm3/bin]$ ./Juno<BR><BR>> ><BR>***<BR>*** runtime error:<BR>*** =3B =3B =3B Exception "IPE=<BR>> >rror.FatalError" not in RAISES list<BR>*** =3B =3B =3B file "..=<BR>> >/src/common/IPError.m3"=2C line 27<BR>***<BR><BR>> ><BR>Abort trap: 6 (core dumped)<BR>[jay@fbsdamd64a /cm3/bin]$<BR><BR>> ><BR>IP.m3:<BR><BR>> > =3B<BR><BR>> >PROCEDURE GetHostAddr(): Address =3D<BR> =3B VAR hname: ARRAY [0..255] =<BR>> OF CHAR=3B<BR> =3B BEGIN<BR> =3B =3B =3B LOCK mu DO<BR>&nbs=<BR>> >p=3B =3B =3B =3B =3B IF Unix.gethostname(ADR(hname[0])=2C B=<BR>> >YTESIZE(hname)) # 0 THEN<BR> =3B =3B =3B =3B =3B =<BR>> >=3B =3B IPError.Die ()=3B<BR> =3B =3B =3B =3B =3B E=<BR>> >ND=3B<BR> =3B =3B =3B =3B =3B VAR h :=3D Unetdb.gethost=<BR>> >byname(ADR(hname[0]))=3B BEGIN<BR> =3B =3B =3B =3B =3B&=<BR>> >nbsp=3B =3B IF h =3D NIL THEN IPError.Die()=3B END=3B<BR> =3B =<BR>> >=3B =3B =3B =3B =3B =3B RETURN GetAddress(h)=3B<BR>&nbs=<BR>> >p=3B =3B =3B =3B =3B END=3B<BR> =3B =3B =3B END=<BR>> >=3B<BR> =3B END GetHostAddr=3B<BR><BR>> ><BR>PROCEDURE GetAddress (ent: Unetdb.struct_hostent_star): Address =3D<BR>=<BR>> > =3B VAR ua: Uin.struct_in_addr=3B<BR> =3B BEGIN<BR> =3B =<BR>> >=3B =3B <=3B* ASSERT ent.h_length <=3B=3D BYTESIZE(Address) *>=3B=<BR>> ><BR> =3B =3B =3B ua :=3D LOOPHOLE(ent.h_addr_list=2C<BR> =<BR>> >=3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=<BR>> > =3B =3B =3B =3B =3B =3B =3B =3B =3B UN=<BR>> >TRACED REF UNTRACED REF Uin.struct_in_addr)^^=3B<BR> =3B =3B =<BR>> >=3B RETURN LOOPHOLE(ua.s_addr=2C Address)=3B<BR> =3B END GetAddress=3B<=<BR>> >BR><BR>> > =3B<BR><BR>> >gethostbyname is failing.<BR><BR>> ><BR> =3B<BR><BR>> >Analogous C code also fails:<BR><BR>> > =3B<BR><BR>> ><BR>[jay@fbsdamd64a /cm3/bin]$ cat ~/5.c<BR>#include <=3Bassert.h>=3B<B=<BR>> >R>#include <=3Bnetdb.h>=3B<BR>#include <=3Bstdio.h>=3B<BR>#include =<BR>> ><=3Berrno.h>=3B<BR>typedef struct hostent hostent_t=3B<BR><BR>> > =3B<BR><BR>> >int main()<BR>{<BR> =3Bchar hostname[200]=3B<BR> =3Bhostent_t* h=3B=<BR>> ><BR> =3Bint i=3B<BR><BR>> > =3Bi =3D gethostname(hostname=2C 200)=3B<BR> =3Bassert(i =3D=3D 0)=<BR>> >=3B<BR> =3Bprintf("hostname: %s\n"=2C hostname)=3B<BR> =3Bh =3D get=<BR>> >hostbyname(hostname)=3B<BR> =3Bherror("foo")=3B<BR> =3Bprintf("%p %=<BR>> >d %d\n"=2C h=2C errno=2C h_errno)=3B<BR> =3Bassert(h)=3B<BR> =3Bret=<BR>> >urn 0=3B<BR>}<BR><BR>> > =3B<BR><BR>> >herror says "unknown host".<BR><BR>> ><BR>Stack is:<BR><BR>> > =3B =3B =3B at ../src/runtime/ex_frame/RTExFrame.m3:58<BR>#13 =<BR>> >0x0000000801a7f2b3 in RTHooks__Raise (M3_AJWxb1_ex=3DError accessing memory=<BR>> > ad<BR>dress 0x8000ffffd278: Bad address.<BR>)<BR> =3B =3B =3B =<BR>> >at ../src/runtime/common/RTHooks.m3:79<BR>#14 0x000000080169c8d3 in IPError=<BR>> >__Die () at ../src/common/IPError.m3:27<BR>#15 0x0000000801698a3e in IP__Ge=<BR>> >tHostAddr (M3_BCxjPn__result=3DError accessing mem<BR>ory address 0x8000fff=<BR>> >fd338: Bad address.<BR>)<BR> =3B =3B =3B at ../src/POSIX/IP.m3:=<BR>> >82<BR>#16 0x00000008012133d0 in XSharedMem__SameHost (M3_AQuuui_trsl=3DErro=<BR>> >r accessing m<BR>emory address 0x8000ffffd4d8: Bad address.<BR>)<BR> =<BR>> >=3B =3B =3B at ../src/xvbt/XSharedMem.m3:96<BR>#17 0x0000000801212a=<BR>> >b7 in XSharedMem__InitXClient (M3_AQuuui_v=3DError accessing m<BR>emory add=<BR>> >ress 0x8000ffffd648: Bad address.<BR>)<BR> =3B =3B =3B at ../sr=<BR>> >c/xvbt/XSharedMem.m3:29<BR>#18 0x0000000801211819 in XExtensions__InitXClie=<BR>> >nt (M3_AQuuui_xclient=3DError acce<BR>ssing memory address 0x8000ffffd7f8: =<BR>> >Bad address.<BR>)<BR> =3B =3B =3B at ../src/xvbt/XExtensions.m3=<BR>> >:14<BR>#19 0x00000008012467a4 in XClientF__Connect (M3_Bd56fi_inst=3D0x1879=<BR>> >b=2C<BR> =3B =3B =3B M3_AQuuui_trsl=3D0x6) at ../src/xvbt/XClie=<BR>> >ntF.m3:583<BR>---Type <=3Breturn>=3B to continue=2C or q <=3Breturn&g=<BR>> >t=3B to quit---<BR>(More stack frames follow...)<BR>(gdb)<BR><BR>> ><BR>(* return TRUE if server and client are on same host *)<BR>PROCEDURE Sa=<BR>> >meHost (trsl: XClient.T): BOOLEAN =3D<BR> =3B VAR<BR> =3B =3B&n=<BR>> >bsp=3B display =3B =3B =3B =3B =3B =3B =3B =<BR>> >=3B =3B =3B =3B =3B =3B =3B =3B =3B :=3D Di=<BR>> >splayHost(trsl)=3B<BR> =3B =3B =3B displayAddr: IP.Address=3B<B=<BR>> >R> =3B BEGIN<BR> =3B =3B =3B IF display =3D NIL THEN RETURN=<BR>> > TRUE=3B END=3B<BR><BR>> > =3B =3B =3B TRY<BR> =3B =3B =3B =3B =3B IF=<BR>> > NOT IP.GetHostByName(display=2C displayAddr) THEN RETURN FALSE=3B END=3B<B=<BR>> >R> =3B =3B =3B =3B =3B RETURN displayAddr =3D IP.GetHos=<BR>> >tAddr()=3B<BR> =3B =3B =3B EXCEPT<BR> =3B =3B =3B |=<BR>> > IP.Error =3D>=3B RETURN FALSE=3B<BR> =3B =3B =3B END=3B<BR>&=<BR>> >nbsp=3B END SameHost=3B<BR><BR>> > =3B<BR><BR>> >Thoughts?<BR><BR>> > =3B<BR><BR>> ><BR>Perhaps my network isn't setup well=2C like I should add the local mach=<BR>> >ine to /etc/hosts.<BR>I think this can be made to fail gracefully though.<B=<BR>> >R>It seems like it has nothing to do with AMD64_FREEBSD=2C but could have t=<BR>> >o do with FreeBSD.<BR><BR>> ><BR> =3B<BR><BR>> >Seems like SocketPosix has nearly the exact same code but appears<BR>more f=<BR>> >orgiving.. IOError instead of Fatal?<BR><BR>> > =3B<BR><BR>> ><BR>SocketPosix.m3:<BR><BR>> > =3B<BR><BR>> ><BR>PROCEDURE GetHostAddr (): Address<BR> =3B RAISES {OSError.E} =3D<BR=<BR>> >> =3B VAR<BR> =3B =3B =3B host : ARRAY [0..255] OF CHAR=3B<=<BR>> >BR> =3B =3B =3B info : Unetdb.struct_hostent_star=3B<BR> =<BR>> >=3B =3B =3B ua =3B =3B : Uin.struct_in_addr=3B<BR> =3B =<BR>> >BEGIN<BR> =3B =3B =3B IF Unix.gethostname (ADR (host[0])=2C BYT=<BR>> >ESIZE (host)) # 0 THEN<BR> =3B =3B =3B =3B =3B IOError =<BR>> >(Unexpected)=3B<BR> =3B =3B =3B END=3B<BR><BR>> > =3B =3B =3B info :=3D Unetdb.gethostbyname (ADR (host[0]))=3B<=<BR>> >BR> =3B =3B =3B IF info =3D NIL THEN IOError (Unexpected)=3B EN=<BR>> >D=3B<BR> =3B =3B =3B <=3B* ASSERT info.h_length <=3B=3D BYT=<BR>> >ESIZE (Address) *>=3B<BR><BR>> > =3B =3B =3B ua :=3D LOOPHOLE(info.h_addr_list=2C<BR> =3B&n=<BR>> >bsp=3B =3B =3B =3B =3B =3B =3B =3B =3B =<BR>> >=3B =3B =3B =3B =3B =3B =3B =3B UNTRACED REF UN=<BR>> >TRACED REF Uin.struct_in_addr)^^=3B<BR> =3B =3B =3B RETURN LOOP=<BR>> >HOLE (ua.s_addr=2C Address)=3B<BR> =3B END GetHostAddr=3B<BR><BR>> > =3B<BR><BR>> > =3B<BR><BR>> >It is again disappointing to see such code duplication.<BR><BR>> > =3B<BR><BR>> > =3B<BR><BR>> >I guess =3BSameHost can duplicate the logic to predict the error state =<BR>> >and return false =3Bupon error?<BR><BR>> >Duplicating the logic for a third time. :(<BR><BR>> > =3B<BR><BR>> ><BR> =3B- Jay<BR><BR></body><BR>> ></html>=<BR>> ><BR>> >--_9e67232c-a064-417d-879e-227a77e310f9_--<BR><BR></body>
</html>