| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I'm not quite able to establish a connection with IRC. It is telling me, from what I can tell (don't have any expericence with sockets) that SockAddr.family isn't AF_INET Running strace gives me this (manual line breaks with \ ): socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 connect(3, {sa_family=0xf71c /* AF_??? */, \ sa_data="\377\277\347\'\5\10\230\223\6\10\2\0\0\0" }, 20) = -1 EAFNOSUPPORT (Address family not supported by protocol) send(3, "NICK 6", 8, 0) = -1 EPIPE (Broken pipe) --- SIGPIPE (Brokenpipe) @ 0 (0) --- +++ killed by SIGPIPE +++ Here is the code I'm using (I apologize if code isn't desired in the group) the applicable procedure for this particular problem is connect, but I've included the whole thing in case anyone wants to advise me of any other mistakes I might be making.: <*+ M2EXTENSIONS *> <*+ M2ADDTYPES *> <*+ CSTDLIB *> MODULE connect3; IMPORT Sockets; IMPORT Internet; IMPORT NetDB; IMPORT Strings; IMPORT SYSTEM; IMPORT STextIO; IMPORT SWholeIO; CONST maxString = 512; TYPE strType = ARRAY [0..maxString] OF CHAR; VAR s : Sockets.Socket; nick, rname, nspass, server, msg : strType; sent, rcvd : CARDINAL; PROCEDURE ["C"] / htons (numb : CARDINAL) : CARDINAL; PROCEDURE connect (VAR srv : strType; port : CARDINAL); VAR hp : NetDB.HostEntPtr; sa, target : Sockets.SockAddr; done : BOOLEAN; BEGIN hp := NetDB.gethostbyname(srv); (*sa.in_addr.addr := SYSTEM.CARD32(hp^.h_addr_list^);*) sa.family := Sockets.AF_INET; sa.in_addr.addr := SYSTEM.CARD32(htons(hp^.h_addr_list^[0]^)); sa.in_addr.port := SYSTEM.CARD16(htons(port)); sa.in_addr.zero := Internet.Zero8; s := Sockets.socket(Sockets.AF_INET, Sockets.SOCK_STREAM, Sockets.AF_UNSPEC); IF NOT Sockets.connect(s, target, SIZE(target)) THEN STextIO.WriteString("Connect attempt failed."); END; (* IF *) END connect; PROCEDURE login (VAR nick : strType; VAR rname : strType; VAR nspass : strType); VAR msg : strType; sent : CARDINAL; BEGIN msg := "NICK :"; Strings.Concat(msg, nick, msg); sent := Sockets.send(s, msg, LENGTH(msg),0); SWholeIO.WriteCard(sent, 2); msg := "USER :"; Strings.Concat(msg, nick, msg); Strings.Concat(msg, " * 0 :", msg); Strings.Concat(msg, rname, msg); sent := Sockets.send(s, msg, LENGTH(msg),0); msg := "JOIN :"; Strings.Concat(msg,"#atari-2",msg); sent := Sockets.send(s, msg, LENGTH(msg),0); END login; PROCEDURE logout (reason : strType); VAR msg : strType; sent, rcvd : CARDINAL; BEGIN IF (reason # "") THEN msg := "QUIT :"; Strings.Concat(msg, reason, msg); ELSE msg := "QUIT :"; END; (* IF *) sent := Sockets.send(s, msg, LENGTH(msg),0); END logout; BEGIN server := "irc.freenode.net"; nick := "p6"; rname := "p6"; nspass := ""; connect(server,6667); login(nick, rname, nspass); rcvd := Sockets.recv(s, msg, SIZE(strType), 0); SWholeIO.WriteCard(rcvd, 2); END connect3. I appreciate your having looked, Terry -- Terry Ross | qnr | <terry at aliboom dot com> | http://linux.aliboom.com Key BE84 EC1D FC94 D97B 9063 AD15 0F38 193A E579 6C4D Source Mage GNU/Linux: http://www.sourcemage.org - Tome team & News Guru |
|
#2
| |||
| |||
| On Tue, 26 Apr 2005 23:59:26 -0500, qnr wrote: > I'm not quite able to establish a connection with IRC. It is telling me, > from what I can tell (don't have any expericence with sockets) that > SockAddr.family isn't AF_INET Hmmmm well, I replaced target with sa in Sockets.connect, and it is doing something now. Interesting thing is, I had replaced sa with target, because I was getting the error shown in the original message, and looking at the procedure I saw it was designated (* IN *), so I thought it wanted an empty one. Strace gives me this now. I don't know if I'm locked up because I wasn't supposed to change the byte order of the address and port, or if it's just waiting form me to take some action socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(1032), sin_addr=inet_addr("26.11.245.183")}, 20 (after which, the connection times out, so that sounds positive.... Terry -- Terry Ross | qnr | <terry at aliboom dot com> | http://linux.aliboom.com Key BE84 EC1D FC94 D97B 9063 AD15 0F38 193A E579 6C4D Source Mage GNU/Linux: http://www.sourcemage.org - Tome team & News Guru |
|
#3
| |||
| |||
| On 2005-04-27, qnr <terry@timestorm.ross.com> wrote: > Hmmmm well, I replaced target with sa in Sockets.connect, and it is doing > something now. Interesting thing is, I had replaced sa with target, > because I was getting the error shown in the original message, and looking > at the procedure I saw it was designated (* IN *), so I thought it wanted > an empty one. connect expects the address you want to connect to. Hence, the address including family, port and IP address has to be initialized. > Strace gives me this now. I don't know if I'm locked up because I wasn't > supposed to change the byte order of the address and port, or if it's just > waiting form me to take some action Port and the IP address have to be given in network order, i.e. in big-endian. However, I do not know in which representation the IP address is returned by your gethostbyname function. The C library function gethostbyname() _always_ returns IP addresses in the network byte order. If you apply htons on this, you will get the wrong result on little-endian architectures. Andreas. |
|
#4
| |||
| |||
| On Mon, 13 Jun 2005 11:52:26 -0500, Andreas F. Borchert wrote: [snipped] > connect expects the address you want to connect to. Hence, the address > including family, port and IP address has to be initialized. > [snipped] > > Port and the IP address have to be given in network order, i.e. in > big-endian. However, I do not know in which representation the IP > address is returned by your gethostbyname function. The C library > function gethostbyname() _always_ returns IP addresses in the network > byte order. If you apply htons on this, you will get the wrong result on > little-endian architectures. > > Andreas. Thank you Andreas. I've had it working for a while now, but in the program itself. I still have to make a library module up though. Terry |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.