Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!munnari.oz.au!bunyip.cc.uq.oz.au!brolga!uqcspe!cs.uq.oz.au!tonyg From: tonyg@cs.uq.oz.au (Tony Gedge) Newsgroups: comp.lang.perl Subject: using sendto and recvfrom in perl Keywords: syscall sendto recvfrom ipc sockets Message-ID: <1934@uqcspe.cs.uq.oz.au> Date: 13 Jun 91 06:59:34 GMT Sender: news@cs.uq.oz.au Reply-To: tonyg@cs.uq.oz.au Lines: 50 I want to use the system calls "recvfrom" and "sendto" in a perl script. Has anyone put some nice wrappers around these system calls? My current version appears to be a *bit* buggy. This is under SunOS 4.1 and using perl version 4.0 patchlevel 10 here's my code - ignore the fact that I'm not returning any data as yet... --- --- --- --- --- --- --- sub sendto { local($sock,$msg,$len,$flags,$to,$tolen) = @_; local($result) = 1; $len = $len+0; # Force to be an integer $tolen = $tolen+0; # Force to be an integer if (syscall(SYS_sendto,fileno($sock),$msg,$len,$flags,$to,$tolen) < 0) { print "sendto: $!\n"; $result = 0; } $result; } sub recvfrom { local($sock,$msg,$len,$flags,$from,$fromlen) = @_; local($result) = 1; $len = $len+0; # Force to be an integer $msg = pack("a$len",''); # Null pad to correct length $from = pack("a$fromlen",''); # Null pad to correct length $fromlen = pack("n",$fromlen); # number, but stored as string if (syscall(SYS_recvfrom,fileno($sock),$msg,$len,$flags,$from,$fromlen) < 0) { print "recvfrom: $!\n"; $result = 0; } $result; } 1; --- --- --- --- --- --- --- Tony Gedge. -- ------------------------------------------------------------------------- | Computer Science Department, | tonyg@cs.uq.oz.au (Tony Gedge) | | University of Queensland, Australia.| "cc stands for Cryptic Crossword" | -------------------------------------------------------------------------